diff --git a/v3/main.cpp b/v3/main.cpp index a8fedd7..561a3f6 100644 --- a/v3/main.cpp +++ b/v3/main.cpp @@ -1,14 +1,29 @@ -#include "memory_Context.h" #include #include #include +#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 ; } diff --git a/v3/memory.cpp b/v3/memory.cpp index a18dffd..0b3cb62 100644 --- a/v3/memory.cpp +++ b/v3/memory.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "memory.h" #include "memory_Context.h" //////////////// diff --git a/v3/memory_test.cpp b/v3/memory_test.cpp index e5d65dd..390675a 100644 --- a/v3/memory_test.cpp +++ b/v3/memory_test.cpp @@ -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 && diff --git a/v3/memory_test.h b/v3/memory_test.h new file mode 100644 index 0000000..313d8c5 --- /dev/null +++ b/v3/memory_test.h @@ -0,0 +1,15 @@ +#include + +#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 diff --git a/v3/tPythonC++/CPP.py b/v3/tPythonC++/CPP.py index 27a503a..97c551c 100644 --- a/v3/tPythonC++/CPP.py +++ b/v3/tPythonC++/CPP.py @@ -4,6 +4,7 @@ def includes(): return """#include #include #include +#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}}}"