def exact1(test): notAllowed = {"list": "[", "break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda : assertlib.numberOnLine(2, lib.getLine(lib.outputOf(_fileName, stdinArgs=[1]), 0)) test.description = lambda : "vind het 1ste priemgetal: 2"
def containsRequiredFunctionDefinitions(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda : assertlib.fileContainsFunctionDefinitions(_fileName, "tunnel") test.description = lambda : "defines the function `tunnel()`"
def exact16times4(test): notAllowed = {"import": "import"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.numberOnLine( 64, lib.getLine(lib.outputOf(_fileName, stdinArgs=[16, 4]), 0)) test.description = lambda: "het product van 16 en 4 is 64"
def handlesWrongInput(test): notAllowed = {"the * operator, but instead loops": "*"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.match( lib.outputOf(_fileName, stdinArgs=[-100, 24, 1]), re.compile(".*(# #)[ ]*(\n)")) test.description = lambda: "rejects heights of -100 and 24, then accepts a height of 1"
def containsRequiredFunctionDefinitions(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.fileContainsFunctionDefinitions( _fileName, "basejump") test.description = lambda: "definieert de functie `basejump()`"
def exact1(test): notAllowed = {"lists": "[", "break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.numberOnLine( 2, lib.getLine(lib.outputOf(_fileName, stdinArgs=[1]), 0)) test.description = lambda: "input of 1 yields output of 2"
def hasthrow_two_dice(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.fileContainsFunctionDefinitions( _fileName, "throw_two_dice") test.description = lambda: "defines the function throw_two_dice" test.timeout = lambda: 10
def hasworp_met_twee_dobbelstenen(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.fileContainsFunctionDefinitions( _fileName, "worp_met_twee_dobbelstenen") test.description = lambda: "definieert de functie worp_met_twee_dobbelstenen" test.timeout = lambda: 60
def givesMin(test): notAllowed = {"min": "min"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.numberOnLine( 0.37, lib.getLine(lib.outputOf( _fileName), 0), deviation=0.05) and assertlib.numberOnLine( 0.69, lib.getLine(lib.outputOf(_fileName), 0), deviation=0.05) test.fail = lambda info: "Zorg dat het juiste minimum op de eerste regel geprint wordt" test.description = lambda: "print het juiste minimum van de functies"
def givesMin(test): notAllowed = {"the min() function": "min("} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = lambda: assertlib.numberOnLine( 0.37, lib.getLine(lib.outputOf( _fileName), 0), deviation=0.05) and assertlib.numberOnLine( 0.69, lib.getLine(lib.outputOf(_fileName), 0), deviation=0.05) test.fail = lambda info: "make sure that the minimum is printed on the very first line of output" test.description = lambda: "prints the correct minimum as text"
def correctBarriers(test): def testMethod(): result = lib.getLine(lib.outputOf(_fileName), 0) testResult = assertlib.match(result, ".*9552.*9586.*") or assertlib.match(result, ".*9586.*9552.*") return testResult test.test = testMethod notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.description = lambda : "geeft het correcte beginpunt en eindpunt van de reeks" test.fail = lambda info : "let op: de priemgetallen horen niet bij de reeks!"
def correctBarriers(test): def testMethod(): result = lib.getLine(lib.outputOf(_fileName), 0) testResult = assertlib.match(result, ".*9552.*9586.*") or assertlib.match( result, ".*9586.*9552.*") return testResult test.test = testMethod notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.description = lambda: "prints the correct start and end of the sequence" test.fail = lambda info: "note that primes are not actually part of the sequence!"
def correctDistance(test): notAllowed = {"sum": "sum(", "break": "break", "classes": "class"} notAllowedCode(test, lib.source(_fileName), notAllowed) def testMethod(): output = lib.outputOf(test.fileName, overwriteAttributes=[("__name__", "__main__")]) line = lib.getLine(output, 0) correctKm = assertlib.numberOnLine(10.86, line, deviation=0.02) correctM = assertlib.numberOnLine(10860, line, deviation=20) return correctKm or correctM test.test = testMethod test.description = lambda: "print de afgelegde afstand"
def outputsNumbers(test): def testMethod(): result = lib.outputOf(_fileName, stdinArgs=[10]) for line in clean_lines(result): years = lib.getPositiveIntegersFromString(line) if len(years) > 0: return True notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = testMethod test.description = lambda: "The code outputs numbers" test.timeout = lambda: 90
def correctHighestTemp(test): notAllowed = {"sum": "sum(", "break": "break", "classes": "class"} notAllowedCode(test, lib.source(_fileName), notAllowed) def testMethod(): correctAnswer = "36.8" if helpers.isHardcodedIn(correctAnswer, test.fileName): test.success = lambda info: "let op: deze output is hardcoded. {} staat in de source code!".format( correctAnswer) output = lib.outputOf(test.fileName, overwriteAttributes=[("__name__", "__main__")]) return assertlib.contains(output, correctAnswer) test.test = testMethod test.description = lambda: "print hoogste temperatuur"
def allEvenNumbersInOutput(test): def testMethod(): result = lib.outputOf(_fileName) evenNumbers = set(range(4, 1001, 2)) for line in result.split("\n"): if line == "\n": continue evenNumbers -= set(lib.getPositiveIntegersFromString(line)) testResult = len(evenNumbers) == 0 return testResult notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = testMethod test.description = lambda: "alle even getallen tot 1000 staan in de output"
def hassimulate_monopoly_games(test): def testMethod(): correctFunction = False if assertlib.fileContainsFunctionDefinitions(_fileName, "simulate_monopoly_games"): nArguments = len(lib.getFunction("simulate_monopoly_games", _fileName).arguments) if nArguments == 3: correctFunction = True return correctFunction notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = testMethod test.fail = lambda info : "make sure that the simulate_monopoly_games function has three arguments, the number of games, the starting_money for player 1, and the starting_money for player 2" test.description = lambda : "defines functie simulate_monopoly_games with the proper number of arguments" test.timeout = lambda : 90
def hassimuleer_groot_aantal_potjes_Monopoly(test): def testMethod(): correctFunction = False if assertlib.fileContainsFunctionDefinitions( _fileName, "simuleer_groot_aantal_potjes_monopoly"): nArguments = len( lib.getFunction("simuleer_groot_aantal_potjes_monopoly", _fileName).arguments) if nArguments == 3: correctFunction = True return correctFunction notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = testMethod test.fail = lambda info: "zorg dat de functie drie argumenten heeft, het aantal potjes, startgeld voor speler 1 en startgeld voor speler 2" test.description = lambda: "definieert de functie simuleer_potje_monopoly en simuleer_groot_aanal_potjes_monopoly met drie argumenten" test.timeout = lambda: 90
def outputsYears(test): def testMethod(): result = lib.outputOf(_fileName, stdinArgs=[1]) lines = clean_lines(result) if len(lines) > 1: return False, "Output consists of more than one line" if len(lines) < 1: return False, "No output" line = lines[0] ints = lib.getPositiveIntegersFromString(line) if len(ints) < 1: return False, "No year found in the output" return True notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) test.test = testMethod test.fail = lambda info: info test.description = lambda: "The code outputs a line containing a number" test.timeout = lambda: 90
def containsRequiredFunction1Definition(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) has_function(test, _fileName, "simulate_apple1", ['x', 'dt'])
def isHardcodedIn(value, fileName): source = lib.removeComments(lib.source(fileName)) return bool(findLineWith(source, value))
def containsRequiredFunctionDefinitions(test): notAllowed = {"break": "break"} notAllowedCode(test, lib.source(_fileName), notAllowed) has_function(test, _fileName, "simulate_free_fall", ['x_start', 'x_end', 'm', 'xi', 'dt'])
def test_code(): notAllowedCode(test, lib.source(_fileName), notAllowed) return lib.outputOf(_fileName, stdinArgs=[-100, 24, 1])