aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/black_hole_test.cpp28
-rw-r--r--src/test/free_cell_test.cpp28
-rw-r--r--src/test/main_test.cpp19
-rw-r--r--src/test/resources/black_hole/ComplexSolvable.json9
-rw-r--r--src/test/resources/black_hole/ComplexUnsolvable.json9
-rw-r--r--src/test/resources/black_hole/SimpleSolvable.json9
-rw-r--r--src/test/resources/black_hole/SimpleUnsolvable.json9
-rw-r--r--src/test/resources/free_cell/ComplexSolvable.json7
-rw-r--r--src/test/resources/free_cell/ComplexUnsolvable.json7
-rw-r--r--src/test/resources/free_cell/SimpleSolvable.json7
-rw-r--r--src/test/resources/free_cell/SimpleUnsolvable.json7
-rw-r--r--src/test/resources/spanish_patience/ComplexSolvable.json7
-rw-r--r--src/test/resources/spanish_patience/ComplexUnsolvable.json7
-rw-r--r--src/test/resources/spanish_patience/SimpleSolvable.json7
-rw-r--r--src/test/resources/spanish_patience/SimpleUnsolvable.json7
-rw-r--r--src/test/spanish_patience_test.cpp28
-rw-r--r--src/test/test_helper.cpp23
-rw-r--r--src/test/test_helper.h16
18 files changed, 215 insertions, 19 deletions
diff --git a/src/test/black_hole_test.cpp b/src/test/black_hole_test.cpp
new file mode 100644
index 0000000..89ee50a
--- /dev/null
+++ b/src/test/black_hole_test.cpp
@@ -0,0 +1,28 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+#include "test_helper.h"
+
+typedef test_helper th;
+
+const static std::string path = "resources/black_hole/";
+const static std::string type = "simple-black-hole";
+
+TEST(BlackHole, SimpleSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
+}
+
+TEST(BlackHole, ComplexSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
+}
+
+TEST(BlackHole, SimpleUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
+}
+
+TEST(BlackHole, ComplexUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
+}
diff --git a/src/test/free_cell_test.cpp b/src/test/free_cell_test.cpp
new file mode 100644
index 0000000..507c915
--- /dev/null
+++ b/src/test/free_cell_test.cpp
@@ -0,0 +1,28 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+#include "test_helper.h"
+
+typedef test_helper th;
+
+const static std::string path = "resources/free_cell/";
+const static std::string type = "simple-free-cell";
+
+TEST(FreeCell, SimpleSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
+}
+
+TEST(FreeCell, ComplexSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
+}
+
+TEST(FreeCell, SimpleUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
+}
+
+TEST(FreeCell, ComplexUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
+}
diff --git a/src/test/main_test.cpp b/src/test/main_test.cpp
deleted file mode 100644
index 3f2081f..0000000
--- a/src/test/main_test.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// Created by thecharlesblake on 10/4/17.
-//
-
-#include <gtest/gtest.h>
-
-const int actualValTrue = 4;
-const int actualValFalse = 8;
-const int expectVal = 4;
-
-namespace {
- TEST(StrCompare, CStrEqual) {
- EXPECT_EQ(expectVal, actualValTrue);
- }
-
- TEST(StrCompare, CStrNotEqual) {
- EXPECT_NE(expectVal, actualValFalse);
- }
-}
diff --git a/src/test/resources/black_hole/ComplexSolvable.json b/src/test/resources/black_hole/ComplexSolvable.json
new file mode 100644
index 0000000..8d0249d
--- /dev/null
+++ b/src/test/resources/black_hole/ComplexSolvable.json
@@ -0,0 +1,9 @@
+{
+ "tableau piles": [
+ ["5D","4D","3D","2D","AD"],
+ ["5C","4C","3C","2C","4H","5H"],
+ ["AC","AH","2H","3H"],
+ ["2S","5S","4S","3S"]
+ ],
+ "hole": "AS"
+}
diff --git a/src/test/resources/black_hole/ComplexUnsolvable.json b/src/test/resources/black_hole/ComplexUnsolvable.json
new file mode 100644
index 0000000..89eb08f
--- /dev/null
+++ b/src/test/resources/black_hole/ComplexUnsolvable.json
@@ -0,0 +1,9 @@
+{
+ "tableau piles": [
+ ["5","3","2","4","A"],
+ ["5","3","2","4","A"],
+ ["5","3","3","4","A"],
+ ["5","2","2","2"]
+ ],
+ "hole": "AS"
+}
diff --git a/src/test/resources/black_hole/SimpleSolvable.json b/src/test/resources/black_hole/SimpleSolvable.json
new file mode 100644
index 0000000..3a7be18
--- /dev/null
+++ b/src/test/resources/black_hole/SimpleSolvable.json
@@ -0,0 +1,9 @@
+{
+ "tableau piles": [
+ ["AD","2D","3D","4D","5D"],
+ ["AC","2C","3C","4C","5C"],
+ ["AH","2H","3H","4H","5H"],
+ ["2S","3S","4S","5S"]
+ ],
+ "hole": "AS"
+}
diff --git a/src/test/resources/black_hole/SimpleUnsolvable.json b/src/test/resources/black_hole/SimpleUnsolvable.json
new file mode 100644
index 0000000..d6a5e7c
--- /dev/null
+++ b/src/test/resources/black_hole/SimpleUnsolvable.json
@@ -0,0 +1,9 @@
+{
+ "tableau piles": [
+ ["5D","4D","3D","2D","AD"],
+ ["5C","4C","3C","2C","AC"],
+ ["5H","4H","3H","2H","AH"],
+ ["5S","4S","2S","3S"]
+ ],
+ "hole": "AS"
+}
diff --git a/src/test/resources/free_cell/ComplexSolvable.json b/src/test/resources/free_cell/ComplexSolvable.json
new file mode 100644
index 0000000..2c284d9
--- /dev/null
+++ b/src/test/resources/free_cell/ComplexSolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AH","AC","2C","3C"],
+ ["AD","2H","2D","3D"],
+ ["3H","2S","AS","3S"]
+ ]
+}
diff --git a/src/test/resources/free_cell/ComplexUnsolvable.json b/src/test/resources/free_cell/ComplexUnsolvable.json
new file mode 100644
index 0000000..279c319
--- /dev/null
+++ b/src/test/resources/free_cell/ComplexUnsolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AH","AC","3H","3C"],
+ ["AD","2H","2D","3D"],
+ ["2C","2S","AS","3S"]
+ ]
+}
diff --git a/src/test/resources/free_cell/SimpleSolvable.json b/src/test/resources/free_cell/SimpleSolvable.json
new file mode 100644
index 0000000..2ae2f1a
--- /dev/null
+++ b/src/test/resources/free_cell/SimpleSolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["3H","2H","AH","AC"],
+ ["3D","2D","2C","AD"],
+ ["3S","3C","2S","AS"]
+ ]
+}
diff --git a/src/test/resources/free_cell/SimpleUnsolvable.json b/src/test/resources/free_cell/SimpleUnsolvable.json
new file mode 100644
index 0000000..f69312d
--- /dev/null
+++ b/src/test/resources/free_cell/SimpleUnsolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AH","AC","3H","3C"],
+ ["AD","2C","2D","3D"],
+ ["AS","2S","2H","3S"]
+ ]
+}
diff --git a/src/test/resources/spanish_patience/ComplexSolvable.json b/src/test/resources/spanish_patience/ComplexSolvable.json
new file mode 100644
index 0000000..c48ce47
--- /dev/null
+++ b/src/test/resources/spanish_patience/ComplexSolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AS", "2S", "AH"],
+ ["AD", "2D", "2H"],
+ ["2C", "AC"]
+ ]
+}
diff --git a/src/test/resources/spanish_patience/ComplexUnsolvable.json b/src/test/resources/spanish_patience/ComplexUnsolvable.json
new file mode 100644
index 0000000..ba9be59
--- /dev/null
+++ b/src/test/resources/spanish_patience/ComplexUnsolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AS", "2S", "AH"],
+ ["AD", "2D", "2H"],
+ ["AC", "2C"]
+ ]
+}
diff --git a/src/test/resources/spanish_patience/SimpleSolvable.json b/src/test/resources/spanish_patience/SimpleSolvable.json
new file mode 100644
index 0000000..eacad0e
--- /dev/null
+++ b/src/test/resources/spanish_patience/SimpleSolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["2S", "AS", "AD"],
+ ["2D", "2H", "AH"],
+ ["2C", "AC"]
+ ]
+}
diff --git a/src/test/resources/spanish_patience/SimpleUnsolvable.json b/src/test/resources/spanish_patience/SimpleUnsolvable.json
new file mode 100644
index 0000000..99a3140
--- /dev/null
+++ b/src/test/resources/spanish_patience/SimpleUnsolvable.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["AS", "2S", "2D"],
+ ["AD", "AH", "2H"],
+ ["AC", "2C"]
+ ]
+}
diff --git a/src/test/spanish_patience_test.cpp b/src/test/spanish_patience_test.cpp
new file mode 100644
index 0000000..8973a53
--- /dev/null
+++ b/src/test/spanish_patience_test.cpp
@@ -0,0 +1,28 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+#include "test_helper.h"
+
+typedef test_helper th;
+
+const static std::string path = "resources/spanish_patience/";
+const static std::string type = "simple-spanish-patience";
+
+TEST(SpanishPatience, SimpleSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
+}
+
+TEST(SpanishPatience, ComplexSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
+}
+
+TEST(SpanishPatience, SimpleUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
+}
+
+TEST(SpanishPatience, ComplexUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
+}
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
new file mode 100644
index 0000000..9c258a3
--- /dev/null
+++ b/src/test/test_helper.cpp
@@ -0,0 +1,23 @@
+//
+// Created by thecharlesblake on 12/26/17.
+//
+
+#include <rapidjson/document.h>
+
+#include "test_helper.h"
+#include "../main/game/game_state.h"
+#include "../main/solver/solver.h"
+#include "../main/util/util.h"
+
+using namespace rapidjson;
+using namespace std;
+
+bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) {
+ const Document in_doc = util::get_file_json(input_file);
+ const sol_rules rules = sol_rules::from_preset(preset_type);
+
+ game_state gs(rules, in_doc);
+ solver sol(gs, rules);
+
+ return sol.run() ? true : false;
+}
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
new file mode 100644
index 0000000..5b8e755
--- /dev/null
+++ b/src/test/test_helper.h
@@ -0,0 +1,16 @@
+//
+// Created by thecharlesblake on 12/26/17.
+//
+
+#ifndef SOLVITAIRE_TEST_HELPER_H
+#define SOLVITAIRE_TEST_HELPER_H
+
+#include <string>
+
+class test_helper {
+public:
+ static bool is_solvable(const std::string&, const std::string&);
+};
+
+
+#endif //SOLVITAIRE_TEST_HELPER_H