From 2af1bbca2f277e133bd29361ad5de43d4463a434 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Fri, 2 Aug 2024 14:50:26 +0200 Subject: [PATCH] Solve remove --- tested/languages/cpp/generators.py | 4 ++- tested/manual.py | 2 +- tests/exercises/remove/evaluation/full.tson | 27 +++++++++++++++++++++ tests/exercises/remove/solution/correct.cpp | 13 ++++++++++ tests/exercises/remove/solution/wrong.cpp | 12 +++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/exercises/remove/solution/correct.cpp create mode 100644 tests/exercises/remove/solution/wrong.cpp diff --git a/tested/languages/cpp/generators.py b/tested/languages/cpp/generators.py index 4970a536..bba2927d 100644 --- a/tested/languages/cpp/generators.py +++ b/tested/languages/cpp/generators.py @@ -1,7 +1,7 @@ from tested.datatypes import AllTypes, resolve_to_basic from tested.datatypes.advanced import AdvancedNumericTypes, AdvancedObjectTypes, AdvancedSequenceTypes, AdvancedStringTypes -from tested.datatypes.basic import BasicObjectTypes, BasicSequenceTypes, BasicStringTypes, BasicTypes +from tested.datatypes.basic import BasicNumericTypes, BasicObjectTypes, BasicSequenceTypes, BasicStringTypes, BasicTypes from tested.languages.c.generators import CGenerator from tested.languages.preparation import PreparedExecutionUnit, PreparedFunctionCall, PreparedTestcase, PreparedTestcaseStatement from tested.serialisation import FunctionCall, FunctionType, ObjectType, PropertyAssignment, SequenceType, Statement, Value, VariableAssignment, VariableType, WrappedAllTypes @@ -110,6 +110,8 @@ def convert_declaration(self, tp: AllTypes | VariableType, return "std::string" elif basic == BasicStringTypes.ANY: return "std::any" + elif basic == BasicNumericTypes.INTEGER: + return "std::intmax_t" return super().convert_declaration(tp) diff --git a/tested/manual.py b/tested/manual.py index 033660ab..f71f5aa0 100644 --- a/tested/manual.py +++ b/tested/manual.py @@ -24,7 +24,7 @@ def read_config() -> DodonaConfig: programming_language=SupportedLanguage("cpp"), natural_language="nl", resources=Path(exercise_dir, "evaluation"), - source=Path(exercise_dir, "solution/correct.cpp"), + source=Path(exercise_dir, "solution/wrong.cpp"), judge=Path("."), workdir=Path("workdir"), test_suite="full.tson", diff --git a/tests/exercises/remove/evaluation/full.tson b/tests/exercises/remove/evaluation/full.tson index d74cb9f0..64d29df6 100644 --- a/tests/exercises/remove/evaluation/full.tson +++ b/tests/exercises/remove/evaluation/full.tson @@ -7,6 +7,33 @@ "contexts": [ { "testcases": [ + { + "input": { + "variable": "a_list", + "type": "sequence", + "expression": { + "type": "sequence", + "data": [ + { + "type": "integer", + "data": 0 + }, + { + "type": "integer", + "data": 1 + }, + { + "type": "integer", + "data": 1 + }, + { + "type": "integer", + "data": 2 + } + ] + } + } + }, { "output": { "result": { diff --git a/tests/exercises/remove/solution/correct.cpp b/tests/exercises/remove/solution/correct.cpp new file mode 100644 index 00000000..e90a808b --- /dev/null +++ b/tests/exercises/remove/solution/correct.cpp @@ -0,0 +1,13 @@ +#include +#include + +template +std::vector remove(const std::vector& l, const S& value) { + std::vector result; + for (const T& x : l) { + if (x != value) { + result.push_back(x); + } + } + return result; +} diff --git a/tests/exercises/remove/solution/wrong.cpp b/tests/exercises/remove/solution/wrong.cpp new file mode 100644 index 00000000..c662b845 --- /dev/null +++ b/tests/exercises/remove/solution/wrong.cpp @@ -0,0 +1,12 @@ +#include +#include +#include + +template +std::vector remove(std::vector& l, S v) { + auto it = std::find(l.begin(), l.end(), v); + if (it != l.end()) { + l.erase(it); + } + return l; +}