Skip to content

Commit 684a328

Browse files
Qvdpoststgm
authored andcommitted
indexer basic checks
divided casing checks in all-upper and all-lower extra verbose testing create_index
1 parent 93adffc commit 684a328

File tree

2 files changed

+62
-49
lines changed

2 files changed

+62
-49
lines changed

tests/indexerTest.py

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,68 @@
44

55
from _extensions import *
66

7-
## CHECKS FROM CHECK50
8-
9-
# @check50.check(exists)
10-
# def test_dinner():
11-
# """correctly identifies \"dinner\" in birdman.txt"""
12-
# check50.run("python3 indexer.py texts/birdman.txt").stdin("dinner").stdout("The word \"dinner\" can be found on lines: 549, 1542.\n", "The word \"dinner\" can be found on lines: 549, 1542.\n", timeout=5)
13-
#
14-
# @check50.check(test_dinner)
15-
# def test_crash():
16-
# """handles nonexistent words gracefully (i.e. does not crash)"""
17-
# check50.run("python3 indexer.py texts/birdman.txt").stdin("women").stdout("Enter search term: ", "Enter search term:", timeout=5)
18-
19-
## EXAMPLE CHECKS FROM LEESBAARHEID
7+
def sandbox():
8+
lib.require("stopwords.txt", "https://raw.githubusercontent.com/minprog/pyprog/2022/opdrachten/week5/indexer/dist/indexer/stopwords.txt")
9+
lib.require("test.txt", "https://raw.githubusercontent.com/minprog/pyprog/2022/opdrachten/week5/indexer/dist/indexer/texts/birdman.txt")
2010

2111
@t.test(1)
22-
def checks_coleman_liau(test):
12+
def checks_type(test):
2313
def testMethod():
24-
coleman_liau = lib.getFunction("coleman_liau", test.fileName)
25-
if coleman_liau(537, 4.2) == 14.532399999999996:
26-
return True
27-
else:
28-
return False
14+
fn = lib.getFunction("create_index", test.fileName)
15+
index = fn("stopwords.txt", [])
16+
if len(index) != 138:
17+
return False, "the index does not have the correct amount of words"
2918

30-
test.test = testMethod
31-
test.description = lambda : "'coleman_liau' works correctly."
19+
for key, value in index.items():
3220

33-
@t.test(2)
34-
def checks_calculate_grade(test):
35-
def testMethod():
36-
calculate_grade = lib.getFunction("calculate_grade", test.fileName)
37-
if calculate_grade(119, 5, 639) == 15:
38-
return True
39-
else:
40-
return False
21+
if not isinstance(key, str):
22+
return False, "the keys in the index are not strings"
23+
24+
if not isinstance(value, list):
25+
return False, "the values in the index are not lists"
26+
27+
try:
28+
if not isinstance(value[0], int):
29+
return False, "the values in the index are not lists that contain integers"
30+
except:
31+
return (
32+
False,
33+
"some of the values in the index have emtpy lists",
34+
)
35+
36+
return True
4137

4238
test.test = testMethod
43-
test.description = lambda : "'calculate_grade' works correctly."
39+
test.description = lambda: "'create_index' returns a well-formed index with correctly loaded data"
4440

45-
@t.test(3)
41+
42+
@t.test(2)
4643
def checks_tekst1(test):
4744
def testMethod():
48-
output = lib.outputOf(test.fileName, stdinArgs=["In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since."],
49-
overwriteAttributes = [("__name__", "__main__")])
50-
return asserts.exact(output.strip(), "Grade 7")
45+
output = lib.outputOf(
46+
test.fileName,
47+
argv=["indexer.py", "test.txt"],
48+
stdinArgs=["dinner", ""],
49+
overwriteAttributes=[("__name__", "__main__")],
50+
)
51+
return re.search(r".*dinner.*\ 549, 1542", output)
5152

5253
test.test = testMethod
53-
test.description = lambda : "Determines the correct Grade 7 for a short sentence."
54+
test.description = (
55+
lambda: "finds the word 'dinner' on lines 51 and 306 in a modified text file"
56+
)
5457

5558

56-
@t.test(4)
57-
def checks_tekst2(test):
59+
@t.test(3)
60+
def checks_crash(test):
5861
def testMethod():
59-
output = lib.outputOf(test.fileName, stdinArgs=["It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him."],
60-
overwriteAttributes = [("__name__", "__main__")])
61-
return asserts.exact(output.strip(), "Grade 10")
62+
output = lib.outputOf(
63+
test.fileName,
64+
argv=["indexer.py", "test.txt"],
65+
stdinArgs=["women", "dinner", ""],
66+
overwriteAttributes=[("__name__", "__main__")],
67+
)
68+
return re.search(r".*dinner.*\ 549, 1542", output)
6269

6370
test.test = testMethod
64-
test.description = lambda : "Determines the correct Grade 10 for a long sentence."
71+
test.description = lambda: "allows for another search if a word is not found"

tests/rnaTest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,38 @@
44

55
from _extensions import *
66

7+
78
@t.test(0)
89
def checks_input(test):
910
def testMethod():
1011
input_dna = lib.getFunction("check_input", test.fileName)
11-
if (input_dna("ATGC") and input_dna("agtc") and input_dna("AaGgCcTt")
12-
and not input_dna("AUGA") and not input_dna("123")):
12+
if (
13+
input_dna("ATGC")
14+
and input_dna("agtc")
15+
and not input_dna("AUGA")
16+
and not input_dna("123")
17+
):
1318
return True
1419
else:
1520
return False
1621

1722
test.test = testMethod
18-
test.description = lambda : "'check_input' works correctly."
23+
test.description = lambda: "'check_input' works correctly."
1924

2025

2126
@t.test(1)
2227
def checks_convert_dna(test):
2328
def testMethod():
2429
convert = lib.getFunction("transcribe_dna_to_rna", test.fileName)
25-
if (convert(["A", "T", "G", "C"]) == ["U", "A", "C", "G"]
26-
and convert(["a", "A", "t", "g", "c"]) == ["U", "U", "A", "C", "G"]):
30+
if convert(["A", "T", "G", "C"]) == ["U", "A", "C", "G"] and convert(
31+
["a", "a", "t", "g", "c"]
32+
) == ["U", "U", "A", "C", "G"]:
2733
return True
2834
else:
2935
return False
3036

3137
test.test = testMethod
32-
test.description = lambda : "'transcribe_dna_to_rna' works correctly."
38+
test.description = lambda: "'transcribe_dna_to_rna' works correctly."
3339

3440

3541
@t.test(2)
@@ -42,7 +48,7 @@ def testMethod():
4248
return False
4349

4450
test.test = testMethod
45-
test.description = lambda : "'convert_to_list' works correctly."
51+
test.description = lambda: "'convert_to_list' works correctly."
4652

4753

4854
@t.test(3)
@@ -55,4 +61,4 @@ def testMethod():
5561
return False
5662

5763
test.test = testMethod
58-
test.description = lambda : "'convert_to_string' works correctly."
64+
test.description = lambda: "'convert_to_string' works correctly."

0 commit comments

Comments
 (0)