aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_helper.cpp3
-rw-r--r--src/test/unit_tests/k_plus_stock_test.cpp152
-rw-r--r--src/test/unit_tests/legal_move_gen_test.cpp6
-rw-r--r--src/test/unit_tests/rules_parser_test.cpp377
4 files changed, 108 insertions, 430 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index c85cf39..c4f902e 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -18,13 +18,14 @@ using std::vector;
using std::ostream;
typedef std::initializer_list<std::initializer_list<std::string>> string_il;
+typedef game_state::streamliner_options sos;
bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) {
const Document in_doc = json_helper::get_file_json(input_file);
const sol_rules rules = rules_parser::from_preset(preset_type);
- game_state gs(rules, in_doc, false);
+ game_state gs(rules, in_doc, sos::NONE);
solver sol(gs, 1000000);
return sol.run() == solver::sol_state::solved;
diff --git a/src/test/unit_tests/k_plus_stock_test.cpp b/src/test/unit_tests/k_plus_stock_test.cpp
index 8a26cbe..dcd4410 100644
--- a/src/test/unit_tests/k_plus_stock_test.cpp
+++ b/src/test/unit_tests/k_plus_stock_test.cpp
@@ -35,10 +35,10 @@ TEST(KPlusStock, NoRedealExact) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2),
- move(move::mtype::stock_k_plus, 0, 3, 8),
+ move(move::mtype::stock_k_plus, 0, 4, 3),
+ move(move::mtype::stock_k_plus, 0, 3, 9),
},
- move(move::mtype::stock_k_plus, 0, 3, 8),
+ move(move::mtype::stock_k_plus, 0, 3, 9),
0, 8,
card(), "2D"
);
@@ -63,10 +63,10 @@ TEST(KPlusStock, NoRedealOneExtra) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2),
- move(move::mtype::stock_k_plus, 0, 3, 6),
+ move(move::mtype::stock_k_plus, 0, 4, 3),
+ move(move::mtype::stock_k_plus, 0, 3, 7),
},
- move(move::mtype::stock_k_plus, 0, 3, 6),
+ move(move::mtype::stock_k_plus, 0, 3, 7),
0, 6,
card(), "AD"
);
@@ -91,9 +91,9 @@ TEST(KPlusStock, NoRedealTwoExtra) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2)
+ move(move::mtype::stock_k_plus, 0, 4, 3)
},
- move(move::mtype::stock_k_plus, 0, 4, 2),
+ move(move::mtype::stock_k_plus, 0, 4, 3),
5, 2,
"3C", "AH"
);
@@ -118,10 +118,10 @@ TEST(KPlusStock, RedealExact) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2),
- move(move::mtype::stock_k_plus, 0, 3, 8),
+ move(move::mtype::stock_k_plus, 0, 4, 3, false, false),
+ move(move::mtype::stock_k_plus, 0, 3, 9, false, true),
},
- move(move::mtype::stock_k_plus, 0, 3, 8),
+ move(move::mtype::stock_k_plus, 0, 3, 9, false, true),
8, 0,
"AS", card()
);
@@ -146,10 +146,10 @@ TEST(KPlusStock, RedealOneExtra) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2),
- move(move::mtype::stock_k_plus, 0, 3, 6),
+ move(move::mtype::stock_k_plus, 0, 4, 3, false, false),
+ move(move::mtype::stock_k_plus, 0, 3, 7, false, true),
},
- move(move::mtype::stock_k_plus, 0, 3, 6),
+ move(move::mtype::stock_k_plus, 0, 3, 7, false, true),
6, 0,
"AS", card()
);
@@ -174,9 +174,9 @@ TEST(KPlusStock, RedealTwoExtra) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 4, 2)
+ move(move::mtype::stock_k_plus, 0, 4, 3, false, false)
},
- move(move::mtype::stock_k_plus, 0, 4, 2),
+ move(move::mtype::stock_k_plus, 0, 4, 3, false, false),
5, 2,
"3C", "AH"
);
@@ -201,13 +201,12 @@ TEST(KPlusStock, RedealKPlus3Waste) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 3, 5),
- move(move::mtype::stock_k_plus, 0, 4, 8),
- move(move::mtype::regular, 1, 4, 1)
+ move(move::mtype::stock_k_plus, 0, 3, 6, false, true),
+ move(move::mtype::stock_k_plus, 0, 4, 0, false, false)
},
- move(move::mtype::stock_k_plus, 0, 4, 8),
- 6, 2,
- "3C", "AH"
+ move(move::mtype::stock_k_plus, 0, 3, 6, false, true),
+ 8, 0,
+ "AS", card()
);
}
@@ -230,11 +229,11 @@ TEST(KPlusStock, RedealKPlus4Waste) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 3, 4),
- move(move::mtype::stock_k_plus, 0, 4, 7),
- move(move::mtype::stock_k_plus, 0, 2, 1)
+ move(move::mtype::stock_k_plus, 0, 3, 5, false, true),
+ move(move::mtype::stock_k_plus, 0, 4, -1, false, false),
+ move(move::mtype::stock_k_plus, 0, 2, 2, false, false)
},
- move(move::mtype::stock_k_plus, 0, 2, 1),
+ move(move::mtype::stock_k_plus, 0, 2, 2, false, false),
3, 5,
"3S", "2S"
);
@@ -259,11 +258,11 @@ TEST(KPlusStock, RedealKPlus5Waste) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 3, 2),
- move(move::mtype::stock_k_plus, 0, 4, 7),
- move(move::mtype::stock_k_plus, 0, 2, 3)
+ move(move::mtype::stock_k_plus, 0, 3, 3, false, false),
+ move(move::mtype::stock_k_plus, 0, 4, -2, false, false),
+ move(move::mtype::stock_k_plus, 0, 2, 4, false, false)
},
- move(move::mtype::stock_k_plus, 0, 3, 2),
+ move(move::mtype::stock_k_plus, 0, 3, 3, false, false),
2, 7,
"2D", "AD"
);
@@ -288,11 +287,10 @@ TEST(KPlusStock, RedealKPlusEmptyStock) {
{"2C"}
},
{
- move(move::mtype::stock_k_plus, 0, 3, 5),
- move(move::mtype::stock_k_plus, 0, 4, 8),
- move(move::mtype::regular, 1, 4, 1)
+ move(move::mtype::stock_k_plus, 0, 3, 6, false, true),
+ move(move::mtype::stock_k_plus, 0, 4, 0, false, false)
},
- move(move::mtype::stock_k_plus, 0, 3, 5),
+ move(move::mtype::stock_k_plus, 0, 3, 6, false, true),
8, 0,
"AS", card()
);
@@ -306,7 +304,7 @@ TEST(KPlusStock, NoRedealCellFoundationMoves) {
sr.stock_redeal = false;
sr.stock_deal_count = 3;
sr.cells = 2;
- sr.foundations = true;
+ sr.foundations_present = true;
test_helper::k_plus_stock_test(
sr,
@@ -318,16 +316,16 @@ TEST(KPlusStock, NoRedealCellFoundationMoves) {
},
{
// Cell moves
- move(move::mtype::stock_k_plus, 6, 5, 2),
- move(move::mtype::stock_k_plus, 6, 5, 5),
+ move(move::mtype::stock_k_plus, 6, 5, 3),
+ move(move::mtype::stock_k_plus, 6, 5, 6),
// Foundation moves
- move(move::mtype::stock_k_plus, 6, 1, 2),
+ move(move::mtype::stock_k_plus, 6, 1, 3),
// Regular waste move
- move(move::mtype::regular, 7, 5, 1)
+ move(move::mtype::stock_k_plus, 6, 5, 0)
},
- move(move::mtype::stock_k_plus, 6, 1, 2),
+ move(move::mtype::stock_k_plus, 6, 1, 3),
3, 3,
"2C", "2S"
);
@@ -341,7 +339,7 @@ TEST(KPlusStock, RedealCellFoundationMoves) {
sr.stock_redeal = true;
sr.stock_deal_count = 3;
sr.cells = 2;
- sr.foundations = true;
+ sr.foundations_present = true;
test_helper::k_plus_stock_test(
sr,
@@ -353,20 +351,76 @@ TEST(KPlusStock, RedealCellFoundationMoves) {
},
{
// Cell moves
- move(move::mtype::stock_k_plus, 6, 5, 2),
- move(move::mtype::stock_k_plus, 6, 5, 5),
- move(move::mtype::stock_k_plus, 6, 5, 1),
- move(move::mtype::stock_k_plus, 6, 5, 4),
+ move(move::mtype::stock_k_plus, 6, 5, 3, false, false),
+ move(move::mtype::stock_k_plus, 6, 5, 6, false, true),
+ move(move::mtype::stock_k_plus, 6, 5, 2, false, false),
+ move(move::mtype::stock_k_plus, 6, 5, 5, false, false),
// Foundation moves
- move(move::mtype::stock_k_plus, 6, 1, 2),
- move(move::mtype::stock_k_plus, 6, 2, 4),
+ move(move::mtype::stock_k_plus, 6, 1, 3, false, false),
+ move(move::mtype::stock_k_plus, 6, 2, 5, false, false),
// Regular waste move
- move(move::mtype::regular, 7, 5, 1)
+ move(move::mtype::stock_k_plus, 6, 5, 0)
},
- move(move::mtype::stock_k_plus, 6, 2, 4),
+ move(move::mtype::stock_k_plus, 6, 2, 5, false, false),
1, 5,
"2H", "2C"
);
}
+
+TEST(KPlusStock, RedealCount1BottomStock) {
+ sol_rules sr;
+ sr.tableau_pile_count = 3;
+ sr.build_pol = pol::SAME_SUIT;
+ sr.stock_size = 9;
+ sr.stock_deal_t = sdt::WASTE;
+ sr.stock_redeal = true;
+ sr.stock_deal_count = 1;
+
+ test_helper::k_plus_stock_test(
+ sr,
+ {
+ {"2H","2S","AD","2D"},
+ {},
+ {"3D"},
+ {"3H"},
+ {"2C"}
+ },
+ {
+ move(move::mtype::stock_k_plus, 0, 2, 1, false, false),
+ move(move::mtype::stock_k_plus, 0, 3, 4, false, true)
+ },
+ move(move::mtype::stock_k_plus, 0, 3, 4, false, true),
+ 3, 0,
+ "2D", card()
+ );
+}
+
+TEST(KPlusStock, RedealCount1TopStock) {
+ sol_rules sr;
+ sr.tableau_pile_count = 3;
+ sr.build_pol = pol::SAME_SUIT;
+ sr.stock_size = 9;
+ sr.stock_deal_t = sdt::WASTE;
+ sr.stock_redeal = true;
+ sr.stock_deal_count = 1;
+
+ test_helper::k_plus_stock_test(
+ sr,
+ {
+ {"2H","2S","AD","2D"},
+ {},
+ {"3D"},
+ {"3H"},
+ {"2C"}
+ },
+ {
+ move(move::mtype::stock_k_plus, 0, 2, 1, false, false),
+ move(move::mtype::stock_k_plus, 0, 3, 4, false, true)
+ },
+ move(move::mtype::stock_k_plus, 0, 2, 1, false, false),
+ 3, 0,
+ "AD", card()
+ );
+}
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index cbdeae0..4625163 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -199,7 +199,7 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) {
TEST(LegalMoveGen, Foundations) {
sol_rules sr;
- sr.foundations = true;
+ sr.foundations_present = true;
sr.tableau_pile_count = 4;
game_state gs(sr, string_il{
@@ -223,7 +223,7 @@ TEST(LegalMoveGen, Foundations) {
TEST(LegalMoveGen, FoundationsRemovable) {
sol_rules sr;
- sr.foundations = true;
+ sr.foundations_present = true;
sr.foundations_removable = true;
sr.tableau_pile_count = 1;
@@ -264,7 +264,7 @@ TEST(LegalMoveGen, Cells) {
TEST(LegalMoveGen, StockDealToTableau) {
sol_rules sr;
- sr.foundations = true;
+ sr.foundations_present = true;
sr.tableau_pile_count = 3;
sr.stock_size = 2;
sr.stock_deal_t = sdt::TABLEAU_PILES;
diff --git a/src/test/unit_tests/rules_parser_test.cpp b/src/test/unit_tests/rules_parser_test.cpp
deleted file mode 100644
index 31a7101..0000000
--- a/src/test/unit_tests/rules_parser_test.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-//
-// Created by thecharlesblake on 1/11/18.
-//
-
-#include <gtest/gtest.h>
-
-#include "../../../lib/rapidjson/stringbuffer.h"
-#include "../../../lib/rapidjson/document.h"
-
-#include "../../main/input-output/input/json-parsing/rules_parser.h"
-#include "../../main/input-output/input/json-parsing/json_helper.h"
-
-using namespace std;
-using namespace rapidjson;
-
-void run_rules_parser_test(bool, const char*);
-
-// invalid int, build pol, bool, other
-
-TEST(RulesParser, DefaultGameRules) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 8,
- "build policy": "any-suit",
- "spaces policy": "any",
- "diagonal deal": false,
- "move built group": false,
- "move built group policy": "same-as-build"
- },
- "max rank": 13,
- "two decks": false,
- "hole": false,
- "foundations": true,
- "foundations initial card": false,
- "foundations removable": false,
- "foundations complete piles": false,
- "cells": 0,
- "stock size": 0,
- "stock deal type": "waste",
- "reserve size": 0,
- "reserve stacked": false
-}
-)");
-}
-
-TEST(RulesParser, InvalidType) {
- run_rules_parser_test(false, R"(
-{
- "tableau piles": {
- "count": "13"
- }
-}
-)");
-}
-
-TEST(RulesParser, InvalidNumber) {
- run_rules_parser_test(false, R"(
-{
- "tableau piles": {
- "count": 13
- },
- "max rank": 20
-}
-)");
-}
-
-TEST(RulesParser, InvalidEnum) {
- run_rules_parser_test(false, R"(
-{
- "tableau piles": {
- "count": 13,
- "build policy": "red-black-green"
- }
-}
-)");
-}
-
-TEST(RulesParser, InvalidRuleName) {
- run_rules_parser_test(false, R"(
-{
- "tableau piles": {
- "count number": 13
- }
-}
-)");
-}
-
-TEST(RulesParser, SpanishPatience) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 13
- },
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleSpanishPatience) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3
- },
- "max rank": 2,
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, FreeCell) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "build policy": "red-black"
- },
- "cells": 4
-}
-)");
-}
-
-TEST(RulesParser, SimpleFreeCell) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 4,
- "build policy": "red-black"
- },
- "max rank": 4,
- "cells": 1
-}
-)");
-}
-
-TEST(RulesParser, BakersDozen) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 13,
- "spaces policy": "no-build"
- },
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleBakersDozen) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3,
- "spaces policy": "no-build"
- },
- "max rank": 3,
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, BlackHole) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 17,
- "build policy": "no-build"
- },
- "hole": true,
- "foundations": false
-}
-)");
-}
-
-TEST(RulesParser, SimpleBlackHole) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 4,
- "build policy": "no-build"
- },
- "max rank": 5,
- "hole": true,
- "foundations": false
-}
-)");
-}
-
-TEST(RulesParser, FortunesFavor) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 12,
- "build policy": "same-suit"
- },
- "foundations initial card": true,
- "stock size": 36
-}
-)");
-}
-
-TEST(RulesParser, SimpleFortunesFavor) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3,
- "build policy": "same-suit"
- },
- "max rank": 4,
- "foundations initial card": true,
- "stock size": 3
-}
-)");
-}
-
-TEST(RulesParser, FlowerGarden) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 6
- },
- "reserve size": 16,
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleFlowerGarden) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3
- },
- "max rank": 3,
- "reserve size": 3,
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, Canfield) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 4,
- "build policy": "red-black"
- },
- "stock size": 34,
- "reserve size": 14,
- "reserve stacked": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleCanfield) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3,
- "build policy": "red-black"
- },
- "max rank": 3,
- "stock size": 1,
- "reserve size": 2,
- "reserve stacked": true
-}
-)");
-}
-
-TEST(RulesParser, Somerset) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 10,
- "build policy": "red-black",
- "diagonal deal": true
- },
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleSomerset) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 4,
- "build policy": "red-black",
- "diagonal deal": true
- },
- "max rank": 2,
- "foundations removable": true
-}
-)");
-}
-
-TEST(RulesParser, AlphaStar) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 12,
- "build policy": "same-suit",
- "move built group": true
- },
- "foundations initial card": true
-}
-)");
-}
-
-TEST(RulesParser, SimpleAlphaStar) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 3,
- "build policy": "same-suit",
- "move built group": true
- },
- "max rank": 5,
- "foundations initial card": true
-}
-)");
-}
-
-TEST(RulesParser, Spider) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 10,
- "build policy": "any-suit",
- "move built group": true,
- "move built group policy": "same-suit"
- },
- "foundations complete piles": true,
- "two decks": true,
- "stock size": 50,
- "stock deal type": "tableau piles"
-}
-)");
-}
-
-TEST(RulesParser, SimpleSpider) {
- run_rules_parser_test(true, R"(
-{
- "tableau piles": {
- "count": 4,
- "build policy": "any-suit",
- "move built group": true,
- "move built group policy": "same-suit"
- },
- "foundations complete piles": true,
- "two decks": true,
- "max rank": 3,
- "stock size": 12,
- "stock deal type": "tableau piles"
-}
-)");
-}
-
-void run_rules_parser_test(bool validity, const char* json) {
- Document in_doc;
- in_doc.Parse(json);
- if (in_doc.HasParseError()) {
- throw runtime_error("invalid json");
- }
-
- Document val_doc;
- val_doc.Parse(rules_parser::rules_schema_json().c_str());
- SchemaDocument sd(val_doc);
- SchemaValidator validator(sd);
- bool acc = in_doc.Accept(validator);
- if (acc) {
- ASSERT_TRUE(validity == acc) << "JSON accepted when it should not have "
- "been:\n" << json;
- } else {
- ASSERT_TRUE(validity == acc) << json_helper::schema_err_str(validator)
- << "\n" << json;
- }
-}