Esempio n. 1
0
    def POST(self):
        form = self.TestForm();
        form.validates()
        code = form["code"].value
        print code
        stdin = form["stdin"].value

        compiler = Compiler()

        compileHasSucceeded = compiler.compile(code)
        error = ""
        if compileHasSucceeded :
            compiler.run(stdin)
            compiler.clean()
        else:
            error = "compilation has failed"



        return self.render.free(
            code,
            error,
            compiler.compileSdtout,
            stdin,
            compiler.runStdout
        )
Esempio n. 2
0
    def POST(self,exoNumber):
        
        form = self.ExoForm()
        form.validates()

        code = unicode(form["code"].value)

        var = dict(id= exoNumber)
        tests = self.db.select(
            "tests",
            var,
            what = "stdin, stdout",
            where = 'exo_id = $id',
        );

        compiler = Compiler()
        compileHasSucceeded = compiler.compile(code)

        #array of boolean if a given test has succed or not
        successTests = []
        oneTestHasFailed = False

        error = ""
        if compileHasSucceeded :
            for test in tests:
                compiler.run(test.stdin)
                
                success = compiler.runStdout == test.stdout
                print "prout"
                print compiler.runStdout
                successTests.append(success)
                if not success:

                    error = "Some of the tests to check if your software works has failed" 
            compiler.clean()
        else:
            error = "compilation has failed"




        return self.render.result(
            code,
            error,
            compiler.compileSdtout,
            successTests
        )
Esempio n. 3
0
    def POST(self):
        form = self.AddExoForm()
        form.validates()

        code = form["code"].value
        title = form["title"].value
        problem = form["problem"].value

        stdins = []
        stdouts = []


        for i in range(4):
            stdins.append(
                form["stdin"+str(i)].value
            )

        compiler = Compiler()
        compileHasSucceeded = compiler.compile(code)

        error = compiler.compileSdtout

        exo = None
        tests = None

        error = ""
        if compileHasSucceeded :
            for stdin in stdins:
                compiler.run(stdin)
                stdouts.append(compiler.runStdout)

            self.db.insert(
                "exos",
                problem = problem,
                title = title,
                possible_solution = code
            )

            exo = self.db.select(
                "exos",
                dict(title=title),
                what = "id, title, problem, possible_solution",
                where = "title = $title"
            )[0]

            exoId = exo.id

            for i in range(4):
                self.db.insert(
                    "tests",
                    exo_id = exoId,
                    stdin = stdins[i],
                    stdout = stdouts[i]
                )
            tests = self.db.select(
                "tests",
                dict(exo_id = exoId),
                what = "stdin, stdout",
                where = "exo_id = $exo_id"
            )
        else:
            error = "compilation has failed"


        if (exo):
            exo.problem = exo.problem.replace("\n","<br/>\n")
        return self.render.showexo(
            error,
            compiler.compileSdtout,
            exo,
            tests
        )