summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/CMakeLists.txt10
-rw-r--r--sim/tests/HitPoints.cpp44
2 files changed, 54 insertions, 0 deletions
diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt
index ef80c77..4ddd15d 100644
--- a/sim/CMakeLists.txt
+++ b/sim/CMakeLists.txt
@@ -22,3 +22,13 @@ target_link_libraries(
PRIVATE stats
PUBLIC universe
)
+add_executable(
+ ${PROJECT_NAME}_test
+ tests/HitPoints.cpp
+)
+target_link_libraries(
+ ${PROJECT_NAME}_test
+ PRIVATE GTest::gtest_main
+ PRIVATE ${PROJECT_NAME}
+)
+gtest_discover_tests(${PROJECT_NAME}_test)
diff --git a/sim/tests/HitPoints.cpp b/sim/tests/HitPoints.cpp
new file mode 100644
index 0000000..8b8ef84
--- /dev/null
+++ b/sim/tests/HitPoints.cpp
@@ -0,0 +1,44 @@
+#include <gtest/gtest.h>
+
+#include <kurator/sim/HitPoints.h>
+#include <kurator/universe/ShipType.h>
+
+
+namespace kurator
+{
+namespace tests
+{
+
+
+const universe::ShipType SHIP_TYPE {
+ "",
+ 100.0,
+ 100.0,
+ 100.0,
+ 0.0,
+ 0.5,
+ 0.2,
+ 0.5,
+};
+
+
+
+TEST(HitPoints, Deal)
+{
+ sim::HitPoints points {SHIP_TYPE};
+ EXPECT_TRUE(points.is_alive());
+ EXPECT_DOUBLE_EQ(300.0, points.total());
+ EXPECT_DOUBLE_EQ(50.0, points.deal(100.0));
+ EXPECT_DOUBLE_EQ(250.0, points.total());
+ EXPECT_DOUBLE_EQ(50.0, points.deal(100.0));
+ EXPECT_DOUBLE_EQ(200.0, points.total());
+ EXPECT_DOUBLE_EQ(100.0, points.deal(125.0));
+ EXPECT_DOUBLE_EQ(100.0, points.total());
+ EXPECT_DOUBLE_EQ(100.0, points.deal(200.0));
+ EXPECT_DOUBLE_EQ(0.0, points.total());
+ EXPECT_FALSE(points.is_alive());
+}
+
+
+} // namespace tests
+} // namespace kurator