d
This commit is contained in:
21
v3/main.cpp
21
v3/main.cpp
@@ -1,14 +1,29 @@
|
||||
#include "memory_Context.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "memory_test.h"
|
||||
#include "memory_Context.h"
|
||||
|
||||
extern memory_Context memory_createContext();
|
||||
|
||||
int main() {
|
||||
memory_createContext();
|
||||
std::cout <<
|
||||
"check" //memory_test_generateConstPlayfield()
|
||||
std::cout
|
||||
<< memory_test_generateConstPlayfield()
|
||||
<< std::endl
|
||||
<< memory_test_selectItem_1x()
|
||||
<< std::endl
|
||||
<< memory_test_selectItem_2x()
|
||||
<< std::endl
|
||||
<< memory_test_selectItem_3x()
|
||||
<< std::endl
|
||||
<< memory_test_shouldDeselectMismatchedItems()
|
||||
<< std::endl
|
||||
<< memory_test_shouldDeselectMismatchedItems_itemTwice()
|
||||
<< std::endl
|
||||
<< memory_test_shouldDetectVictory()
|
||||
<< std::endl
|
||||
<< memory_test_shouldHideMatchingItems()
|
||||
<< std::endl
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "memory.h"
|
||||
#include "memory_Context.h"
|
||||
|
||||
////////////////
|
||||
|
||||
@@ -29,10 +29,10 @@ std::string memory_test_selectItem_1x(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first item.;
|
||||
// Select the first item.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
# See if it's in selectedItems now.;
|
||||
// See if it's in selectedItems now.
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
c.selectedItems.size() == 1 &&
|
||||
@@ -50,12 +50,12 @@ std::string memory_test_selectItem_2x(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first two items.;
|
||||
// Select the first two items.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
c = memory_selectItem(c);
|
||||
# See if both items are selected now.;
|
||||
// See if both items are selected now.
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
c.selectedItems.size() == 2 &&
|
||||
@@ -74,14 +74,14 @@ std::string memory_test_selectItem_3x(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select three items.;
|
||||
// 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.;
|
||||
// See if only one (last) item is selected now.
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
c.selectedItems.size() == 1 &&
|
||||
@@ -100,14 +100,14 @@ std::string memory_test_shouldDeselectMismatchedItems(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select two items of different groups.;
|
||||
// Select two items of different groups.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 2;
|
||||
c = memory_selectItem(c);
|
||||
# Detect mismatching.;
|
||||
// Detect mismatching.
|
||||
c = memory_shouldDeselectMismatchedItems(c);
|
||||
# See if the two selected items do not match.;
|
||||
// See if the two selected items do not match.
|
||||
if (
|
||||
c.recentField == "mismatchedItems" &&
|
||||
c.mismatchedItems.size() == 2 &&
|
||||
@@ -127,14 +127,14 @@ std::string memory_test_shouldDeselectMismatchedItems_itemTwice(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the same item twice.;
|
||||
// Select the same item twice.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
# Detect mismatching.;
|
||||
// Detect mismatching.
|
||||
c = memory_shouldDeselectMismatchedItems(c);
|
||||
# See if the two selected items do not match.;
|
||||
// See if the two selected items do not match.
|
||||
if (
|
||||
c.recentField == "mismatchedItems" &&
|
||||
c.mismatchedItems.size() == 1 &&
|
||||
@@ -156,23 +156,23 @@ std::string memory_test_shouldDetectVictory(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first two items of the same group.;
|
||||
// Select the first two items of the same group.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
c = memory_selectItem(c);
|
||||
# Hide the first pair.;
|
||||
// Hide the first pair.
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# Select the last two items of the same group.;
|
||||
// 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.;
|
||||
// Hide the second pair.
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# Detect victory.;
|
||||
// Detect victory.
|
||||
c = memory_shouldDetectVictory(c);
|
||||
# See if victory has been detected.;
|
||||
// See if victory has been detected.
|
||||
if (
|
||||
c.recentField == "victory" &&
|
||||
c.victory == true
|
||||
@@ -190,14 +190,14 @@ std::string memory_test_shouldHideMatchingItems(
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select two items of the same group.;
|
||||
// Select two items of the same group.
|
||||
c.selectedId = 0;
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
c = memory_selectItem(c);
|
||||
# Hide matching items.;
|
||||
// Hide matching items.
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# See if the two selected items match.;
|
||||
// See if the two selected items match.
|
||||
if (
|
||||
c.recentField == "hiddenItems" &&
|
||||
c.hiddenItems.size() == 2 &&
|
||||
|
||||
15
v3/memory_test.h
Normal file
15
v3/memory_test.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <string>
|
||||
|
||||
#ifndef memory_test_HEADER
|
||||
#define memory_test_HEADER
|
||||
|
||||
std::string memory_test_generateConstPlayfield();
|
||||
std::string memory_test_selectItem_1x();
|
||||
std::string memory_test_selectItem_2x();
|
||||
std::string memory_test_selectItem_3x();
|
||||
std::string memory_test_shouldDeselectMismatchedItems();
|
||||
std::string memory_test_shouldDeselectMismatchedItems_itemTwice();
|
||||
std::string memory_test_shouldDetectVictory();
|
||||
std::string memory_test_shouldHideMatchingItems();
|
||||
|
||||
#endif // memory_test_HEADER
|
||||
@@ -4,6 +4,7 @@ def includes():
|
||||
return """#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "memory.h"
|
||||
#include "memory_Context.h"
|
||||
"""
|
||||
|
||||
@@ -47,6 +48,7 @@ def translateStatement(s, state):
|
||||
ss = s.lstrip()
|
||||
posColon = ss.find(": ")
|
||||
posComma = ss.find(", ")
|
||||
posComment = ss.find("# ")
|
||||
posCtx = ss.find("c.")
|
||||
posEqual = ss.find(" = ")
|
||||
posFor = ss.find("for ")
|
||||
@@ -56,6 +58,10 @@ def translateStatement(s, state):
|
||||
posClosingScope = ss.find("#}")
|
||||
posOpenSquareBracket = ss.find("[")
|
||||
|
||||
# # -> //
|
||||
if posComment != -1:
|
||||
return replaceComment(s)
|
||||
|
||||
# #} -> }
|
||||
if posClosingScope != -1:
|
||||
return f"{indentation}}}"
|
||||
|
||||
Reference in New Issue
Block a user