Skip to content

Commit 1d20701

Browse files
committed
new tests
1 parent ec20af3 commit 1d20701

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

tests/string_methodsTest.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from checkpy import *
2+
from _basics_no_listcomp import *
3+
from _static_analysis import *
4+
5+
import ast
6+
7+
@t.passed(doctest_ok)
8+
def has_functions():
9+
"""alle gevraagde functies zijn aanwezig"""
10+
assert defines_function("number_of_Os")
11+
assert defines_function("first_O")
12+
assert defines_function("number_of_letters")
13+
assert defines_function("where_letter")
14+
assert defines_function("total_occurences")
15+
assert has_string(".count"), "gebruik de opgegeven methodes in je oplossing"
16+
assert has_string(".find"), "gebruik de opgegeven methodes in je oplossing"
17+
assert not_in_code(ast.While)
18+
assert not_in_code(ast.For)
19+
20+
@t.passed(has_functions)
21+
def test_number_of_Os(test):
22+
"""functie `number_of_Os` werkt correct"""
23+
assert getFunction("number_of_Os")('ooo') == 3
24+
assert getFunction("number_of_Os")('') == 0
25+
assert getFunction("number_of_Os")('yoyoyo') == 3
26+
assert getFunction("number_of_Os")('blo') == 1
27+
28+
@t.passed(has_functions)
29+
def test_first_O(test):
30+
"""functie `first_O` werkt correct"""
31+
assert getFunction("first_O")('ooo') == 0
32+
assert getFunction("first_O")('yo') == 1
33+
34+
@t.passed(has_functions)
35+
def test_number_of_letters(test):
36+
"""functie `number_of_letters` werkt correct"""
37+
assert getFunction("number_of_letters")('a', 'a') == 1
38+
assert getFunction("number_of_letters")('aaa', 'a') == 3
39+
assert getFunction("number_of_letters")('o', 'o') == 1
40+
assert getFunction("number_of_letters")('', 'a') == 0
41+
42+
@t.passed(has_functions)
43+
def test_where_letter(test):
44+
"""functie `where_letter` werkt correct"""
45+
assert getFunction("first_O")('ooo', 'o') == 0
46+
assert getFunction("first_O")('ao', 'o') == 1
47+
assert getFunction("first_O")('aaa', 'a') == 0
48+
assert getFunction("first_O")('ya', 'a') == 1
49+
50+
@t.passed(has_functions)
51+
def test_total_occurrences(test):
52+
"""functie `total_occurrences` werkt correct"""
53+
assert getFunction("total_occurrences")('color', 'yellow', 'l') == 3
54+
assert getFunction("total_occurrences")('red', 'blue', 'l') == 1
55+
assert getFunction("total_occurrences")('green', 'purple', 'b') == 0
56+
assert getFunction("total_occurrences")('', 'glitter', 'r') == 1

tests/string_moduleTest.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from checkpy import *
2+
from _basics_no_listcomp import *
3+
from _static_analysis import *
4+
5+
import ast
6+
7+
@t.passed(doctest_ok)
8+
def has_functions():
9+
"""alle gevraagde functies zijn aanwezig"""
10+
assert defines_function("isalpha")
11+
assert defines_function("islower")
12+
assert defines_function("isupper")
13+
assert defines_function("isdigit")
14+
assert defines_function("isblank")
15+
assert not has_string("defgh"), "gebruik de variabelen uit de string-module voor deze opdracht"
16+
assert not has_string("DEFGH"), "gebruik de variabelen uit de string-module voor deze opdracht"
17+
assert not has_string("1234"), "gebruik de variabelen uit de string-module voor deze opdracht"
18+
assert has_string(".ascii_lowercase"), "gebruik de variabelen uit de string-module voor deze opdracht"
19+
assert has_string(".ascii_uppercase"), "gebruik de variabelen uit de string-module voor deze opdracht"
20+
assert has_string(".whitespace"), "gebruik de variabelen uit de string-module voor deze opdracht"
21+
22+
@t.passed(has_functions)
23+
def test_isalpha(test):
24+
"""functie `isalpha` werkt correct"""
25+
assert getFunction("isalpha")('a') == True
26+
assert getFunction("isalpha")('9') == False
27+
assert getFunction("isalpha")('e') == True
28+
assert getFunction("isalpha")('á') == False
29+
assert getFunction("isalpha")(' ') == False
30+
31+
@t.passed(has_functions)
32+
def test_islower(test):
33+
"""functie `islower` werkt correct"""
34+
assert getFunction("islower")('a') == True
35+
assert getFunction("islower")('9') == False
36+
assert getFunction("islower")('e') == True
37+
assert getFunction("islower")('A') == False
38+
assert getFunction("islower")(' ') == False
39+
40+
@t.passed(has_functions)
41+
def test_isupper(test):
42+
"""functie `isupper` werkt correct"""
43+
assert getFunction("isupper")('A') == True
44+
assert getFunction("isupper")('9') == False
45+
assert getFunction("isupper")('e') == False
46+
assert getFunction("isupper")('á') == False
47+
assert getFunction("isupper")(' ') == False
48+
49+
@t.passed(has_functions)
50+
def test_isdigit(test):
51+
"""functie `isdigit` werkt correct"""
52+
assert getFunction("isdigit")('A') == False
53+
assert getFunction("isdigit")('9') == True
54+
assert getFunction("isdigit")('e') == False
55+
assert getFunction("isdigit")('á') == False
56+
assert getFunction("isdigit")(' ') == False
57+
58+
@t.passed(has_functions)
59+
def test_isblank(test):
60+
"""functie `isblank` werkt correct"""
61+
assert getFunction("isblank")('A') == False
62+
assert getFunction("isblank")('9') == False
63+
assert getFunction("isblank")('e') == False
64+
assert getFunction("isblank")('á') == False
65+
assert getFunction("isblank")(' ') == True

0 commit comments

Comments
 (0)