Skip to content

Commit 31757e7

Browse files
committed
add default checks
1 parent 5f8cf35 commit 31757e7

File tree

10 files changed

+73
-94
lines changed

10 files changed

+73
-94
lines changed

tests/_extensions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
import subprocess
77
import re
88

9-
@t.test(1000)
9+
from _notAllowedCode import *
10+
11+
@t.test(0)
12+
def tabs_ok(test):
13+
test.description = lambda: "het bestand is in orde"
14+
test.test = lambda: (
15+
notAllowedCode(test, lib.source(test.fileName), {'tab': ' '})
16+
)
17+
18+
@t.test(1)
1019
def mypy_ok(test):
1120
def testMethod():
1221
p = subprocess.run(['mypy', '--strict', '--ignore-missing-imports', test.fileName], capture_output=True, universal_newlines=True)
@@ -19,7 +28,7 @@ def report(output):
1928
test.test = testMethod
2029
test.fail = report
2130

22-
@t.test(1001)
31+
@t.test(2)
2332
def doctest_ok(test):
2433
def testMethod():
2534
with open(test.fileName, 'r') as source_file:

tests/_notAllowedCode.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import checkpy.tests as t
2+
import checkpy.lib as lib
3+
import checkpy.assertlib as assertlib
4+
5+
def notAllowedCode(test, source, notAllowed):
6+
source_no_comments = lib.removeComments(source)
7+
8+
abc = []
9+
10+
for element in notAllowed:
11+
if notAllowed[element] in source_no_comments:
12+
abc.append(element)
13+
14+
15+
if len(abc) > 0:
16+
warning = "let op dat je geen " + ", ".join(abc) + " gebruikt"
17+
test.fail = lambda info : warning
18+
test.success = lambda info : warning
19+
return False
20+
21+
return True

tests/cafeineTest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
from _extensions import *
66

7-
language = "en"
8-
97
def expectedOutput(target, args):
108
return f"print 'Je krijgt {target} cafeine binnen.' bij {str(args)} als invoer"
119

12-
@t.test(1)
10+
@t.test(10)
1311
def calculatesZeroCaffeine(test):
1412
args = [0, 0, 0, 0]
1513
target = "0 mg"
@@ -21,7 +19,7 @@ def testMethod():
2119
test.test = testMethod
2220
test.description = lambda : expectedOutput(target, args)
2321

24-
@t.test(2)
22+
@t.test(20)
2523
def calculatesCoffee(test):
2624
args = [1, 0, 0, 0]
2725
target = "90 mg"
@@ -33,7 +31,7 @@ def testMethod():
3331
test.test = testMethod
3432
test.description = lambda : expectedOutput(target, args)
3533

36-
@t.test(2)
34+
@t.test(20)
3735
def calculatesTea(test):
3836
args = [0, 1, 0, 0]
3937
target = "45 mg"
@@ -45,7 +43,7 @@ def testMethod():
4543
test.test = testMethod
4644
test.description = lambda : expectedOutput(target, args)
4745

48-
@t.test(2)
46+
@t.test(20)
4947
def calculatesEnergy(test):
5048
args = [0, 0, 1, 0]
5149
target = "80 mg"
@@ -57,7 +55,7 @@ def testMethod():
5755
test.test = testMethod
5856
test.description = lambda : expectedOutput(target, args)
5957

60-
@t.test(2)
58+
@t.test(20)
6159
def calculatesCola(test):
6260
args = [0, 0, 0, 1]
6361
target = "40 mg"
@@ -69,7 +67,7 @@ def testMethod():
6967
test.test = testMethod
7068
test.description = lambda : expectedOutput(target, args)
7169

72-
@t.test(3)
70+
@t.test(30)
7371
def calculatesSomeCafeine(test):
7472
args = [1, 2, 3, 4]
7573
target = "580 mg"

tests/calculatorTest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from _extensions import *
66

7-
@t.test(0)
7+
@t.test(10)
88
def checks_answer0(test):
99
def testMethod():
1010
output = lib.outputOf(test.fileName, stdinArgs=["3 + 5"],
@@ -14,7 +14,7 @@ def testMethod():
1414
test.test = testMethod
1515
test.description = lambda : "3 + 5 = 8.0"
1616

17-
@t.test(1)
17+
@t.test(20)
1818
def checks_answer1(test):
1919
def testMethod():
2020
output = lib.outputOf(test.fileName, stdinArgs=["19 - 6"],
@@ -24,7 +24,7 @@ def testMethod():
2424
test.test = testMethod
2525
test.description = lambda : "19 - 6 = 13.0"
2626

27-
@t.test(2)
27+
@t.test(30)
2828
def checks_answer2(test):
2929
def testMethod():
3030
output = lib.outputOf(test.fileName, stdinArgs=["6 - 19"],
@@ -35,7 +35,7 @@ def testMethod():
3535
test.description = lambda : "6 - 19 = -13.0"
3636

3737

38-
@t.test(3)
38+
@t.test(40)
3939
def checks_answer3(test):
4040
def testMethod():
4141
output = lib.outputOf(test.fileName, stdinArgs=["12 * 23"],
@@ -45,7 +45,7 @@ def testMethod():
4545
test.test = testMethod
4646
test.description = lambda : "12 * 23 = 276.0"
4747

48-
@t.test(4)
48+
@t.test(50)
4949
def checks_answer4(test):
5050
def testMethod():
5151
output = lib.outputOf(test.fileName, stdinArgs=["6 / 4"],
@@ -56,7 +56,7 @@ def testMethod():
5656
test.description = lambda : "6 / 4 = 1.5"
5757

5858

59-
@t.test(5)
59+
@t.test(60)
6060
def checks_answer5(test):
6161
def testMethod():
6262
output = lib.outputOf(test.fileName, stdinArgs=["-8 * 12"],

tests/etenstijdTest.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,10 @@
44

55
from _extensions import *
66

7-
language = "en"
8-
97
def expectedOutput(target, args):
10-
if language == "nl":
11-
return f"Bepaalt correct de tijd voor {target[0]}."
12-
else:
13-
return f"Correctly determines the time for {target[1]}."
14-
15-
@t.test(0)
16-
def validFile(test):
17-
def testMethod():
18-
output = lib.outputOf(test.fileName, stdinArgs=["7:01"],
19-
overwriteAttributes = [("__name__", "__main__")])
20-
if "ontbijt" in output:
21-
global language
22-
language = "nl"
23-
elif not "breakfast" in output:
24-
return False, "Output not recognized; please double check examples on the assignment page."
25-
return asserts.fileExists(test.fileName)
26-
27-
test.test = testMethod
28-
test.description = lambda : (
29-
"Het bestand is in orde."
30-
if language == "nl" else
31-
"The file is valid."
32-
)
8+
return f"bepaalt correct de tijd voor {target[0]}"
339

34-
@t.test(1)
10+
@t.test(10)
3511
def checks_breakfast(test):
3612
correct_meal_descriptions = ["ontbijt", "breakfast"]
3713
def testMethod():
@@ -53,7 +29,7 @@ def testMethod():
5329
test.description = lambda : expectedOutput(correct_meal_descriptions, None)
5430

5531

56-
@t.test(2)
32+
@t.test(20)
5733
def checks_lunch(test):
5834
correct_meal_descriptions = ["lunch", "lunch"]
5935
def testMethod():
@@ -75,7 +51,7 @@ def testMethod():
7551
test.description = lambda : expectedOutput(correct_meal_descriptions, None)
7652

7753

78-
@t.test(3)
54+
@t.test(30)
7955
def checks_dinner(test):
8056
correct_meal_descriptions = ["avondeten", "dinner"]
8157
def testMethod():

tests/orakelTest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def expectedOutput(target, args):
88
return f"het antwoord '{args}' geeft de uitvoer '{target}'"
99

10-
@t.test(1)
10+
@t.test(10)
1111
def checks_answer0(test):
1212
args = "42"
1313
target = "Ja"
@@ -19,7 +19,7 @@ def testMethod():
1919
test.test = testMethod
2020
test.description = lambda : expectedOutput(target, args)
2121

22-
@t.test(2)
22+
@t.test(20)
2323
def checks_answer1(test):
2424
args = "tweeenveertig"
2525
target = "Ja"
@@ -31,7 +31,7 @@ def testMethod():
3131
test.test = testMethod
3232
test.description = lambda : expectedOutput(target, args)
3333

34-
@t.test(3)
34+
@t.test(30)
3535
def checks_answer2(test):
3636
args = "tweeënveertig"
3737
target = "Ja"
@@ -57,7 +57,7 @@ def testMethod():
5757
# test.test = testMethod
5858
# test.description = lambda : expectedOutput(target, args)
5959

60-
@t.test(5)
60+
@t.test(50)
6161
def checks_answer4(test):
6262
args = "53"
6363
target = "Nee"

tests/scrabbleTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from _extensions import *
66

77

8-
@t.test(0)
8+
@t.test(10)
99
def checks_compute_score(test):
1010
def testMethod():
1111
compute_score = lib.getFunction("compute_score", test.fileName)
@@ -22,7 +22,7 @@ def testMethod():
2222
test.description = lambda: "De functie 'compute_score' werkt correct."
2323

2424

25-
@t.test(1)
25+
@t.test(20)
2626
def check_S1(test):
2727
targets = ["Speler 1 wint!", "Player 1 wins!"]
2828

@@ -38,7 +38,7 @@ def testMethod():
3838
test.description = lambda: "Player 1 with 'Pizza' wins from Player 2 with 'Kaas'."
3939

4040

41-
@t.test(2)
41+
@t.test(30)
4242
def check_S2(test):
4343
targets = ["Speler 2 wint!", "Player 2 wins!"]
4444

@@ -56,7 +56,7 @@ def testMethod():
5656
)
5757

5858

59-
@t.test(3)
59+
@t.test(40)
6060
def check_gelijkspel(test):
6161
targets = ["Gelijkspel!", "It's a tie!"]
6262

@@ -74,7 +74,7 @@ def testMethod():
7474
)
7575

7676

77-
@t.test(4)
77+
@t.test(50)
7878
def check_gelijkspel(test):
7979
targets = ["Gelijkspel!", "It's a tie!"]
8080

tests/temperatuurTest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from _extensions import *
66

7-
@t.test(0)
7+
@t.test(10)
88
def checks_convert_temperature(test):
99
def testMethod():
1010
convert_temperature = lib.getFunction("convert_temperature", test.fileName)
@@ -31,7 +31,7 @@ def testMethod():
3131
# test.description = lambda : "All of 'C', 'F', 'c' and 'f' are accepted by the program."
3232

3333

34-
@t.test(2)
34+
@t.test(20)
3535
def check_overall1(test):
3636
def testMethod():
3737
output = lib.outputOf(test.fileName, stdinArgs=["F", 0, 9, 3],
@@ -42,7 +42,7 @@ def testMethod():
4242
test.description = lambda : "The correct table is printed when converting F to C with 0 as begin temperature, 9 as end temperature and 3 as step size."
4343

4444

45-
@t.test(3)
45+
@t.test(30)
4646
def check_overall2(test):
4747
def testMethod():
4848
output = lib.outputOf(test.fileName, stdinArgs=["C", 0, 20, 5],
@@ -52,7 +52,7 @@ def testMethod():
5252
test.test = testMethod
5353
test.description = lambda : "The correct table is printed when converting C to F with 0 as begin temperature, 20 as end temperature and 5 as step size."
5454

55-
@t.test(4)
55+
@t.test(40)
5656
def check_overall3(test):
5757
def testMethod():
5858
output = lib.outputOf(test.fileName, stdinArgs=["f", 0, 9, 3],
@@ -61,4 +61,3 @@ def testMethod():
6161

6262
test.test = testMethod
6363
test.description = lambda : "The correct table is printed when converting f (lowercase) to C with 0 as begin temperature, 9 as end temperature and 3 as step size."
64-

0 commit comments

Comments
 (0)