First cut of pulling out the relevant parts of my original game to make a little framework.
This commit is contained in:
commit
6a0c9e8d46
177 changed files with 18197 additions and 0 deletions
52
tests/inventory.cpp
Normal file
52
tests/inventory.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include "game/inventory.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
TEST_CASE("base test", "[inventory]") {
|
||||
return;
|
||||
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
|
||||
// BUG: this dies
|
||||
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]") {
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue