Containment Assertions - dicksonlaw583/gmassert2 GitHub Wiki
Containment Assertions
These assertions from GMAssert_Containment
checks whether the incoming container-type value (e.g. 1D/2D array, struct, DS list, DS map, DS grid) contains or does not contain certain values.
assert_contains(got, content, [msg])
Assert that the gotten string, list or array contains a value exactly equal to content
.
Example
var list = ds_list_create();
ds_list_add(list, 1, 2, "waahoo", 3, 4);
assert_contains(list, "waahoo"); //Assertion OK
assert_contains(list, "WAAHOO"); //Assertion failed
assert_contains_2d(got, content, [msg])
Assert that the gotten grid or 2D array contains a value equal to content
.
Example
var grid = ds_grid_create(2, 2);
grid[# 0, 0] = 1;
grid[# 1, 0] = 2;
grid[# 0, 1] = 3;
grid[# 1, 1] = 4;
assert_contains_2d(grid, 3); //Assertion OK
assert_contains_2d(grid, 6); //Assertion failed
assert_contains_exact(got, content, [msg])
Assert that the gotten string, list or array contains a value exactly equal to content
(as compared using ==
).
Example
var sentence = "The quick brown fox jumps over the lazy dog";
assert_contains_exact(sentence, "fox"); //Assertion OK
assert_contains_exact(sentence, "armadillo"); //Assertion failed
assert_contains_exact_2d(got, content, [msg])
Assert that the gotten grid or 2D array contains a value exactly equal to content
(as compared using ==
).
Example
var animals = ["aardvark", "bear"], ["crocodile", "dingo"](/dicksonlaw583/gmassert2/wiki/"aardvark",-"bear"],-["crocodile",-"dingo");
assert_contains_exact_2d(animals, "dingo"); //Assertion OK
assert_contains_exact_2d(animals, "elephant"); //Assertion failed
assert_doesnt_contain(got, content, [msg])
Assert that the gotten string, list or array does not contain a value equal to content
.
Example
var animals;
animals[0] = "ant";
animals[1] = "bear";
animals[2] = "cat";
assert_doesnt_contain(animals, "butterfly"); //Assertion OK
assert_doesnt_contain(animals, "bear"); //Assertion failed
assert_doesnt_contain_2d(got, content, [msg])
Assert that the gotten grid or 2D array doesn't contain a value equal to content
.
Example
var menu_items = ["Spaghetti", "Pizza", "Roti Chicken"], ["Panzerotti", "Baguette", "Tortellini"](/dicksonlaw583/gmassert2/wiki/"Spaghetti",-"Pizza",-"Roti-Chicken"],-["Panzerotti",-"Baguette",-"Tortellini");
assert_doesnt_contain_2d(menu_items, "Ravioli"); //Assertion OK
assert_doesnt_contain_2d(menu_items, "Tortellini"); //Assertion failed
assert_doesnt_contain_exact(got, content, [msg])
Assert that the gotten string, list or array does not contain a value exactly equal to content
(as compared using ==
).
Example
var list = ds_list_create();
ds_list_add(list, 1, 2, "waahoo", 3, 4);
assert_doesnt_contain_exact(list, "WAAHOO"); //Assertion OK
assert_doesnt_contain_exact(list, 4); //Assertion failed
assert_doesnt_contain_exact_2d(got, content, [msg])
Assert that the gotten grid or 2D array doesn't contain a value exactly equal to content
(as compared using ==
).
Example
var grid = ds_grid_create(2, 2);
grid[# 0, 0] = "foo";
grid[# 1, 0] = "bar";
grid[# 0, 1] = "baz";
grid[# 1, 1] = "qux";
assert_doesnt_contain_exact_2d(grid, "foobar"); //Assertion OK
assert_doesnt_contain_exact_2d(grid, "foo"); //Assertion failed
assert_doesnt_have_key(got, key, [msg])
Assert that the gotten map or struct does not have the given key.
Example
var map = ds_map_create();
ds_map_add(map, "label", "foo");
assert_doesnt_have_key(map, "text"); //Assertion OK
assert_doesnt_have_key(map, "label"); //Assertion failed
assert_doesnt_have_method(got, methodName, [msg])
Assert that the gotten struct does not have the given method name.
Example
function Node(_value) constructor {
value = _value;
children = [];
addChild = function(_childValue) {
children[array_length(children)] = new Node(_childValue);
};
}
var node = new Node("foo");
assert_doesnt_have_method(node, "getChildren"); //Assertion OK
assert_doesnt_have_method(node, "addChild"); //Assertion failed
assert_has_key(got, key, [msg])
Assert that the gotten map or struct has the given key.
Example
var coords = {x: 583, y: 1166};
assert_has_key(coords, "x"); //Assertion OK
assert_has_key(coords, "y"); //Assertion OK
assert_has_key(coords, "z"); //Assertion failed
assert_has_method(got, methodName, [msg])
Assert that the gotten struct has a method with the given name (i.e key exists and value type is method).
Example
function Vector2(_x, _y) constructor {
x = _x;
y = _y;
mag = function() { return sqrt(x*x+y*y); };
}
var myv2 = new Vector2(222, 444);
assert_has_method(myv2, "mag"); //Assertion OK
assert_has_method(myv2, "norm"); //Assertion failed