bubel-ecs/tests/map.d
Mergul f964d7bf85 Added more tests
-added Vector test
-added HashMap test
-added EntityMeta test
-added default hashing function to hashmap
2020-05-27 19:46:11 +02:00

53 lines
No EOL
1 KiB
D

module tests.map;
import bubel.ecs.hash_map;
version(GNU)
{
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
{
return a;
}
}
else import std.array : staticArray;
@("HashMap")
unittest
{
HashMap!(string, int) map;
assert(map.length == 0);
map.add("asd",1);
assert(map.length == 1);
map.clear();
assert(map.length == 0);
map.add("asd",1);
assert(map.length == 1);
map.reset();
assert(map.length == 0);
map.add("asd",1);
string asd = "asd";
assert(map.isIn("asd"));
assert(map.isIn(asd));
assert(!map.isIn("asdf"));
map.tryRemove("asdf");
map.tryRemove("asd");
assert(map.length == 0);
map.add("asdf",1);
map.add("asd",2);
assert(map["asd"] == 2);
assert(map["asdf"] == 1);
assert(map.length == 2);
map.tryRemove("asdf");
assert(map.length == 1);
map.remove("asd");
assert(map.length == 0);
map.add("asd",1);
map.add("asdwwghe",6);
foreach(k,v;&map.byKeyValue)
{
assert(map[k] == v);
}
}