Equivalence Assertions - dicksonlaw583/gmassert2 GitHub Wiki
Equivalence Assertions
These assertions from GMAssert_Equivalence
compare the incoming value against an expected value, checking for exact or approximate equivalence.
Tip: You can use array or struct literals to check multiple values at a time using assert_equal
or assert_equalish
. Example:
var foo = 5;
var bar = "bar";
var baz = true;
assert_equal([foo, bar, baz], [5, "bar", true]); //Assertion OK
assert_equalish({a: foo, b: bar, c: baz}, {a: 5, b: "bar", c: true}); //Assertion OK
assert_equal([foo, bar, baz], [6, "car", false]); //Assertion failed
assert_equalish({a: foo, b: bar, c: baz}, {a: 6, b: "car", c: false}); //Assertion failed
assert_equal(got, expected, [msg])
Assert that the gotten expression is equal to the expected expression.
Example
var total = 3+5;
assert_equal(total, 8); //Assertion OK
assert_equal(total, "8"); //Assertion failed
assert_equalish(got, expected, [msg])
Assert that the gotten expression is approximately equal to the expected expression.
Example
assert_equalish(math_get_epsilon(), 0); //Assertion OK
assert_equalish(0.1, 0); //Assertion failed
assert_is(got, expected, [msg])
Assert that the gotten expression is exactly equal to the expected expression (as compared using ==
).
Example
var arrayA = [5, 5];
var arrayB = [8, 8];
var arrayC = [5, 5];
assert_is(arrayA, arrayA); //Assertion OK
assert_is(arrayA, arrayB); //Assertion failed
assert_is(arrayA, arrayC); //Assertion STILL failed --- arrayA and arrayC are not the same array!
assert_isnt(got, expected, [msg])
Assert that the gotten expression is not exactly equal to the expected expression (as compared using ==
).
Example
var arrayA, arrayB;
arrayA[0] = 5;
arrayB[0] = 5;
arrayA[1] = 8;
arrayB[1] = 8;
assert_isnt(arrayA, arrayB); //Assertion OK
assert_isnt(arrayA, arrayA); //Assertion failed
assert_not_equal(got, expected, [msg])
Assert that the gotten expression is not equal to the expected expression.
Example
var total = 583+907;
assert_not_equal(total, 2016); //Assertion OK
assert_not_equal(total, 1490); //Assertion failed
assert_not_equalish(got, expected, [msg])
Assert that the gotten expression is not approximately equal to the expected expression.
Example
assert_not_equalish(0.5, 0); //Assertion OK
assert_not_equalish(math_get_epsilon(), 0); //Assertion failed