Skip to content

Commit

Permalink
dont run student code for integreren
Browse files Browse the repository at this point in the history
  • Loading branch information
stgm committed Sep 28, 2023
1 parent 06487ed commit 60a42da
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/integreren/montecarloTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ def after():

@t.test(0)
def hasMontecarlo(test):
# v---- Filter global code from source file -----

global _originalFileName
global _fileName

_originalFileName = _fileName

with open(_fileName, 'r') as f:
tempfile = f"_{_fileName}.tmp"
file_contents = f.readlines()

with open(tempfile, 'w') as f:
state = 0
for line in file_contents:
if state == 0:
if line.startswith('def '):
state = 1
f.write(line)
elif state == 1:
if not (line.strip() == '' or line.startswith(' ') or line.startswith("\t") or line.startswith("def ") or line.startswith("#")):
state = 2
continue
f.write(line)
elif state == 2:
if line.startswith('def '):
f.write(line)
state = 1

_fileName = tempfile

# ^---- Filter global code from source file -----

test.test = lambda : assertlib.fileContainsFunctionDefinitions(_fileName, "montecarlo")
test.description = lambda : "definieert de functie montecarlo()"
test.timeout = lambda : 90
Expand Down
32 changes: 32 additions & 0 deletions tests/integreren/riemannTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ def after():

@t.test(0)
def hasRiemann(test):
# v---- Filter global code from source file -----

global _originalFileName
global _fileName

_originalFileName = _fileName

with open(_fileName, 'r') as f:
tempfile = f"_{_fileName}.tmp"
file_contents = f.readlines()

with open(tempfile, 'w') as f:
state = 0
for line in file_contents:
if state == 0:
if line.startswith('def '):
state = 1
f.write(line)
elif state == 1:
if not (line.strip() == '' or line.startswith(' ') or line.startswith("\t") or line.startswith("def ") or line.startswith("#")):
state = 2
continue
f.write(line)
elif state == 2:
if line.startswith('def '):
f.write(line)
state = 1

_fileName = tempfile

# ^---- Filter global code from source file -----

test.test = lambda : assertlib.fileContainsFunctionDefinitions(_fileName, "riemann")
test.description = lambda : "definieert de functie riemann()"
test.timeout = lambda : 90
Expand Down
32 changes: 32 additions & 0 deletions tests/integreren/twitterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ def after():

@t.test(0)
def correctFunc1(test):
# v---- Filter global code from source file -----

global _originalFileName
global _fileName

_originalFileName = _fileName

with open(_fileName, 'r') as f:
tempfile = f"_{_fileName}.tmp"
file_contents = f.readlines()

with open(tempfile, 'w') as f:
state = 0
for line in file_contents:
if state == 0:
if line.startswith('def '):
state = 1
f.write(line)
elif state == 1:
if not (line.strip() == '' or line.startswith(' ') or line.startswith("\t") or line.startswith("def ") or line.startswith("#")):
state = 2
continue
f.write(line)
elif state == 2:
if line.startswith('def '):
f.write(line)
state = 1

_fileName = tempfile

# ^---- Filter global code from source file -----

test.test = lambda : assertlib.between(lib.getFunction("twitter", _fileName)(), 0.82, 0.83)
test.description = lambda : "twitter geeft het juiste antwoord"
test.timeout = lambda : 90

0 comments on commit 60a42da

Please sign in to comment.