@@ -7,24 +7,172 @@ | |||||
#include "memory_Context.h" | #include "memory_Context.h" | ||||
#include "shell.h" | #include "shell.h" | ||||
// Exit | |||||
// | |||||
// Conditions: | |||||
// 1. `e`, `exit`, `q`, or `quit` was entered | |||||
// 2. Victory has just been reported | |||||
memory_Context cli_exit( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "input" && | |||||
( | |||||
c.input == "e" || | |||||
c.input == "exit" || | |||||
c.input == "q" || | |||||
c.input == "quit" | |||||
) | |||||
) { | |||||
c.exit = true; | |||||
c.recentField = "exit"; | |||||
return c; | |||||
} | |||||
if ( | |||||
c.recentField == "outputVictory" | |||||
) { | |||||
c.exit = true; | |||||
c.recentField = "exit"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Ask user to go on | |||||
// | |||||
// Conditions: | |||||
// 1. Items have just matched and there are still items left to select | |||||
memory_Context cli_goOn( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "outputMatchedItems" && | |||||
c.hiddenItems.size() != c.playfieldItems.size() | |||||
) { | |||||
c.outputGoOn = "Go on:"; | |||||
c.recentField = "outputGoOn"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Greet the user | // Greet the user | ||||
cli_Context cli_greetUser( | |||||
cli_Context c | |||||
// | |||||
// Conditions: | |||||
// 1. Just launched | |||||
memory_Context cli_greetUser( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "didLaunch" && | |||||
c.didLaunch == true | |||||
) { | |||||
c.outputGreeting = "OGS Memory Command Line Interface"; | |||||
c.recentField = "outputGreeting"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Ask user to select second item to have a pair of selected items | |||||
// | |||||
// Conditions: | |||||
// 1. Single item has just been selected | |||||
memory_Context cli_promptSecondItemSelection( | |||||
memory_Context c | |||||
) { | ) { | ||||
c.outputGreeting = "OGS Memory Textual UI"; | |||||
c.recentField = "outputGreeting"; | |||||
if ( | |||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 1 | |||||
) { | |||||
c.outputPromptSelection = "Select the second item now:"; | |||||
c.recentField = "outputPromptSelection"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Report matched items | |||||
// | |||||
// Conditions: | |||||
// 1. Items were hidden (i.e., they matched) | |||||
memory_Context cli_reportMatchedItems( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "hiddenItems" | |||||
) { | |||||
c.outputMatchedItems = "Items matched!"; | |||||
c.recentField = "outputMatchedItems"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Report victory | |||||
memory_Context cli_reportVictory( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "victory" | |||||
) { | |||||
c.outputVictory = "VICTORY! The game is over now"; | |||||
c.recentField = "outputVictory"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
// Select item | |||||
// | |||||
// Conditions: | |||||
// 1. Id is digit | |||||
memory_Context cli_selectItem( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "input" && | |||||
c.input.isdigit() | |||||
) { | |||||
// CLI ids start with 1 while memory module has ids starting with 0 | |||||
// Convert CLI id to memory id | |||||
c.selectedId = int(c.input) - 1; | |||||
c.recentField = "selectedId"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | return c; | ||||
} | } | ||||
// Show help (aka commands) | // Show help (aka commands) | ||||
cli_Context cli_showHelp( | |||||
cli_Context c | |||||
// | |||||
// Conditions: | |||||
// 1. Just launched | |||||
// 1. `h` or `help` was entered | |||||
memory_Context cli_showHelp( | |||||
memory_Context c | |||||
) { | ) { | ||||
if ( | if ( | ||||
c.input == "h" || | |||||
c.input == "help" | |||||
( | |||||
c.recentField == "didLaunch" && | |||||
c.didLaunch == true | |||||
) || | |||||
( | |||||
c.recentField == "input" && | |||||
c.input == "h" | |||||
) || | |||||
( | |||||
c.recentField == "input" && | |||||
c.input == "help" | |||||
) | |||||
) { | ) { | ||||
c.outputHelp = "Commands:\n\te, exit, q, quit\n\t\tExit\n\th, help\n\t\tList commands\n"; | |||||
c.outputHelp = "Commands:\n\te, exit, q, quit\n\t\tExit\n\th, help\n\t\tList commands\n\t1, 2, 3, ...\n\t\tSelect item\nEnter your choice:"; | |||||
c.recentField = "outputHelp"; | c.recentField = "outputHelp"; | ||||
return c; | return c; | ||||
} | } | ||||
@@ -32,3 +180,41 @@ cli_Context cli_showHelp( | |||||
return c; | return c; | ||||
} | } | ||||
// Report mismatched items | |||||
memory_Context cli_reportMismatchedItems( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.recentField == "mismatchedItems" | |||||
) { | |||||
c.outputMismatchedItems = "Wrong! Try again:"; | |||||
c.recentField = "outputMismatchedItems"; | |||||
return c; | |||||
} | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
//// Report selection of invalid item ids | |||||
//// | |||||
//// Conditions: | |||||
//// 1. Index out of bounds: less than minimum | |||||
//// 2. Index out of bounds: greater than maximum | |||||
//// 3. Item is already hidden | |||||
////@llm_by_value | |||||
////def cli_shouldReportInvalidItemSelection( | |||||
//// c: cli_Context | |||||
////) -> cli_Context: | |||||
//// if ( | |||||
//// c.recentField == "cMemory" and | |||||
//// c.cMemory.recentField == "selectedItems" and | |||||
//// len(c.cMemory.selectedItems) == 1 | |||||
//// ): | |||||
//// c.outputPromptSelection = "Select the second item now:" | |||||
//// c.recentField = "outputPromptSelection" | |||||
//// return c | |||||
//// //} | |||||
//// c.recentField = "none" | |||||
//// return c | |||||
//////} | |||||
@@ -7,9 +7,135 @@ | |||||
#include "memory_Context.h" | #include "memory_Context.h" | ||||
#include "shell.h" | #include "shell.h" | ||||
std::string cli_test_exit_e( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "e"; | |||||
c.recentField = "input"; | |||||
c = cli_exit(c); | |||||
if ( | |||||
c.recentField == "exit" | |||||
) { | |||||
return "OK: cli_exit_e"; | |||||
} | |||||
return "ERR: cli_exit_e"; | |||||
} | |||||
std::string cli_test_exit_exit( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "exit"; | |||||
c.recentField = "input"; | |||||
c = cli_exit(c); | |||||
if ( | |||||
c.recentField == "exit" | |||||
) { | |||||
return "OK: cli_exit_exit"; | |||||
} | |||||
return "ERR: cli_exit_e"; | |||||
} | |||||
std::string cli_test_exit_victory( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.playfieldSize = 2; | |||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | |||||
// Match the first pair of tiles. | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "2"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
// Match the second pair of tiles. | |||||
c.input = "3"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "4"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
c = memory_detectVictory(c); | |||||
c = cli_reportVictory(c); | |||||
c = cli_exit(c); | |||||
if ( | |||||
c.recentField == "exit" | |||||
) { | |||||
return "OK: cli_exit_victory"; | |||||
} | |||||
return "ERR: cli_exit_victory"; | |||||
} | |||||
std::string cli_test_exit_q( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "q"; | |||||
c.recentField = "input"; | |||||
c = cli_exit(c); | |||||
if ( | |||||
c.recentField == "exit" | |||||
) { | |||||
return "OK: cli_exit_q"; | |||||
} | |||||
return "ERR: cli_exit_q"; | |||||
} | |||||
std::string cli_test_exit_quit( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "quit"; | |||||
c.recentField = "input"; | |||||
c = cli_exit(c); | |||||
if ( | |||||
c.recentField == "exit" | |||||
) { | |||||
return "OK: cli_exit_quit"; | |||||
} | |||||
return "ERR: cli_exit_quit"; | |||||
} | |||||
std::string cli_test_goOn( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.playfieldSize = 2; | |||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | |||||
// Match the first pair of items. | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "2"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
c = cli_reportMatchedItems(c); | |||||
c = cli_goOn(c); | |||||
if ( | |||||
c.recentField == "outputGoOn" | |||||
) { | |||||
return "OK: cli_goOn"; | |||||
} | |||||
return "ERR: cli_goOn"; | |||||
} | |||||
std::string cli_test_greetUser( | std::string cli_test_greetUser( | ||||
) { | ) { | ||||
auto c = cli_createContext(); | |||||
auto c = memory_createContext(); | |||||
c.didLaunch = true; | |||||
c.recentField = "didLaunch"; | |||||
c = cli_greetUser(c); | c = cli_greetUser(c); | ||||
if ( | if ( | ||||
c.recentField == "outputGreeting" | c.recentField == "outputGreeting" | ||||
@@ -19,10 +145,90 @@ std::string cli_test_greetUser( | |||||
return "ERR: cli_greetUser"; | return "ERR: cli_greetUser"; | ||||
} | } | ||||
std::string cli_test_promptSecondItemSelection( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = cli_promptSecondItemSelection(c); | |||||
if ( | |||||
c.recentField == "outputPromptSelection" | |||||
) { | |||||
return "OK: cli_promptSecondItemSelection"; | |||||
} | |||||
return "ERR: cli_promptSecondItemSelection"; | |||||
} | |||||
std::string cli_test_reportMatchedItems( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.playfieldSize = 2; | |||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "2"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
c = cli_reportMatchedItems(c); | |||||
if ( | |||||
c.recentField == "outputMatchedItems" | |||||
) { | |||||
return "OK: cli_reportMatchedItems"; | |||||
} | |||||
return "ERR: cli_reportMatchedItems"; | |||||
} | |||||
std::string cli_test_reportMismatchedItems( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.playfieldSize = 2; | |||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "3"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_detectMismatchedItems(c); | |||||
c = cli_reportMismatchedItems(c); | |||||
if ( | |||||
c.recentField == "outputMismatchedItems" | |||||
) { | |||||
return "OK: cli_reportMismatchedItems"; | |||||
} | |||||
return "ERR: cli_reportMismatchedItems"; | |||||
} | |||||
std::string cli_test_selectItem( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
if ( | |||||
c.recentField == "selectedId" && | |||||
c.selectedId == 0 | |||||
) { | |||||
return "OK: cli_selectItem"; | |||||
} | |||||
return "ERR: cli_selectItem"; | |||||
} | |||||
std::string cli_test_showHelp_h( | std::string cli_test_showHelp_h( | ||||
) { | ) { | ||||
auto c = cli_createContext(); | |||||
auto c = memory_createContext(); | |||||
c.input = "h"; | c.input = "h"; | ||||
c.recentField = "input"; | |||||
c = cli_showHelp(c); | c = cli_showHelp(c); | ||||
if ( | if ( | ||||
c.recentField == "outputHelp" | c.recentField == "outputHelp" | ||||
@@ -34,8 +240,9 @@ std::string cli_test_showHelp_h( | |||||
std::string cli_test_showHelp_help( | std::string cli_test_showHelp_help( | ||||
) { | ) { | ||||
auto c = cli_createContext(); | |||||
auto c = memory_createContext(); | |||||
c.input = "help"; | c.input = "help"; | ||||
c.recentField = "input"; | |||||
c = cli_showHelp(c); | c = cli_showHelp(c); | ||||
if ( | if ( | ||||
c.recentField == "outputHelp" | c.recentField == "outputHelp" | ||||
@@ -45,3 +252,58 @@ std::string cli_test_showHelp_help( | |||||
return "ERR: cli_showHelp_help"; | return "ERR: cli_showHelp_help"; | ||||
} | } | ||||
std::string cli_test_reportVictory( | |||||
) { | |||||
auto c = memory_createContext(); | |||||
c.playfieldSize = 2; | |||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | |||||
// Match the first pair of tiles. | |||||
c.input = "1"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "2"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
// Match the second pair of tiles. | |||||
c.input = "3"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c.input = "4"; | |||||
c.recentField = "input"; | |||||
c = cli_selectItem(c); | |||||
c = memory_selectItem(c); | |||||
c = memory_hideMatchingItems(c); | |||||
c = memory_detectVictory(c); | |||||
c = cli_reportVictory(c); | |||||
if ( | |||||
c.recentField == "outputVictory" | |||||
) { | |||||
return "OK: cli_reportVictory"; | |||||
} | |||||
return "ERR: cli_reportVictory"; | |||||
} | |||||
//def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin( | |||||
//) -> str: | |||||
// c = cli_createContext() | |||||
// c.cMemory = memory_createContext() | |||||
// c.input = "0" | |||||
// c = cli_selectItem(c) | |||||
// c = cli_shouldReportInvalidItemSelection(c) | |||||
// if ( | |||||
// c.recentField == "outputInvalidItemSelection" | |||||
// ): | |||||
// return "OK: cli_shouldReportInvalidItemSelection" | |||||
// //} | |||||
// return "ERR: cli_shouldReportInvalidItemSelection" | |||||
////} | |||||
// | |||||
@@ -7,52 +7,13 @@ | |||||
#include "memory_Context.h" | #include "memory_Context.h" | ||||
#include "shell.h" | #include "shell.h" | ||||
//////////////// | |||||
// Client initiated input | |||||
//////////////// | |||||
// Generate constant playfield | |||||
memory_Context memory_generateConstPlayfield( | |||||
memory_Context c | |||||
) { | |||||
std::map<int, int> idGroups = { }; | |||||
auto id = 0; | |||||
for (auto gid = 0; gid < c.playfieldSize; ++gid) { | |||||
idGroups[id] = gid; | |||||
id += 1; | |||||
idGroups[id] = gid; | |||||
id += 1; | |||||
} | |||||
c.playfieldItems = idGroups; | |||||
c.recentField = "playfieldItems"; | |||||
return c; | |||||
} | |||||
// Select item | |||||
memory_Context memory_selectItem( | |||||
memory_Context c | |||||
) { | |||||
if ( | |||||
c.selectedItems.size() == 2 | |||||
) { | |||||
c.selectedItems.clear(); | |||||
} | |||||
c.selectedItems.push_back(c.selectedId); | |||||
c.recentField = "selectedItems"; | |||||
return c; | |||||
} | |||||
//////////////// | |||||
// System initiated reaction | |||||
//////////////// | |||||
// Deselect mismatched items | |||||
// Detect mismatched items | |||||
// | // | ||||
// Conditions: | // Conditions: | ||||
// 0. Two items has just been selected | // 0. Two items has just been selected | ||||
// 1. The same item has been selected twice | // 1. The same item has been selected twice | ||||
// 2. Selected items are of different groups | // 2. Selected items are of different groups | ||||
memory_Context memory_shouldDeselectMismatchedItems( | |||||
memory_Context memory_detectMismatchedItems( | |||||
memory_Context c | memory_Context c | ||||
) { | ) { | ||||
if (!( | if (!( | ||||
@@ -87,7 +48,7 @@ memory_Context memory_shouldDeselectMismatchedItems( | |||||
// | // | ||||
// Conditions: | // Conditions: | ||||
// 1. Matching items have just been hidden and all items are hidden now | // 1. Matching items have just been hidden and all items are hidden now | ||||
memory_Context memory_shouldDetectVictory( | |||||
memory_Context memory_detectVictory( | |||||
memory_Context c | memory_Context c | ||||
) { | ) { | ||||
if ( | if ( | ||||
@@ -102,11 +63,40 @@ memory_Context memory_shouldDetectVictory( | |||||
return c; | return c; | ||||
} | } | ||||
// Generate constant playfield | |||||
// | |||||
// Conditions: | |||||
// 1. Size has just been specified | |||||
// | |||||
// Both ids and group ids start with 0 | |||||
memory_Context memory_generateConstPlayfield( | |||||
memory_Context c | |||||
) { | |||||
if (!( | |||||
c.recentField == "playfieldSize" | |||||
)) { | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
std::map<int, int> idGroups = { }; | |||||
auto id = 0; | |||||
for (auto gid = 0; gid < c.playfieldSize; ++gid) { | |||||
idGroups[id] = gid; | |||||
id += 1; | |||||
idGroups[id] = gid; | |||||
id += 1; | |||||
} | |||||
c.playfieldItems = idGroups; | |||||
c.recentField = "playfieldItems"; | |||||
return c; | |||||
} | |||||
// Hide matching selected items | // Hide matching selected items | ||||
// | // | ||||
// Conditions: | // Conditions: | ||||
// 1. Two items are selected and they are of the same group | // 1. Two items are selected and they are of the same group | ||||
memory_Context memory_shouldHideMatchingItems( | |||||
memory_Context memory_hideMatchingItems( | |||||
memory_Context c | memory_Context c | ||||
) { | ) { | ||||
if ( | if ( | ||||
@@ -123,3 +113,28 @@ memory_Context memory_shouldHideMatchingItems( | |||||
return c; | return c; | ||||
} | } | ||||
// Select item | |||||
// | |||||
// Conditions: | |||||
// 1. Id has just been specified for selection | |||||
memory_Context memory_selectItem( | |||||
memory_Context c | |||||
) { | |||||
if (!( | |||||
c.recentField == "selectedId" | |||||
)) { | |||||
c.recentField = "none"; | |||||
return c; | |||||
} | |||||
if ( | |||||
c.selectedItems.size() == 2 | |||||
) { | |||||
c.selectedItems.clear(); | |||||
} | |||||
c.selectedItems.push_back(c.selectedId); | |||||
c.recentField = "selectedItems"; | |||||
return c; | |||||
} | |||||
@@ -7,208 +7,232 @@ | |||||
#include "memory_Context.h" | #include "memory_Context.h" | ||||
#include "shell.h" | #include "shell.h" | ||||
std::string memory_test_generateConstPlayfield( | |||||
std::string memory_test_detectMismatchedItems( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select two items of different groups. | |||||
c.selectedId = 0; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
c.selectedId = 2; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
// Detect mismatching. | |||||
c = memory_detectMismatchedItems(c); | |||||
// See if the two selected items do not match. | |||||
if ( | if ( | ||||
c.recentField == "playfieldItems" && | |||||
c.playfieldItems.size() == 4 && | |||||
c.playfieldItems[0] == 0 && | |||||
c.playfieldItems[1] == 0 && | |||||
c.playfieldItems[2] == 1 && | |||||
c.playfieldItems[3] == 1 | |||||
c.recentField == "mismatchedItems" && | |||||
c.mismatchedItems.size() == 2 && | |||||
c.mismatchedItems[0] == 0 && | |||||
c.mismatchedItems[1] == 2 | |||||
) { | ) { | ||||
return "OK: memory_generateConstPlayfield"; | |||||
return "OK: memory_detectMismatchedItems"; | |||||
} | } | ||||
return "ERR: memory_generateConstPlayfield"; | |||||
return "ERR: memory_detectMismatchedItems"; | |||||
} | } | ||||
std::string memory_test_selectItem_1x( | |||||
std::string memory_test_detectMismatchedItems_itemTwice( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select the first item. | |||||
// Select the same item twice. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// See if it's in selectedItems now. | |||||
c.selectedId = 0; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
// Detect mismatching. | |||||
c = memory_detectMismatchedItems(c); | |||||
// See if the two selected items do not match. | |||||
if ( | if ( | ||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 1 && | |||||
c.selectedItems[0] == 0 | |||||
c.recentField == "mismatchedItems" && | |||||
c.mismatchedItems.size() == 1 && | |||||
c.mismatchedItems[0] == 0 | |||||
) { | ) { | ||||
return "OK: memory_selectItem_1x"; | |||||
return "OK: memory_detectMismatchedItems_itemTwice"; | |||||
} | } | ||||
return "ERR: memory_selectItem_1x"; | |||||
return "ERR: memory_detectMismatchedItems_itemTwice"; | |||||
} | } | ||||
std::string memory_test_selectItem_2x( | |||||
std::string memory_test_detectVictory( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select the first two items. | |||||
// Select the first two items of the same group. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
c.selectedId = 1; | c.selectedId = 1; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// See if both items are selected now. | |||||
// Hide the first pair. | |||||
c = memory_hideMatchingItems(c); | |||||
// Select the last two items of the same group. | |||||
c.selectedId = 2; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
c.selectedId = 3; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
// Hide the second pair. | |||||
c = memory_hideMatchingItems(c); | |||||
// Detect victory. | |||||
c = memory_detectVictory(c); | |||||
// See if victory has been detected. | |||||
if ( | if ( | ||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 2 && | |||||
c.selectedItems[0] == 0 && | |||||
c.selectedItems[1] == 1 | |||||
c.recentField == "victory" && | |||||
c.victory == true | |||||
) { | ) { | ||||
return "OK: memory_selectItem_2x"; | |||||
return "OK: memory_detectVictory"; | |||||
} | } | ||||
return "ERR: memory_selectItem_2x"; | |||||
return "ERR: memory_detectVictory"; | |||||
} | } | ||||
std::string memory_test_selectItem_3x( | |||||
std::string memory_test_generateConstPlayfield( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select three items. | |||||
c.selectedId = 0; | |||||
c = memory_selectItem(c); | |||||
c.selectedId = 1; | |||||
c = memory_selectItem(c); | |||||
c.selectedId = 2; | |||||
c = memory_selectItem(c); | |||||
// See if only one (last) item is selected now. | |||||
if ( | if ( | ||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 1 && | |||||
c.selectedItems[0] == 2 | |||||
c.recentField == "playfieldItems" && | |||||
c.playfieldItems.size() == 4 && | |||||
c.playfieldItems[0] == 0 && | |||||
c.playfieldItems[1] == 0 && | |||||
c.playfieldItems[2] == 1 && | |||||
c.playfieldItems[3] == 1 | |||||
) { | ) { | ||||
return "OK: memory_selectItem_3x"; | |||||
return "OK: memory_generateConstPlayfield"; | |||||
} | } | ||||
return "ERR: memory_selectItem_3x"; | |||||
return "ERR: memory_generateConstPlayfield"; | |||||
} | } | ||||
std::string memory_test_shouldDeselectMismatchedItems( | |||||
std::string memory_test_hideMatchingItems( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select two items of different groups. | |||||
// Select two items of the same group. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
c.selectedId = 2; | |||||
c.selectedId = 1; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// Detect mismatching. | |||||
c = memory_shouldDeselectMismatchedItems(c); | |||||
// See if the two selected items do not match. | |||||
// Hide matching items. | |||||
c = memory_hideMatchingItems(c); | |||||
// See if the two selected items match. | |||||
if ( | if ( | ||||
c.recentField == "mismatchedItems" && | |||||
c.mismatchedItems.size() == 2 && | |||||
c.mismatchedItems[0] == 0 && | |||||
c.mismatchedItems[1] == 2 | |||||
c.recentField == "hiddenItems" && | |||||
c.hiddenItems.size() == 2 && | |||||
c.hiddenItems[0] == 0 && | |||||
c.hiddenItems[1] == 1 | |||||
) { | ) { | ||||
return "OK: memory_shouldDeselectMismatchedItems"; | |||||
return "OK: memory_hideMatchingItems"; | |||||
} | } | ||||
return "ERR: memory_shouldDeselectMismatchedItems"; | |||||
return "ERR: memory_hideMatchingItems"; | |||||
} | } | ||||
std::string memory_test_shouldDeselectMismatchedItems_itemTwice( | |||||
std::string memory_test_selectItem_1x( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select the same item twice. | |||||
c.selectedId = 0; | |||||
c = memory_selectItem(c); | |||||
// Select the first item. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// Detect mismatching. | |||||
c = memory_shouldDeselectMismatchedItems(c); | |||||
// See if the two selected items do not match. | |||||
// See if it's in selectedItems now. | |||||
if ( | if ( | ||||
c.recentField == "mismatchedItems" && | |||||
c.mismatchedItems.size() == 1 && | |||||
c.mismatchedItems[0] == 0 | |||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 1 && | |||||
c.selectedItems[0] == 0 | |||||
) { | ) { | ||||
return "OK: memory_shouldDeselectMismatchedItems_itemTwice"; | |||||
return "OK: memory_selectItem_1x"; | |||||
} | } | ||||
return "ERR: memory_shouldDeselectMismatchedItems_itemTwice"; | |||||
return "ERR: memory_selectItem_1x"; | |||||
} | } | ||||
std::string memory_test_shouldDetectVictory( | |||||
std::string memory_test_selectItem_2x( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select the first two items of the same group. | |||||
// Select the first two items. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
c.selectedId = 1; | c.selectedId = 1; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// Hide the first pair. | |||||
c = memory_shouldHideMatchingItems(c); | |||||
// Select the last two items of the same group. | |||||
c.selectedId = 2; | |||||
c = memory_selectItem(c); | |||||
c.selectedId = 3; | |||||
c = memory_selectItem(c); | |||||
// Hide the second pair. | |||||
c = memory_shouldHideMatchingItems(c); | |||||
// Detect victory. | |||||
c = memory_shouldDetectVictory(c); | |||||
// See if victory has been detected. | |||||
// See if both items are selected now. | |||||
if ( | if ( | ||||
c.recentField == "victory" && | |||||
c.victory == true | |||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 2 && | |||||
c.selectedItems[0] == 0 && | |||||
c.selectedItems[1] == 1 | |||||
) { | ) { | ||||
return "OK: memory_shouldDetectVictory"; | |||||
return "OK: memory_selectItem_2x"; | |||||
} | } | ||||
return "ERR: memory_shouldDetectVictory"; | |||||
return "ERR: memory_selectItem_2x"; | |||||
} | } | ||||
std::string memory_test_shouldHideMatchingItems( | |||||
std::string memory_test_selectItem_3x( | |||||
) { | ) { | ||||
auto c = memory_createContext(); | auto c = memory_createContext(); | ||||
c.playfieldSize = 2; | c.playfieldSize = 2; | ||||
c.recentField = "playfieldSize"; | |||||
c = memory_generateConstPlayfield(c); | c = memory_generateConstPlayfield(c); | ||||
// Select two items of the same group. | |||||
// Select three items. | |||||
c.selectedId = 0; | c.selectedId = 0; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
c.selectedId = 1; | c.selectedId = 1; | ||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | c = memory_selectItem(c); | ||||
// Hide matching items. | |||||
c = memory_shouldHideMatchingItems(c); | |||||
// See if the two selected items match. | |||||
c.selectedId = 2; | |||||
c.recentField = "selectedId"; | |||||
c = memory_selectItem(c); | |||||
// See if only one (last) item is selected now. | |||||
if ( | if ( | ||||
c.recentField == "hiddenItems" && | |||||
c.hiddenItems.size() == 2 && | |||||
c.hiddenItems[0] == 0 && | |||||
c.hiddenItems[1] == 1 | |||||
c.recentField == "selectedItems" && | |||||
c.selectedItems.size() == 1 && | |||||
c.selectedItems[0] == 2 | |||||
) { | ) { | ||||
return "OK: memory_shouldHideMatchingItems"; | |||||
return "OK: memory_selectItem_3x"; | |||||
} | } | ||||
return "ERR: memory_shouldHideMatchingItems"; | |||||
return "ERR: memory_selectItem_3x"; | |||||
} | } | ||||