Skip to content

Commit

Permalink
Solve remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Aug 2, 2024
1 parent c97aacd commit 2af1bbc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tested/languages/cpp/generators.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tested/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions tests/exercises/remove/evaluation/full.tson
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions tests/exercises/remove/solution/correct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <vector>

template<typename T, typename S>
std::vector<T> remove(const std::vector<T>& l, const S& value) {
std::vector<T> result;
for (const T& x : l) {
if (x != value) {
result.push_back(x);
}
}
return result;
}
12 changes: 12 additions & 0 deletions tests/exercises/remove/solution/wrong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <vector>
#include <algorithm>

template<typename T, typename S>
std::vector<T> remove(std::vector<T>& l, S v) {
auto it = std::find(l.begin(), l.end(), v);
if (it != l.end()) {
l.erase(it);
}
return l;
}

0 comments on commit 2af1bbc

Please sign in to comment.