#include <stdlib.h>#include <stdio.h>#include "problem.h"#include "utility.h"
Go to the source code of this file.
Functions | |
| int | run_standard_tests () |
| int | main (int argc, char *argv[]) |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 21 of file expr_eval_test.c.
{
extern int idl_parse();
double d;
int i;
if(argc == 1)
exit(run_standard_tests());
for(i = 1; i < argc; i++) {
printf("parsing '%s'.. ", argv[i]);
if(gs_expr_d(argv[i], &d, NULL) < 0)
printf("result = PARSE ERROR\n");
else
printf("result = %g\n", d);
}
exit(EXIT_SUCCESS);
}

| int run_standard_tests | ( | ) |
Run a few standard tests.
Definition at line 46 of file expr_eval_test.c.
{
icl_hash_t *table;
int i, rv;
double d;
double values[] = {1.2, 3.7, 4.0, 1.0, 0.0, 43.63};
char *expressions[] = {
"1+2",
"a+b",
"sqrt(c)",
"1<2",
"3>4",
"(1<2)&&(3>4)",
"3<<1",
"(3<<1)+4",
"6>>1",
"(6>>1)-7",
"3||f",
"c^zero",
"c^one",
"c^zero|one",
"c^zero|one&c",
"((6>>1)-7) && (3||f)",
"((6>>1)-7) && (3||f) <= (c^zero|one&c)",
"((6>>1)-7) && (3||f) < (c^zero|one&c)",
"((6>>1)-7) && (3||f) > (c^zero|one&c)",
"3*2",
"3*2/4",
"3*2/4%6",
"(((6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6)",
"(((6>>1)-7) && (3||f) <= (c^zero|one&c)) > (3*2/4%6)",
"3!=2",
"((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7)",
"((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f)",
"((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6)",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3!=2)",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3==2)",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3!=2) + zero",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3!=2) + zero - one",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3!=2) + zero - one - +c",
"(((1<2)&&(3>4) ? (3<<1)+4 : (6>>1)-7) && (3||f) <= (c^zero|one&c)) >= (3*2/4%6) == (3!=2) + zero - one - +c - -a + ~c * !one +(int)c",
"~c",
"~c*!one",
"b",
"(int)b",
"~c*!one +(int)b",
"-a + ~c*!one +(int)b",
"+c - -a",
"+c - -a + ~c*!one +(int)b",
"zero - one - +c",
"zero - one - +c - -a",
"zero - one - +c - -a + ~c * !one",
"zero - one - +c - -a + ~c * !one +(int)b",
NULL
};
double correct_results[] = {3.0, 4.9, 2.0, 1.0, 0.0, 0.0, 6.0, 10.0, 3.0, -4.0,
1.0, 4.0, 5.0, 5.0, 4.0, 1.0, 1.0, 1.0, 0.0, 6.0, 1.5, 1.0, 1.0, 0.0, 1.0,
-4.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -5.0, 0.0, 3.7, 3.0, 3.0,
1.8, 5.2, 8.2, -5.0, -3.8, -3.8, -0.8};
rv = EXIT_SUCCESS;
table = icl_hash_create(11, NULL);
icl_hash_insert(table, "a", &values[0]);
icl_hash_insert(table, "b", &values[1]);
icl_hash_insert(table, "c", &values[2]);
icl_hash_insert(table, "one", &values[3]);
icl_hash_insert(table, "zero", &values[4]);
icl_hash_insert(table, "f", &values[5]);
for(i=0;expressions[i];i++) {
printf("parsing '%s'.. ", expressions[i]);
if(gs_expr_d(expressions[i], &d, table) < 0)
printf("result = PARSE ERROR\n");
else {
if(abs(d - correct_results[i]) > 0.05) {
printf("INCORRECT result = %g (correct = %g)\n",
d, correct_results[i]);
rv = EXIT_FAILURE;
}
else
printf("result = %g\n", d);
}
}
icl_hash_destroy(table, NULL, NULL);
return rv;
}


1.6.3-20100507