|
7 | 7 | language = "en" |
8 | 8 |
|
9 | 9 | def expectedOutput(target, args): |
10 | | - # if language == "nl": |
11 | | - return f"print 'Je krijgt {target} cafeine binnen.' bij {str(args)} als invoer" |
12 | | - # else: |
13 | | - # return f"Prints 'Your intake is {target} of caffeine.' for {str(args)} as input" |
| 10 | + return f"print 'Je krijgt {target} cafeine binnen.' bij {str(args)} als invoer" |
14 | 11 |
|
15 | | -def caffeineTest(test, values, target): |
| 12 | +@t.test(1) |
| 13 | +def calculatesZeroCaffeine(test): |
| 14 | + args = [0, 0, 0, 0] |
| 15 | + target = "0 mg" |
16 | 16 | def testMethod(): |
17 | | - output = test.runProgram(values) |
| 17 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 18 | + overwriteAttributes = [("__name__", "__main__")]) |
18 | 19 | return asserts.contains(output.strip(), target) |
19 | | - test.test = testMethod |
20 | | - test.description = lambda: expectedOutput(target, values) |
21 | | - |
22 | | -# @t.test(0) |
23 | | -# def assign_language(test): |
24 | | -# source_no_comments = lib.removeComments(lib.source(test.fileName)) |
25 | | -# global language |
26 | | -# if "binnen" in source_no_comments: |
27 | | -# language = "nl" |
28 | | -# test.description = lambda: f"{test.fileName} bestaat en het programma lijkt Nederlandstalig" |
29 | | -# else: |
30 | | -# language = "en" |
31 | | -# test.description = lambda: f"{test.fileName} exists and the program seems to be in English" |
32 | | -# test.test = lambda: True |
33 | 20 |
|
34 | | -@t.test(1) |
35 | | -def calculatesZeroCaffeine(test): |
36 | | - caffeineTest(test, [0, 0, 0, 0], "0 mg") |
| 21 | + test.test = testMethod |
| 22 | + test.description = lambda : expectedOutput(target, args) |
37 | 23 |
|
38 | 24 | @t.test(2) |
39 | 25 | def calculatesCoffee(test): |
40 | | - caffeineTest(test, [1, 0, 0, 0], "90 mg") |
| 26 | + args = [1, 0, 0, 0] |
| 27 | + target = "90 mg" |
| 28 | + def testMethod(): |
| 29 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 30 | + overwriteAttributes = [("__name__", "__main__")]) |
| 31 | + return asserts.contains(output.strip(), target) |
| 32 | + |
| 33 | + test.test = testMethod |
| 34 | + test.description = lambda : expectedOutput(target, args) |
41 | 35 |
|
42 | 36 | @t.test(2) |
43 | 37 | def calculatesTea(test): |
44 | | - caffeineTest(test, [0, 1, 0, 0], "45 mg") |
| 38 | + args = [0, 1, 0, 0] |
| 39 | + target = "45 mg" |
| 40 | + def testMethod(): |
| 41 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 42 | + overwriteAttributes = [("__name__", "__main__")]) |
| 43 | + return asserts.contains(output.strip(), target) |
| 44 | + |
| 45 | + test.test = testMethod |
| 46 | + test.description = lambda : expectedOutput(target, args) |
45 | 47 |
|
46 | 48 | @t.test(2) |
47 | 49 | def calculatesEnergy(test): |
48 | | - caffeineTest(test, [0, 0, 1, 0], "80 mg") |
| 50 | + args = [0, 0, 1, 0] |
| 51 | + target = "80 mg" |
| 52 | + def testMethod(): |
| 53 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 54 | + overwriteAttributes = [("__name__", "__main__")]) |
| 55 | + return asserts.contains(output.strip(), target) |
| 56 | + |
| 57 | + test.test = testMethod |
| 58 | + test.description = lambda : expectedOutput(target, args) |
49 | 59 |
|
50 | 60 | @t.test(2) |
51 | 61 | def calculatesCola(test): |
52 | | - caffeineTest(test, [0, 0, 0, 1], "40 mg") |
| 62 | + args = [0, 0, 0, 1] |
| 63 | + target = "40 mg" |
| 64 | + def testMethod(): |
| 65 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 66 | + overwriteAttributes = [("__name__", "__main__")]) |
| 67 | + return asserts.contains(output.strip(), target) |
| 68 | + |
| 69 | + test.test = testMethod |
| 70 | + test.description = lambda : expectedOutput(target, args) |
53 | 71 |
|
54 | 72 | @t.test(3) |
55 | 73 | def calculatesSomeCafeine(test): |
56 | | - caffeineTest(test, [1, 2, 3, 4], "580 mg") |
| 74 | + args = [1, 2, 3, 4] |
| 75 | + target = "580 mg" |
| 76 | + def testMethod(): |
| 77 | + output = lib.outputOf(test.fileName, stdinArgs=args, |
| 78 | + overwriteAttributes = [("__name__", "__main__")]) |
| 79 | + return asserts.contains(output.strip(), target) |
| 80 | + |
| 81 | + test.test = testMethod |
| 82 | + test.description = lambda : expectedOutput(target, args) |
0 commit comments