feat: add syntax config constants
fix(VarStore): better hash function
This commit is contained in:
parent
19d6f6fd70
commit
a66bfff424
9 changed files with 125 additions and 56 deletions
|
|
@ -21,6 +21,14 @@ void test_evaluation()
|
|||
assert(resType == TYPE_INT);
|
||||
assert(-4 == resVal);
|
||||
|
||||
evaluate(state, " - 6 ", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(-6 == resVal);
|
||||
|
||||
evaluate(state, " 1+ (- 45 ) ", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(-44 == resVal);
|
||||
|
||||
evaluate(state, "-(4+9)+1", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(-12 == resVal);
|
||||
|
|
@ -53,6 +61,8 @@ void test_evaluation()
|
|||
assert(resType == TYPE_FLOAT);
|
||||
assert(float_almost_equal(-0.4, get_float_from_int_rep(resVal)));
|
||||
|
||||
/* FUNCTIONS */
|
||||
|
||||
evaluate(state, "sqrt(2)-1", &resVal, &resType);
|
||||
assert(resType == TYPE_FLOAT);
|
||||
assert(float_almost_equal(0.41421, get_float_from_int_rep(resVal)));
|
||||
|
|
@ -89,11 +99,28 @@ void test_evaluation()
|
|||
assert(resType == TYPE_INT);
|
||||
assert(4 == resVal);
|
||||
|
||||
evaluate(state, "max(25, 4)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(25 == resVal);
|
||||
|
||||
evaluate(state, "max(-25, 42)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(42 == resVal);
|
||||
|
||||
evaluate(state, "max( (1+1)^(6+1-1) , 4+2)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(64 == resVal);
|
||||
|
||||
evaluate(state, "max(floor(exp(1))^(4+1) , -2)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(32 == resVal);
|
||||
|
||||
// testing function composition is important
|
||||
evaluate(state, "abs(abs(-2))", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(2 == resVal);
|
||||
|
||||
/* COMPARAISON OPERATORS */
|
||||
evaluate(state, "2 = 2", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(1 == resVal);
|
||||
|
|
@ -154,6 +181,7 @@ void test_evaluation()
|
|||
assert(resType == TYPE_FLOAT);
|
||||
assert(float_almost_equal(5.3, get_float_from_int_rep(resVal)));
|
||||
|
||||
/* VARIABLES */
|
||||
int ex = 43;
|
||||
var_store_set(state->varStore, "var", TYPE_INT, (void*) &ex);
|
||||
evaluate(state, "var", &resVal, &resType);
|
||||
|
|
@ -176,6 +204,7 @@ void test_evaluation()
|
|||
printf("actually got: %d \n", resVal);
|
||||
assert(7 == resVal);
|
||||
|
||||
/* TYPE FUNCS */
|
||||
evaluate(state, "is_number(123)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(resVal);
|
||||
|
|
@ -191,4 +220,8 @@ void test_evaluation()
|
|||
evaluate(state, "is_null(NULL)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(resVal);
|
||||
|
||||
evaluate(state, "(is_null(NULL) & is_number(42)) | 0", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(resVal);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue