File tree Expand file tree Collapse file tree 6 files changed +42
-18
lines changed Expand file tree Collapse file tree 6 files changed +42
-18
lines changed Original file line number Diff line number Diff line change 1+ from checkpy import *
12from typing import Any
23import ast
34
45from checkpy import static
56
7+ def defines_function (name : str ) -> bool :
8+ check = name in static .getFunctionDefinitions ()
9+ if not check :
10+ raise AssertionError (f"`{ name } ` is niet aanwezig" )
11+ return check
12+
13+ def not_in_code (construct : type ):
14+ check = construct in static .AbstractSyntaxTree ()
15+ name = str (construct ).split ("." )[1 ].split ("'" )[0 ].lower ()
16+ if check :
17+ raise AssertionError (f"`{ name } ` mag niet gebruikt worden in deze opdracht" )
18+ return check
19+
20+ def in_code (construct : type ):
21+ check = construct in static .AbstractSyntaxTree ()
22+ name = str (construct ).split ("." )[1 ].split ("'" )[0 ].lower ()
23+ if not check :
24+ raise AssertionError (f"`{ name } ` moet gebruikt worden in deze opdracht" )
25+ return check
26+
627def has_syntax_error ():
728 try :
829 compile (static .getSource (), "<your program>" , "exec" )
Original file line number Diff line number Diff line change 11from checkpy import *
22from _basics_no_listcomp import *
3+ from _static_analysis import *
34
45@t .passed (doctest_ok )
56def has_functions ():
67 """functie `is_acidic` is aanwezig"""
7- assert "is_acidic" in static . getFunctionDefinitions (), "` is_acidic` is niet aanwezig"
8+ assert defines_function ( " is_acidic" )
89
910@t .passed (has_functions )
1011def test_weeks_elapsed (test ):
Original file line number Diff line number Diff line change 33import checkpy .assertlib as asserts
44
55from _basics_no_listcomp import *
6+ from _static_analysis import *
67
78@t .passed (doctest_ok )
89def has_functions ():
910 """alle gevraagde functies zijn aanwezig"""
10- assert "check_coin" in static . getFunctionDefinitions (), "` check_coin` is niet aanwezig"
11- assert "determine_due" in static . getFunctionDefinitions (), "` determine_due` is niet aanwezig"
12- assert "prompt_coin" not in static . getFunctionDefinitions (), "` prompt_coin` is aanwezig, maar dat staat niet in de opdracht"
13- assert ast .While in static . AbstractSyntaxTree (), "er wordt geen gebruik gemaakt van een `while`-loop"
11+ assert defines_function ( " check_coin" )
12+ assert defines_function ( " determine_due" )
13+ assert defines_function ( " prompt_coin" )
14+ assert in_code ( ast .While )
1415
1516@t .passed (doctest_ok )
1617@t .test (10 )
Original file line number Diff line number Diff line change 11from checkpy import *
22from _basics_no_listcomp import *
3+ from _static_analysis import *
34
45@t .passed (doctest_ok )
56def has_functions ():
67 """alle gevraagde functies zijn aanwezig"""
7- assert "pie_percent" in static . getFunctionDefinitions (), "` pie_percent` is niet aanwezig"
8- assert "triple" in static . getFunctionDefinitions (), "` triple` is niet aanwezig"
9- assert "absdiff" in static . getFunctionDefinitions (), "` absdiff` is niet aanwezig"
10- assert "kmmiles" in static . getFunctionDefinitions (), "` kmmiles` is niet aanwezig"
11- assert "avg3" in static . getFunctionDefinitions (), "` avg3` is niet aanwezig"
12- assert "avg3of4" in static . getFunctionDefinitions (), "` avg3of4` is niet aanwezig"
8+ assert defines_function ( " pie_percent" )
9+ assert defines_function ( " triple" )
10+ assert defines_function ( " absdiff" )
11+ assert defines_function ( " kmmiles" )
12+ assert defines_function ( " avg3" )
13+ assert defines_function ( " avg3of4" )
1314
1415@t .passed (has_functions )
1516def test_pie_percent (test ):
Original file line number Diff line number Diff line change 77@t .passed (doctest_ok )
88def has_functions ():
99 """alle gevraagde functies zijn aanwezig"""
10- assert "repeat" in static .getFunctionDefinitions (), "`repeat` is niet aanwezig"
11- assert "total_length" in static .getFunctionDefinitions (), "`total_length` is niet aanwezig"
12-
13- assert ast .If not in static .AbstractSyntaxTree ()
14- assert ast .While not in static .AbstractSyntaxTree ()
15- assert ast .For not in static .AbstractSyntaxTree ()
10+ assert defines_function ("repeat" )
11+ assert defines_function ("total_length" )
12+ assert not_in_code (ast .If )
13+ assert not_in_code (ast .While )
14+ assert not_in_code (ast .For )
1615
1716@t .passed (has_functions )
1817def test_repeat (test ):
Original file line number Diff line number Diff line change 11from checkpy import *
22from _basics_no_listcomp import *
3+ from _static_analysis import *
34
45@t .passed (doctest_ok )
56def has_functions ():
67 """functie `weeks_elapsed` is aanwezig"""
7- assert "weeks_elapsed" in static . getFunctionDefinitions (), "` weeks_elapsed` is niet aanwezig"
8+ assert defines_function ( " weeks_elapsed" )
89
910@t .passed (has_functions )
1011def test_weeks_elapsed (test ):
You can’t perform that action at this time.
0 commit comments