Beispiel #1
0
    def test(input, expect, num):
        dest = open("./test/solutions/" + str(num) + ".txt", "w")

        if type(input) is str:
            inputfile = TestUtil.makeSource(input, num)
            lexer = MCLexer(inputfile)
            tokens = CommonTokenStream(lexer)
            parser = MCParser(tokens)
            tree = parser.program()
            asttree = ASTGeneration().visit(tree)
        else:
            inputfile = TestUtil.makeSource(str(input), num)
            asttree = input

        checker = StaticChecker(asttree)
        try:
            res = checker.check()
            dest.write(str(list(res)))
        except StaticError as e:
            dest.write(str(e))
        finally:
            dest.close()
        dest = open("./test/solutions/" + str(num) + ".txt", "r")
        line = dest.read()
        return line == expect
Beispiel #2
0
    def checkStatic(input, expect, num):
        dest = open("./test/solutions/" + str(num) + ".txt", "w")

        if type(input) is str:
            inputfile = TestUtil.makeSource(input, num)
            lexer = BKITLexer(inputfile)
            tokens = CommonTokenStream(lexer)
            parser = BKITParser(tokens)
            tree = parser.program()
            asttree = ASTGeneration().visit(tree)
        else:
            inputfile = TestUtil.makeSource(str(input), num)
            asttree = input

        checker = StaticChecker(asttree)
        try:
            res = checker.check()
            # dest.write(str(list(res)))
        except StaticError as e:
            dest.write(str(e))
        finally:
            dest.close()
        dest = open("./test/solutions/" + str(num) + ".txt", "r")
        line = dest.read()
        if (line != expect):
            print("Number:", num)
            print("Input:", input)
            print("Output:", line)
            print("Expect:", expect)
            print(
                "-------------------------------------------------------------------\n\n"
            )

        return line == expect
Beispiel #3
0
 def check(soldir, asttree, num):
     dest = open(soldir + "/" + str(num) + ".txt", "w")
     checker = StaticChecker(asttree)
     try:
         res = checker.check()
         dest.write('[' + ', '.join([str(x) for x in res]) + ']')
     except StaticError as e:
         dest.write(str(e))
     finally:
         dest.close()
Beispiel #4
0
 def check(soldir, asttree, num):
     dest = open(os.path.join(soldir, str(num) + ".txt"), "w")
     checker = StaticChecker(asttree)
     try:
         res = checker.check()
         dest.write(str(list(res)))
     except StaticError as e:
         dest.write(str(e))
     finally:
         dest.close()
Beispiel #5
0
    def check(soldir, asttree, num):
        dest = open(soldir + "/" + str(num) + ".txt", "w")
        checker = StaticChecker(asttree)
        try:
            res = checker.check()
            res = res[::-1]
            if isinstance(res, list):
                res = '[' + ','.join(str(i) for i in res) + ']'

            dest.write(str(res))
        except StaticError as e:
            dest.write(str(e))
        finally:
            dest.close()
Beispiel #6
0
    def test1(inputdir, outputdir, num):

        dest = open(outputdir + "/" + str(num) + ".txt", "w")

        try:
            lexer = BKITLexer(FileStream(inputdir + "/" + str(num) + ".txt"))
            tokens = CommonTokenStream(lexer)
            parser = BKITParser(tokens)
            tree = parser.program()
            asttree = ASTGeneration().visit(tree)

            checker = StaticChecker(asttree)
            res = checker.check()

        except StaticError as e:
            dest.write(str(e) + '\n')
        except:
            trace = traceback.format_exc()
            print("Test " + str(num) + " catches unexpected error:" + trace +
                  "\n")
        finally:
            dest.close()