Exemplo n.º 1
0
 def testMethod():
     output = lib.outputOf(_fileName,
                           argv=["vigenere.py", "a"],
                           stdinArgs=["a"],
                           overwriteAttributes=[("__name__", "__main__")])
     line = lib.getLine(output, 0)
     return asserts.contains(line, "a")
Exemplo n.º 2
0
 def containsCheck():
     output = lib.outputOf(test.fileName, stdinArgs=[22, 15])
     time = re.search("\d{1,2}:\d{2}", output)
     if time is None:
         return False
     else:
         return True
Exemplo n.º 3
0
	def testMethod():
		output = lib.outputOf(
            _fileName,
            stdinArgs = [23],
            overwriteAttributes = [("__name__", "__main__")]
        )
		regex = re.compile(".*"
			"(                      ##)[ ]*(\n)"
			"(                     ###)[ ]*(\n)"
			"(                    ####)[ ]*(\n)"
			"(                   #####)[ ]*(\n)"
			"(                  ######)[ ]*(\n)"
			"(                 #######)[ ]*(\n)"
			"(                ########)[ ]*(\n)"
			"(               #########)[ ]*(\n)"
			"(              ##########)[ ]*(\n)"
			"(             ###########)[ ]*(\n)"
			"(            ############)[ ]*(\n)"
			"(           #############)[ ]*(\n)"
			"(          ##############)[ ]*(\n)"
			"(         ###############)[ ]*(\n)"
			"(        ################)[ ]*(\n)"
			"(       #################)[ ]*(\n)"
			"(      ##################)[ ]*(\n)"
			"(     ###################)[ ]*(\n)"
			"(    ####################)[ ]*(\n)"
			"(   #####################)[ ]*(\n)"
			"(  ######################)[ ]*(\n)"
			"( #######################)[ ]*(\n)"
			"(########################)[ ]*(\n)"
			".*", re.MULTILINE)
		return asserts.match(output, regex)
Exemplo n.º 4
0
 def testMethod():
     output = lib.outputOf(_fileName,
                           overwriteAttributes=[("__name__", "__main__")])
     line = lib.getLine(output, 0)
     return asserts.numberOnLine(
         147, line, deviation=5
     ), "hint: make sure the number of throws is on the first line of the output"
Exemplo n.º 5
0
 def containsCheck():
     output = lib.outputOf(test.fileName, stdinArgs=[22, 15])
     time = re.search("(10a|11a|13a|14a|15a|15b)", output)
     if time is None:
         return False
     else:
         return True
Exemplo n.º 6
0
	def testMethod():
		output = lib.outputOf(
            _fileName,
            stdinArgs = [-1, 0],
            overwriteAttributes = [("__name__", "__main__")]
        )
		return not asserts.contains(output, "#")
Exemplo n.º 7
0
 def testMethod():
     primes = set([
         2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
         67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
         139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
         211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277,
         281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359,
         367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439,
         443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,
         523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
         613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683,
         691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773,
         787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
         877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967,
         971, 977, 983, 991, 997
     ])
     result = lib.outputOf(_fileName)
     for line in result.split("\n"):
         if line.strip() == "":
             continue
         numbers = lib.getPositiveIntegersFromString(line)
         if sum(1 for n in numbers if n in primes) != 2:
             return False, "berekening \"{}\" bevat niet precies twee priemgetallen".format(
                 line)
     return True
Exemplo n.º 8
0
def handlesWrongInput(test):
    test.test = lambda: assertlib.numberOnLine(
        4,
        lib.getLine(
            lib.outputOf(_fileName,
                         stdinArgs=[-1, -1, -1, -1, -1, -1, -1, 0.41]), 0))
    test.description = lambda: "rejects negative input"
Exemplo n.º 9
0
def exactMario23(test):
    test.test = lambda: assertlib.match(
        lib.outputOf(_fileName, stdinArgs=[23]),
        re.compile(
            ".*"
            "(                                            # #)[ ]*(\n)"
            "(                                          # # #)[ ]*(\n)"
            "(                                        # # # #)[ ]*(\n)"
            "(                                      # # # # #)[ ]*(\n)"
            "(                                    # # # # # #)[ ]*(\n)"
            "(                                  # # # # # # #)[ ]*(\n)"
            "(                                # # # # # # # #)[ ]*(\n)"
            "(                              # # # # # # # # #)[ ]*(\n)"
            "(                            # # # # # # # # # #)[ ]*(\n)"
            "(                          # # # # # # # # # # #)[ ]*(\n)"
            "(                        # # # # # # # # # # # #)[ ]*(\n)"
            "(                      # # # # # # # # # # # # #)[ ]*(\n)"
            "(                    # # # # # # # # # # # # # #)[ ]*(\n)"
            "(                  # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(                # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(              # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(            # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(          # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(        # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(      # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(    # # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(  # # # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(# # # # # # # # # # # # # # # # # # # # # # # #)[ ]*"
            ".*", re.MULTILINE))
    test.description = lambda: "correctly prints a pyramid of height 23"
Exemplo n.º 10
0
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"
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 def testMethod():
     output = lib.outputOf(
         _fileName,
         overwriteAttributes = [("__name__", "__main__")]
     )
     line = lib.getLine(output, 1)
     return asserts.numberOnLine(330, line, deviation = 0.1)
Exemplo n.º 13
0
def exactMario23(test):
    test.test = lambda: assertlib.match(
        lib.outputOf(_fileName, stdinArgs=[23]),
        re.compile(
            ".*"
            "(                                            # #)[ ]*(\n)"
            "(                                          # # #)[ ]*(\n)"
            "(                                        # # # #)[ ]*(\n)"
            "(                                      # # # # #)[ ]*(\n)"
            "(                                    # # # # # #)[ ]*(\n)"
            "(                                  # # # # # # #)[ ]*(\n)"
            "(                                # # # # # # # #)[ ]*(\n)"
            "(                              # # # # # # # # #)[ ]*(\n)"
            "(                            # # # # # # # # # #)[ ]*(\n)"
            "(                          # # # # # # # # # # #)[ ]*(\n)"
            "(                        # # # # # # # # # # # #)[ ]*(\n)"
            "(                      # # # # # # # # # # # # #)[ ]*(\n)"
            "(                    # # # # # # # # # # # # # #)[ ]*(\n)"
            "(                  # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(                # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(              # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(            # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(          # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(        # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(      # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(    # # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(  # # # # # # # # # # # # # # # # # # # # # # #)[ ]*(\n)"
            "(# # # # # # # # # # # # # # # # # # # # # # # #)[ ]*"
            ".*", re.MULTILINE))
    test.description = lambda: "print een welgevormde pyramide van 23 hoog"
Exemplo n.º 14
0
 def testMethod():
     output = lib.outputOf(_fileName,
                           argv=["find.py"],
                           overwriteAttributes=[("__name__", "__main__")],
                           ignoreExceptions=[SystemExit])
     line = lib.getLine(output, 0)
     return asserts.contains(line, "usage: python find.py needle haystack")
Exemplo n.º 15
0
def handlesWrongInput(test):
    test.test = lambda: assertlib.numberOnLine(
        4,
        lib.getLine(
            lib.outputOf(_fileName,
                         stdinArgs=[-1, -1, -1, -1, -1, -1, -1, 0.41]), 0))
    test.description = lambda: "accepteert geen negatieve invoer"
Exemplo n.º 16
0
def exactMario23(test):
	test.test = lambda : assertlib.contains(lib.outputOf(_fileName, [23]),
"""                      ##
                     ###
                    ####
                   #####
                  ######
                 #######
                ########
               #########
              ##########
             ###########
            ############
           #############
          ##############
         ###############
        ################
       #################
      ##################
     ###################
    ####################
   #####################
  ######################
 #######################
########################""")
	test.description = lambda : "prints a pyramid of height 23"
Exemplo n.º 17
0
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"
Exemplo n.º 18
0
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"
Exemplo n.º 19
0
 def testMethod():
     output = lib.outputOf(_fileName,
                           argv=["vigenere.py", "foo", "bar"],
                           stdinArgs=["foo"],
                           overwriteAttributes=[("__name__", "__main__")],
                           ignoreExceptions=[SystemExit])
     line = lib.getLine(output, 0)
     return asserts.contains(line, "usage: python vigenere.py keyword")
Exemplo n.º 20
0
 def testMethod():
     result = lib.outputOf(_fileName, stdinArgs=[100])
     expected_numbers = set([
         2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
         67, 71, 73, 79, 83, 89, 97
     ])
     printed_numbers = set(lib.getPositiveIntegersFromString(result))
     return expected_numbers == printed_numbers
Exemplo n.º 21
0
def exactMario3(test):
  test.test = lambda : assertlib.match(lib.outputOf(_fileName, [3]), 
    re.compile(".*"
      "(    # #)[ ]*(\n)"
      "(  # # #)[ ]*(\n)"
      "(# # # #)[ ]*"
      ".*", re.MULTILINE))
  test.description = lambda : "print een pyramide van 3 hoog"
Exemplo n.º 22
0
    def testMethod():
        result = lib.outputOf(_fileName, stdinArgs=[2000, 2010])

        for line in clean_lines(result):
            years = lib.getPositiveIntegersFromString(line)
            if len(years) != 1:
                return False
        return True
Exemplo n.º 23
0
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"
Exemplo n.º 24
0
 def testMethod():
     result = lib.outputOf(_fileName)
     for line in result.split("\n"):
         if line.strip() == "":
             continue
         numbers = lib.getPositiveIntegersFromString(line)
         if not any(sum(numbers) / 2 == n for n in numbers):
             return False, "\"{}\" is an incorrect calculation".format(line)
     return True
Exemplo n.º 25
0
 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
Exemplo n.º 26
0
    def testMethod():
        correctAnswer = "-24.8"
        if helpers.isHardcodedIn(correctAnswer, test.fileName):
            test.success = lambda info: "watch out: {} appears to be hardcoded!".format(
                correctAnswer)

        output = lib.outputOf(test.fileName,
                              overwriteAttributes=[("__name__", "__main__")])
        return assertlib.contains(output, correctAnswer)
Exemplo n.º 27
0
 def testMethod():
     output = lib.outputOf(
         _fileName,
         argv = ["caesar.py", "65"],
         stdinArgs = ["barfoo"],
         overwriteAttributes = [("__name__", "__main__")]
     )
     line = lib.getLine(output, 0)
     return asserts.contains(line, "onesbb")
Exemplo n.º 28
0
 def testMethod():
     output = lib.outputOf(
         _fileName,
         argv = ["caesar.py", "3"],
         stdinArgs = ["BARFOO"],
         overwriteAttributes = [("__name__", "__main__")]
     )
     line = lib.getLine(output, 0)
     return asserts.contains(line, "EDUIRR")
Exemplo n.º 29
0
    def testMethod():
        correctAnswer = "-24.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)
Exemplo n.º 30
0
    def testMethod():
        correctYear = 1911

        line = lib.getLine(lib.outputOf(_fileName), 4)
        numbers = lib.getNumbersFromString(line)

        check = correctYear in numbers

        return check