4 * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include "functions.h"
29 test(char *expression
, char *expected
, int expected_error
)
33 char result_str
[MAXLINE
];
35 error
= ce_parse(expression
, result
);
36 if(error
!= 0 || error
!= expected_error
)
38 if(error
== expected_error
)
39 printf("SUCCESS: '%s' -> error %d\n", expression
, error
);
41 printf("FAIL: '%s' -> error %d, expected error %d and result '%s'\n", expression
, error
, expected_error
, expected
);
45 make_fixed(result
, result_str
, DEC
, 10, FALSE
);
46 if(strcmp(result_str
, expected
) != 0)
47 printf("FAIL: '%s' -> '%s', expected '%s'\n", expression
, result_str
, expected
);
49 printf("SUCCESS: '%s' -> '%s'\n", expression
, result_str
);
56 v
->modetype
= SCIENTIFIC
;
63 test("255", "255", 0);
64 test("256", "256", 0);
66 test("1.01", "1.01", 0);
67 test("1e9", "1000000000", 0);
73 //FIXME: Need to update mperr() test("1/2", "0.5", 0);
74 //FIXME: Need to update mperr() test("1/0", "", 0);
75 //FIXME: Need to update mperr() test("0/0", "", 0);
77 test("1+2*3", "7", 0);
78 test("(1+2)*3", "9", 0);
81 test("1%", "0.01", 0);
83 test("2^-1", "0.5", 0);
87 //FIXME: Need to update do_factorial() test("0.1!", "", 0);
88 //FIXME: Need to update do_factorial() test("-1!", "", 0);
90 test("-10^2", "-100", 0);
91 test("(-10)^2", "100", 0);
93 test("Sqrt(4)", "2", 0);
94 test("Sqrt(2)", "1.4142135", 0);
96 test("Int(3.2)", "3", 0);
97 test("Frac(3.2)", "0.2", 0);
98 test("Int(-3.2)", "-3", 0);
99 test("Frac(-3.2)", "-0.2", 0);
101 test("Abs(1)", "1", 0);
102 test("Abs(-1)", "1", 0);
104 test("Sin(0)", "0", 0);
105 test("Cos(0)", "1", 0);
106 test("Tan(0)", "0", 0);
109 test("Sin(90)", "1", 0);
112 test("Sin(3.14159/2)", "1", 0);
115 test("Sin(100)", "1", 0);