Comparison Assertions - dicksonlaw583/gmassert2 GitHub Wiki
These assertions from GMAssert_Comparison
compare the incoming real, string, array, or struct value against an expected value using <
, >
, <=
or >=
comparisons.
Tip: You can use array or struct literals to make several comparisons in parallel. Example:
var foo = 5;
var bar = 50;
assert_greater_than([foo, bar], [4, 40]); //Assertion OK
assert_greater_than_or_equal({a: foo, b: bar}, {a: 4, b: 40}); //Assertion OK
assert_in_range([foo, bar], [4, 40], [6, 60]); //Assertion OK
assert_less_than([foo, bar], [4, 40]); //Assertion failed --- both comparisons failed
assert_less_than_or_equal({a: foo, b: bar}, {a: 4, b: 60}); //Assertion failed --- one or more comparisons failed
assert_not_in_range([foo, bar], [6, 60], [7, 70]); //Assertion failed --- both comparisons out of range
Assert that the gotten expression is greater than the expected expression.
Example
var result = sin(pi/3); //sqrt(3)/2
assert_greater_than(result, 0.5); //Assertion OK
assert_greater_than(result, 1); //Assertion failed
Assert that the gotten expression is greater than or equal to the expected expression..
Example
var spd = 5,
dir = 90;
assert_greater_than_or_equal(lengthdir_x(spd, dir), 0); //Assertion OK
assert_greater_than_or_equal(lengthdir_y(spd, dir), 0); //Assertion failed
Assert that the gotten expression is within the inclusive range between lower
and upper
.
Example
assert_in_range(pi, 3, 4); //Assertion OK
assert_in_range(exp(1), 3, 4); //Assertion failed
Assert that the gotten expression is less than the expected expression.
Example
var list = ds_list_create();
ds_list_add(list, 1, 2, 3);
assert_less_than(ds_list_size(list), 5); //Assertion OK
assert_less_than(ds_list_size(list), 3); //Assertion failed
Assert that the gotten expression is less than or equal to the expected expression.
Example
assert_less_than_or_equal(dcos(220), 0); //Assertion OK
assert_less_than_or_equal(dcos(330), 0); //Assertion failed
Assert that the gotten expression is not within the inclusive range between lower
and upper
.
Example
assert_not_in_range(sin(pi/4), 0, 1/2); //Assertion OK
assert_not_in_range(sin(pi/8), 0, 1/2); //Assertion failed