aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthecharlesblake2017-12-27 23:55:34 +0000
committerthecharlesblake2017-12-27 23:55:34 +0000
commit588a36c63991d24566d4af6f1b9722186bdcc286 (patch)
tree26b9855cf4a9ec808dae99b378fbbcfa7af4315f
parentAll basic bh tests complete (diff)
downloadmetasol-588a36c63991d24566d4af6f1b9722186bdcc286.tar.gz
metasol-588a36c63991d24566d4af6f1b9722186bdcc286.zip

Added fc tests - currently intract.

-rw-r--r--CMakeLists.txt4
-rw-r--r--src/main/input-output/deal_parser.cpp40
-rw-r--r--src/main/input-output/deal_parser.h1
-rw-r--r--src/test/free_cell_test.cpp28
-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
8 files changed, 95 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f5ad38..66ff54a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,9 @@ set(sources src/main/input-output/command_line_helper.cpp
src/main/solver/solver.cpp src/main/solver/solver.h src/main/game/game_state.cpp
src/main/game/game_state.h src/main/game/sol_rules.h src/main/game/sol_rules.cpp
src/main/game/pile.cpp src/main/game/pile.h src/main/util/util.cpp src/main/util/util.h src/main/input-output/sol_preset_types.h src/main/input-output/sol_preset_types.cpp)
-set(sources_test src/test/spanish_patience_test.cpp src/test/test_helper.cpp src/test/test_helper.h src/test/black_hole_test.cpp)
+set(sources_test src/test/spanish_patience_test.cpp src/test/test_helper.cpp
+ src/test/test_helper.h src/test/black_hole_test.cpp
+ src/test/free_cell_test.cpp)
###############################################################################
## Rapid JSON setup ###########################################################
diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp
index bf4ebaa..2ff5a02 100644
--- a/src/main/input-output/deal_parser.cpp
+++ b/src/main/input-output/deal_parser.cpp
@@ -22,6 +22,11 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
if (gs.rules.hole) {
parse_hole(gs, doc);
}
+
+ // Construct filled cells
+ if (gs.rules.cells) {
+ parse_cells(gs, doc);
+ }
}
void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& doc) {
@@ -38,15 +43,40 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document&
++p.first, ++p.second) {
for (auto& json_card : p.first->GetArray()) {
+ assert(json_card.IsString());
p.second->place(card(json_card.GetString()));
}
}
}
-void deal_parser::parse_hole(game_state &gs, const rapidjson::Document& doc) {
- assert(doc.HasMember("hole"));
- const Value& json_hole = doc["hole"];
- assert(json_hole.IsString());
+void deal_parser::parse_hole(game_state &gs, const Document& doc) {
+ if (doc.HasMember("hole")) {
+ const Value &json_hole = doc["hole"];
+ assert(json_hole.IsString());
+
+ gs.hole.place(card(json_hole.GetString()));
+ }
+}
+
+void deal_parser::parse_cells(game_state &gs, const Document& doc) {
+ if (doc.HasMember("cells")) {
+ const Value &json_cells = doc["cells"];
+ assert(json_cells.IsArray());
- gs.hole.place(card(json_hole.GetString()));
+ const auto json_cell_arr = json_cells.GetArray();
+
+ if (json_cell_arr.Empty()) return;
+ else if (gs.rules.cells != json_cell_arr.Size()) {
+ util::json_parse_err("Incorrect number of cells");
+ }
+
+ for (auto p = std::make_pair(begin(json_cell_arr), begin(gs.cells));
+ p.second != end(gs.cells);
+ ++p.first, ++p.second) {
+
+ auto json_card = p.first;
+ assert(json_card->IsString());
+ p.second->place(json_card->GetString());
+ }
+ }
}
diff --git a/src/main/input-output/deal_parser.h b/src/main/input-output/deal_parser.h
index 80a0f52..255116b 100644
--- a/src/main/input-output/deal_parser.h
+++ b/src/main/input-output/deal_parser.h
@@ -22,6 +22,7 @@ public:
private:
static void parse_tableau_piles(game_state&, const rapidjson::Document&);
static void parse_hole(game_state&, const rapidjson::Document&);
+ static void parse_cells(game_state&, const rapidjson::Document&);
};
#endif //SOLVITAIRE_DEAL_PARSER_H
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/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"]
+ ]
+}