2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/stringid.hpp>
|
2015-04-13 16:45:56 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2014-05-26 17:11:07 +10:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**) {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2016-01-19 18:31:49 +11:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::stringid map;
|
2014-05-26 17:11:07 +10:00
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "find on empty set throws");
|
2014-05-26 17:11:07 +10:00
|
|
|
|
|
|
|
auto id1 = map.add ("first");
|
2016-01-19 18:31:49 +11:00
|
|
|
tap.expect_eq (id1, map.find ("first"), "single entity ID matches");
|
2014-05-26 17:11:07 +10:00
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "invalid find throws");
|
2014-05-26 17:11:07 +10:00
|
|
|
|
|
|
|
auto id2 = map.add ("second");
|
2016-01-19 18:31:49 +11:00
|
|
|
tap.expect_eq (id1 + 1, id2, "monotonically increasing IDs");
|
|
|
|
tap.expect_eq (id1, map.find ("first"), "first element still matches");
|
2014-05-26 17:11:07 +10:00
|
|
|
|
2018-09-17 14:50:23 +10:00
|
|
|
tap.expect_eq (map["second"], id2, "index lookup invokes no change");
|
|
|
|
|
|
|
|
auto id3 = map["third"];
|
|
|
|
tap.expect (id3 != id1 && id3 != id2, "index creation adds new value");
|
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
return tap.status ();
|
2014-05-26 17:11:07 +10:00
|
|
|
}
|