Skip to content

Commit 834a959

Browse files
committed
week 1 upgrades
1 parent e15b9df commit 834a959

File tree

4 files changed

+86
-88
lines changed

4 files changed

+86
-88
lines changed

tests/cafeineTest.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,74 @@
44

55
from _extensions import *
66

7-
def expectedOutput(target, args):
8-
return f"print 'Je krijgt {target} cafeine binnen.' bij {str(args)} als invoer"
9-
7+
@t.passed(doctest_ok)
108
@t.test(10)
119
def calculatesZeroCaffeine(test):
10+
"""print 'Je krijgt 0 mg cafeine binnen.' bij [0, 0, 0, 0] als invoer"""
1211
args = [0, 0, 0, 0]
1312
target = "0 mg"
1413
def testMethod():
1514
output = lib.outputOf(test.fileName, stdinArgs=args,
1615
overwriteAttributes = [("__name__", "__main__")])
1716
return asserts.contains(output.strip(), target)
18-
1917
test.test = testMethod
20-
test.description = lambda : expectedOutput(target, args)
2118

19+
@t.passed(doctest_ok)
2220
@t.test(20)
2321
def calculatesCoffee(test):
22+
"""print 'Je krijgt 90 mg cafeine binnen.' bij [1, 0, 0, 0] als invoer"""
2423
args = [1, 0, 0, 0]
2524
target = "90 mg"
2625
def testMethod():
2726
output = lib.outputOf(test.fileName, stdinArgs=args,
2827
overwriteAttributes = [("__name__", "__main__")])
2928
return asserts.contains(output.strip(), target)
30-
3129
test.test = testMethod
32-
test.description = lambda : expectedOutput(target, args)
3330

31+
@t.passed(doctest_ok)
3432
@t.test(20)
3533
def calculatesTea(test):
34+
"""print 'Je krijgt 45 mg cafeine binnen.' bij [0, 1, 0, 0] als invoer"""
3635
args = [0, 1, 0, 0]
3736
target = "45 mg"
3837
def testMethod():
3938
output = lib.outputOf(test.fileName, stdinArgs=args,
4039
overwriteAttributes = [("__name__", "__main__")])
4140
return asserts.contains(output.strip(), target)
42-
4341
test.test = testMethod
44-
test.description = lambda : expectedOutput(target, args)
4542

43+
@t.passed(doctest_ok)
4644
@t.test(20)
4745
def calculatesEnergy(test):
46+
"""print 'Je krijgt 80 mg cafeine binnen.' bij [0, 0, 1, 0] als invoer"""
4847
args = [0, 0, 1, 0]
4948
target = "80 mg"
5049
def testMethod():
5150
output = lib.outputOf(test.fileName, stdinArgs=args,
5251
overwriteAttributes = [("__name__", "__main__")])
5352
return asserts.contains(output.strip(), target)
54-
5553
test.test = testMethod
56-
test.description = lambda : expectedOutput(target, args)
5754

55+
@t.passed(doctest_ok)
5856
@t.test(20)
5957
def calculatesCola(test):
58+
"""print 'Je krijgt 40 mg cafeine binnen.' bij [0, 0, 0, 1] als invoer"""
6059
args = [0, 0, 0, 1]
6160
target = "40 mg"
6261
def testMethod():
6362
output = lib.outputOf(test.fileName, stdinArgs=args,
6463
overwriteAttributes = [("__name__", "__main__")])
6564
return asserts.contains(output.strip(), target)
66-
6765
test.test = testMethod
68-
test.description = lambda : expectedOutput(target, args)
6966

67+
@t.passed(doctest_ok)
7068
@t.test(30)
7169
def calculatesSomeCafeine(test):
70+
"""print 'Je krijgt 580 mg cafeine binnen.' bij [1, 2, 3, 4] als invoer"""
7271
args = [1, 2, 3, 4]
7372
target = "580 mg"
7473
def testMethod():
7574
output = lib.outputOf(test.fileName, stdinArgs=args,
7675
overwriteAttributes = [("__name__", "__main__")])
7776
return asserts.contains(output.strip(), target)
78-
7977
test.test = testMethod
80-
test.description = lambda : expectedOutput(target, args)

tests/etenstijdTest.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,42 @@
44

55
from _extensions import *
66

7-
def expectedOutput(target, args):
8-
return f"bepaalt correct de tijd voor {target[0]}"
7+
@t.passed(doctest_ok)
8+
@t.test(8)
9+
def correct_meal_if_meal(test):
10+
"""de functie 'meal' geeft de juiste maaltijd voor elke tijd"""
11+
def testMethod():
12+
f = lib.getFunction("meal", test.fileName)
13+
return (
14+
f('7:30') == 'ontbijt' and
15+
f('7:31') == 'ontbijt' and
16+
f('07:31') == 'ontbijt' and
17+
f('18:30') == 'avondeten' and
18+
f('13:00') == 'lunch' and
19+
f('12:00') == 'lunch'
20+
)
21+
test.test = testMethod
22+
23+
@t.passed(doctest_ok)
24+
@t.test(9)
25+
def correct_none_if_no_meal(test):
26+
"""de functie 'meal' geeft None als er geen maaltijd van toepassing is"""
27+
def testMethod():
28+
f = lib.getFunction("meal", test.fileName)
29+
return (
30+
f('6:30') is None and
31+
f('8:01') is None and
32+
f('08:31') is None and
33+
f('14:01') is None and
34+
f('13:01') is None and
35+
f('17:59') is None
36+
)
37+
test.test = testMethod
938

39+
@t.passed(doctest_ok)
1040
@t.test(10)
1141
def checks_breakfast(test):
42+
"""bepaalt correct de tijd voor ontbijt"""
1243
correct_meal_descriptions = ["ontbijt", "breakfast"]
1344
def testMethod():
1445
output = lib.outputOf(test.fileName, stdinArgs=["7:25"], overwriteAttributes = [("__name__", "__main__")])
@@ -24,14 +55,13 @@ def testMethod():
2455
return False
2556

2657
return True
27-
2858
test.test = testMethod
29-
test.description = lambda : expectedOutput(correct_meal_descriptions, None)
30-
3159

60+
@t.passed(doctest_ok)
3261
@t.test(20)
3362
def checks_lunch(test):
34-
correct_meal_descriptions = ["lunch", "lunch"]
63+
"""bepaalt correct de tijd voor lunch"""
64+
correct_meal_descriptions = ["lunch"]
3565
def testMethod():
3666
output = lib.outputOf(test.fileName, stdinArgs=["13:00"], overwriteAttributes = [("__name__", "__main__")])
3767
if not any([asserts.contains(output, meal) for meal in correct_meal_descriptions]):
@@ -46,13 +76,12 @@ def testMethod():
4676
return False
4777

4878
return True
49-
5079
test.test = testMethod
51-
test.description = lambda : expectedOutput(correct_meal_descriptions, None)
52-
5380

81+
@t.passed(doctest_ok)
5482
@t.test(30)
5583
def checks_dinner(test):
84+
"""bepaalt correct de tijd voor avondeten"""
5685
correct_meal_descriptions = ["avondeten", "dinner"]
5786
def testMethod():
5887
output = lib.outputOf(test.fileName, stdinArgs=["18:53"], overwriteAttributes = [("__name__", "__main__")])
@@ -72,6 +101,4 @@ def testMethod():
72101
return False
73102

74103
return True
75-
76104
test.test = testMethod
77-
test.description = lambda : expectedOutput(correct_meal_descriptions, None)

tests/orakelTest.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,50 @@
44

55
from _extensions import *
66

7-
def expectedOutput(target, args):
8-
return f"het antwoord '{args}' geeft de uitvoer '{target}'"
9-
7+
@t.passed(doctest_ok)
108
@t.test(10)
119
def checks_answer0(test):
10+
"""het antwoord '42' geeft de uitvoer 'Ja'"""
1211
args = "42"
1312
target = "Ja"
1413
def testMethod():
1514
output = lib.outputOf(test.fileName, stdinArgs=[args],
1615
overwriteAttributes = [("__name__", "__main__")])
1716
return asserts.exact(output.strip().split('\n')[-1], target)
18-
1917
test.test = testMethod
20-
test.description = lambda : expectedOutput(target, args)
2118

19+
@t.passed(doctest_ok)
2220
@t.test(20)
2321
def checks_answer1(test):
22+
"""het antwoord 'tweeenveertig' geeft de uitvoer 'Ja'"""
2423
args = "tweeenveertig"
2524
target = "Ja"
2625
def testMethod():
2726
output = lib.outputOf(test.fileName, stdinArgs=[args],
2827
overwriteAttributes = [("__name__", "__main__")])
2928
return asserts.exact(output.strip().split('\n')[-1], target)
30-
3129
test.test = testMethod
32-
test.description = lambda : expectedOutput(target, args)
3330

31+
@t.passed(doctest_ok)
3432
@t.test(30)
3533
def checks_answer2(test):
34+
"""het antwoord 'tweeënveertig' geeft de uitvoer 'Ja'"""
3635
args = "tweeënveertig"
3736
target = "Ja"
3837
def testMethod():
3938
output = lib.outputOf(test.fileName, stdinArgs=[args],
4039
overwriteAttributes = [("__name__", "__main__")])
4140
return asserts.exact(output.strip().split('\n')[-1], target)
42-
4341
test.test = testMethod
44-
test.description = lambda : expectedOutput(target, args)
45-
46-
# uitgecomment want dit staat niet in de opdracht, plus de string-methods
47-
# zijn nog niet behandeld in week 1
48-
# @t.test(4)
49-
# def checks_answer3(test):
50-
# args = "TWEEENVEERTIG"
51-
# target = "Ja"
52-
# def testMethod():
53-
# output = lib.outputOf(test.fileName, stdinArgs=[args],
54-
# overwriteAttributes = [("__name__", "__main__")])
55-
# return asserts.exact(output.strip().split('\n')[-1], target)
56-
#
57-
# test.test = testMethod
58-
# test.description = lambda : expectedOutput(target, args)
5942

60-
@t.test(50)
61-
def checks_answer4(test):
43+
@t.passed(doctest_ok)
44+
@t.test(40)
45+
def checks_answer3(test):
46+
"""het antwoord '53' geeft de uitvoer 'Nee'"""
6247
args = "53"
6348
target = "Nee"
6449
def testMethod():
6550
output = lib.outputOf(test.fileName, stdinArgs=[args],
6651
overwriteAttributes = [("__name__", "__main__")])
6752
return asserts.exact(output.strip().split('\n')[-1], target)
68-
6953
test.test = testMethod
70-
test.description = lambda : expectedOutput(target, args)

tests/vakantieTest.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,73 @@
44

55
from _extensions import *
66

7-
def expectedOutput(target, args):
8-
return f"print correct 'Jouw vakantie kost: {target}' bij {str(args)} als invoer"
9-
7+
@t.passed(doctest_ok)
108
@t.test(10)
9+
def calculatesTravelCostsWithHint(test):
10+
"""de functie 'travel_costs' berekent correct de vervoerkosten"""
11+
def testMethod():
12+
travelCosts = lib.getFunction("travel_costs", test.fileName, stdinArgs=[1000, 0])(1000)
13+
if travelCosts == 130:
14+
return (False,
15+
"vergeet niet om de kosten voor zowel heen als terug te berekenen"
16+
)
17+
elif travelCosts == 260:
18+
return True
19+
else:
20+
return False
21+
test.test = testMethod
22+
23+
@t.passed(doctest_ok)
24+
@t.test(20)
1125
def calculatesZeroCosts(test):
26+
"""print correct 'Jouw vakantie kost: 0' bij [0, 0] als invoer"""
1227
target = "0"
1328
args = [0, 0]
1429
def testMethod():
1530
output = lib.outputOf(test.fileName, stdinArgs=args, overwriteAttributes = [("__name__", "__main__")])
1631
return asserts.contains(output.strip(), target)
17-
1832
test.test = testMethod
19-
test.description = lambda: expectedOutput(target, args)
20-
21-
@t.test(20)
22-
def calculatesTravelCostsWithHint(test):
23-
def testMethod():
24-
travelCosts = lib.getFunction("travel_costs", test.fileName, stdinArgs=[1000, 0])(1000)
25-
if travelCosts == 130:
26-
return (False,
27-
"vergeet niet om de kosten voor zowel heen als terug te berekenen"
28-
# if language == "nl" else
29-
# "Don't forget to calculate costs for a round trip."
30-
)
31-
elif travelCosts == 260:
32-
return True
33-
else:
34-
return False
35-
36-
test.test = testMethod
37-
test.description = lambda : (
38-
"de functie 'travel_costs' berekent correct de vervoerkosten"
39-
# if language == "nl" else
40-
# "The function 'travel_costs' calculates the costs of travel correctly."
41-
)
4233

34+
@t.passed(doctest_ok)
4335
@t.test(20)
4436
def calculatesTravelCosts(test):
37+
"""print correct 'Jouw vakantie kost: 260' bij [1000, 0] als invoer"""
4538
target = "260"
4639
args = [1000, 0]
4740
def testMethod():
4841
output = lib.outputOf(test.fileName, stdinArgs=args, overwriteAttributes = [("__name__", "__main__")])
4942
return asserts.contains(output.strip(), target)
50-
5143
test.test = testMethod
52-
test.description = lambda: expectedOutput(target, args)
5344

45+
@t.passed(doctest_ok)
5446
@t.test(30)
5547
def calculatesSleepingCosts(test):
48+
"""print correct 'Jouw vakantie kost: 600' bij [0, 10] als invoer"""
5649
target = "600"
5750
args = [0, 10]
5851
def testMethod():
5952
output = lib.outputOf(test.fileName, stdinArgs=args, overwriteAttributes = [("__name__", "__main__")])
6053
return asserts.contains(output.strip(), target)
61-
6254
test.test = testMethod
63-
test.description = lambda: expectedOutput(target, args)
6455

56+
@t.passed(doctest_ok)
6557
@t.test(40)
6658
def calculatesCosts(test):
59+
"""print correct 'Jouw vakantie kost: 589' bij [650, 7] als invoer"""
6760
target = "589"
6861
args = [650, 7]
6962
def testMethod():
7063
output = lib.outputOf(test.fileName, stdinArgs=args, overwriteAttributes = [("__name__", "__main__")])
7164
return asserts.contains(output.strip(), target)
72-
7365
test.test = testMethod
74-
test.description = lambda: expectedOutput(target, args)
7566

67+
@t.passed(doctest_ok)
7668
@t.test(50)
7769
def calculatesCostsAndRoundsCorrectly(test):
70+
"""print correct 'Jouw vakantie kost: 371' bij [1425, 0] als invoer"""
7871
target = "371"
7972
args = [1425, 0]
8073
def testMethod():
8174
output = lib.outputOf(test.fileName, stdinArgs=args, overwriteAttributes = [("__name__", "__main__")])
8275
return asserts.contains(output.strip(), target)
83-
8476
test.test = testMethod
85-
test.description = lambda: expectedOutput(target, args)

0 commit comments

Comments
 (0)