Skip to content

Commit

Permalink
Improve testing for specific checks
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Jun 13, 2024
1 parent 83ef6cf commit 71ef942
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 128 deletions.
4 changes: 4 additions & 0 deletions tests/exercises/division/evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public static EvaluationResult Evaluate(object? actual) {
return new EvaluationResult(false, "System.DivideByZeroException", actual == null ? "" : actual.ToString(), messages);
}
}

public static EvaluationResult Runtime(object? actual) {
throw new ArgumentOutOfRangeException("hello");
}
}
10 changes: 9 additions & 1 deletion tests/exercises/division/evaluation/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ evaluate (Just x) =
}


runtime :: Maybe (SomeException) -> EvaluationResult
runtime _ = evaluationResult {
readableExpected = Just $ show DivideByZero,
readableActual = Just $ show (100 `div` 0),
messages = [message "Expected DivideByZero, got nothing."]
}


handleA :: ArithException -> EvaluationResult
handleA DivideByZero = evaluationResult {
result = True,
Expand All @@ -30,4 +38,4 @@ handleA other = evaluationResult {
readableExpected = Just $ show DivideByZero,
readableActual = Just $ show other,
messages = [message "Expected DivideByZero, got something else."]
}
}
6 changes: 5 additions & 1 deletion tests/exercises/division/evaluation/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public static EvaluationResult evaluate(Object actual) {
}
}

}
public static EvaluationResult runtime(Object actual) {
throw new RuntimeException("Something went wrong!");
}

}
7 changes: 6 additions & 1 deletion tests/exercises/division/evaluation/Evaluator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ class Evaluator {
.build()
}
}

@JvmStatic
fun runtime(actual: Any?): EvaluationResult {
throw Exception("Hi There!")
}
}
}
}
9 changes: 9 additions & 0 deletions tests/exercises/division/evaluation/EvaluatorSyntaxError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using Tested;
a
public class Evaluator { zeffa ff v
public static E vxwvsages = new List<Message>() { new Message("Expected DivideByZeroException, got something else.") };
return new EvaluationResult(false, "System.DivideByZeroException", actual == null ? "" : actual.ToString(), messages);
}
}
}vv qega
37 changes: 37 additions & 0 deletions tests/exercises/division/evaluation/EvaluatorSyntaxError.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Evaluator where

import EvaluationUtils
import Control.Exception

evaluate :: Maybe (SomeException) -> EvaluationResult
evaluate Nothing = evaluationResult {
readableExpected = Just $ show DivideByZero,
readableActual = Just "",
messages = [message "Expected DivideByZero, got nothing."]
}
evaluate (Just x) =
case fromException x off aegaeglho hapyat²uùµajµjoµjµ µg jùµj ùtjùpµtjùpjµj(&µj µjµajtpµj

egkzmknzk oih
gcd





zgg[message "Expected DivideByZero, got nothing."]
}


handleA :: ArithException -> EvaluationResult
handleA DivideByZero = evaluationResult {
result = True,
readableExpected = Just $ show DivideByZero,
readableActual = Just $ show DivideByZero
}
handleA other = evaluationResult {
readableExpected = Just $ show DivideByZero,
readableActual = Just $ show other,
messages = [message "Expected DivideByZero, got something else."]
}
15 changes: 15 additions & 0 deletions tests/exercises/division/evaluation/EvaluatorSyntaxError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Evaluator { egqdg sd
public static EvaluationResult evaluate(Object actual) {
if (actual instanceof ArithmeticException) {
return EvaluationResuvd lt.builder(true)
.withReadableExpected(actual.toString())
.withReadableActual(actual.toString())
.build();
} else {
return EvaluationResusdlt.builder(false)
.withReadableExpected("ArithmeticException")
.withReadableActual(actual == null ? "" : actual.toString())
.withMessage(nbsd
}

} sbsdgssdé§u u
16 changes: 16 additions & 0 deletions tests/exercises/division/evaluation/EvaluatorSyntaxError.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Evaluator { ae
companion object {t "t"&t
@JvmStatic zfz"r'" '" '
fun evaluate(actual: Any?): EvaluationResult {
return if (actual is ArithmeticException) {
EvaluationResult.Builder(result = true,
readableExpected = actual.toString(),
aeg readableActual = actual.toString()).build()
} else {
EvalugtionResult.Builder(result = false,
readableExpected = "ArithmeticException",
readableActual = actual?.toString() ?: "")
.withMessage(EvaluationResult.Message("Expected ArithmeticException, got something else."))
.build()
qg
}qd qsdvdvqd
18 changes: 18 additions & 0 deletions tests/exercises/division/evaluation/evaluator-syntax-error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
jdhbkd mbzough import traceback

from evaluation_utils import EvaluationResult, Message


def evaluate(value):
if isinstance(value, ZeroDivisionError):
# If a zero division error, show the stacktrace.
formatted = "".join(traceback.format_exception(type(value), value, value.__traceback__))
return EvaluationResult(True, formatted, formatted)
elif isinstance(value, Exception):
# If another error, show the stacktrace as well.
formatted = "".join(traceback.format_exception(type(value), value, value.__traceback__))
return EvaluationResult(False, "ZeroDivisionError", formatted, [Message(f"Verwachtte een ZeroDivisionError, maar kreeg een {type(value).__name__}.")])
else:
# Else show the str of the value.
actual = str(value) if value else ""
return EvaluationResult(False, "ZeroDivisionError", actual, [Message("Verwachtte een ZeroDivisionError.")])
4 changes: 4 additions & 0 deletions tests/exercises/division/evaluation/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ def evaluate(value):
# Else show the str of the value.
actual = str(value) if value else ""
return EvaluationResult(False, "ZeroDivisionError", actual, [Message("Verwachtte een ZeroDivisionError.")])


def runtime(_value):
raise ValueError("Hallo")
50 changes: 50 additions & 0 deletions tests/exercises/division/evaluation/plan-runtime-exception.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"tabs": [
{
"name": "Feedback",
"runs": [
{
"run": {
"description": "Uitvoeren code",
"input": {
"main_call": true
},
"output": {
"exception": {
"evaluator": {
"type": "specific",
"evaluators": {
"python": {
"file": "evaluator.py",
"name": "runtime"
},
"java": {
"file": "Evaluator.java",
"name": "runtime"
},
"kotlin": {
"file": "Evaluator.kt",
"name": "runtime"
},
"haskell": {
"file": "Evaluator.hs",
"name": "runtime"
},
"runhaskell": {
"file": "Evaluator.hs",
"name": "runtime"
},
"csharp": {
"file": "Evaluator.cs",
"name": "runtime"
}
}
}
}
}
}
}
]
}
]
}
44 changes: 44 additions & 0 deletions tests/exercises/division/evaluation/plan-syntax-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"tabs": [
{
"name": "Feedback",
"runs": [
{
"run": {
"description": "Uitvoeren code",
"input": {
"main_call": true
},
"output": {
"exception": {
"evaluator": {
"type": "specific",
"evaluators": {
"python": {
"file": "evaluator.py"
},
"java": {
"file": "EvaluatorSyntaxError.java"
},
"kotlin": {
"file": "EvaluatorSyntaxError.kt"
},
"haskell": {
"file": "EvaluatorSyntaxError.hs"
},
"runhaskell": {
"file": "EvaluatorSyntaxError.hs"
},
"csharp": {
"file": "EvaluatorSyntaxError.cs"
}
}
}
}
}
}
}
]
}
]
}
2 changes: 2 additions & 0 deletions tests/language_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
pytest.param("runhaskell", marks=pytest.mark.haskell),
]
ALL_LANGUAGES = ALL_SPECIFIC_LANGUAGES + ["bash"]

EXCEPTION_LANGUAGES = ["python", "java", "kotlin", "csharp", "haskell"]
9 changes: 5 additions & 4 deletions tests/manual_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from io import StringIO
from pathlib import Path

import pytest
from jsonschema import validate

from tested.cli import CommandDict, split_output
Expand All @@ -28,23 +29,23 @@ def assert_valid_output(output: str, config) -> CommandDict:


def configuration(
config,
config: pytest.Config,
exercise: str,
language: str,
work_dir: Path,
suite: str = "plan.json",
solution: str = "solution",
options=None,
) -> DodonaConfig:
exercise_dir = Path(config.rootdir) / "tests" / "exercises"
exercise_dir = config.rootpath / "tests" / "exercises"
ep = exercise_dir / exercise
return exercise_configuration(
config, ep, language, work_dir, suite, solution, options
)


def exercise_configuration(
config,
config: pytest.Config,
exercise_directory: Path,
language: str,
work_dir: Path,
Expand All @@ -64,7 +65,7 @@ def exercise_configuration(
"natural_language": "nl",
"resources": exercise_directory / "evaluation",
"source": exercise_directory / "solution" / f"{solution}.{ext}",
"judge": Path(f"{config.rootdir}"),
"judge": config.rootpath,
"workdir": work_dir,
"test_suite": suite,
"options": {"linter": False},
Expand Down
Loading

0 comments on commit 71ef942

Please sign in to comment.