#include #include #include #include "inventory.hpp" using namespace fmt; TEST_CASE("base test", "[inventory]") { inventory::Model inv; DinkyECS::Entity test_ent = 1; bool good = inv.add("hand_l", test_ent); inv.invariant(); REQUIRE(good); auto& slot = inv.get(test_ent); REQUIRE(slot == "hand_l"); // confirm that we get false when trying to do it again good = inv.add("hand_l", test_ent); REQUIRE(!good); auto ent = inv.get(slot); REQUIRE(ent == test_ent); REQUIRE(inv.has(ent)); REQUIRE(inv.has(slot)); // test base remove inv.remove(ent); REQUIRE(!inv.has(slot)); REQUIRE(!inv.has(ent)); } TEST_CASE("test swapping items", "[inventory-swap]") { inventory::Model inv; DinkyECS::Entity hand_l_ent = 10; DinkyECS::Entity hand_r_ent = 20; inv.add("hand_l", hand_l_ent); inv.add("hand_r", hand_r_ent); REQUIRE(inv.count() == 2); inv.swap(hand_l_ent, hand_r_ent); REQUIRE(inv.get("hand_l") == hand_r_ent); REQUIRE(inv.get("hand_r") == hand_l_ent); REQUIRE(inv.count() == 2); }