|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #include <map>
- #include <string>
- #include <vector>
- #include "memory_Context.h"
-
- std::string memory_test_generateConstPlayfield(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- if (
- 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_generateConstPlayfield";
- }
- return "ERR: memory_generateConstPlayfield";
- }
-
-
-
- std::string memory_test_selectItem_1x(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select the first item.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- # See if it's in selectedItems now.;
- if (
- c.recentField == "selectedItems" &&
- c.selectedItems.size() == 1 &&
- c.selectedItems[0] == 0
- ) {
- return "OK: memory_selectItem_1x";
- }
- return "ERR: memory_selectItem_1x";
- }
-
-
-
- std::string memory_test_selectItem_2x(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select the first two items.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 1;
- auto c = memory_selectItem(c);
- # See if both items are selected now.;
- if (
- c.recentField == "selectedItems" &&
- c.selectedItems.size() == 2 &&
- c.selectedItems[0] == 0 &&
- c.selectedItems[1] == 1
- ) {
- return "OK: memory_selectItem_2x";
- }
- return "ERR: memory_selectItem_2x";
- }
-
-
-
- std::string memory_test_selectItem_3x(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select three items.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 1;
- auto c = memory_selectItem(c);
- c.selectedId = 2;
- auto c = memory_selectItem(c);
- # See if only one (last) item is selected now.;
- if (
- c.recentField == "selectedItems" &&
- c.selectedItems.size() == 1 &&
- c.selectedItems[0] == 2
- ) {
- return "OK: memory_selectItem_3x";
- }
- return "ERR: memory_selectItem_3x";
- }
-
-
-
-
- std::string memory_test_shouldDeselectMismatchedItems(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select two items of different groups.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 2;
- auto c = memory_selectItem(c);
- # Detect mismatching.;
- auto c = memory_shouldDeselectMismatchedItems(c);
- # See if the two selected items do not match.;
- if (
- c.recentField == "mismatchedItems" &&
- c.mismatchedItems.size() == 2 &&
- c.mismatchedItems[0] == 0 &&
- c.mismatchedItems[1] == 2
- ) {
- return "OK: memory_shouldDeselectMismatchedItems";
- }
- return "ERR: memory_shouldDeselectMismatchedItems";
- }
-
-
-
-
- std::string memory_test_shouldDeselectMismatchedItems_itemTwice(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select the same item twice.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- # Detect mismatching.;
- auto c = memory_shouldDeselectMismatchedItems(c);
- # See if the two selected items do not match.;
- if (
- c.recentField == "mismatchedItems" &&
- c.mismatchedItems.size() == 1 &&
- c.mismatchedItems[0] == 0
- ) {
- return "OK: memory_shouldDeselectMismatchedItems_itemTwice";
- }
- return "ERR: memory_shouldDeselectMismatchedItems_itemTwice";
- }
-
-
-
-
-
-
-
- std::string memory_test_shouldDetectVictory(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select the first two items of the same group.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 1;
- auto c = memory_selectItem(c);
- # Hide the first pair.;
- auto c = memory_shouldHideMatchingItems(c);
- # Select the last two items of the same group.;
- c.selectedId = 2;
- auto c = memory_selectItem(c);
- c.selectedId = 3;
- auto c = memory_selectItem(c);
- # Hide the second pair.;
- auto c = memory_shouldHideMatchingItems(c);
- # Detect victory.;
- auto c = memory_shouldDetectVictory(c);
- # See if victory has been detected.;
- if (
- c.recentField == "victory" &&
- c.victory == true
- ) {
- return "OK: memory_shouldDetectVictory";
- }
- return "ERR: memory_shouldDetectVictory";
- }
-
-
-
-
- std::string memory_test_shouldHideMatchingItems(
- ) {
- auto c = memory_createContext();
- c.playfieldSize = 2;
- auto c = memory_generateConstPlayfield(c);
- # Select two items of the same group.;
- c.selectedId = 0;
- auto c = memory_selectItem(c);
- c.selectedId = 1;
- auto c = memory_selectItem(c);
- # Hide matching items.;
- auto c = memory_shouldHideMatchingItems(c);
- # See if the two selected items match.;
- if (
- c.recentField == "hiddenItems" &&
- c.hiddenItems.size() == 2 &&
- c.hiddenItems[0] == 0 &&
- c.hiddenItems[1] == 1
- ) {
- return "OK: memory_shouldHideMatchingItems";
- }
- return "ERR: memory_shouldHideMatchingItems";
- }
-
|