Пример #1
0
    def test_proc_problem_language(self):
        """Test to check if language in proc problem page displays correctly"""
        curr_path = os.path.dirname(__file__)
        client = Client()

        zip_proc_path = os.path.join(curr_path, ParseTest.ZIP_FOLDER,
                                     ParseTest.PROC_OK)
        collection = create_collection('Colleccion de prueba XYZ')
        user = create_user('5555', 'pepe')
        problem = ProcProblem(zipfile=zip_proc_path,
                              collection=collection,
                              author=user)
        problem.clean()
        problem.save()
        client.login(username='******', password='******')

        client.cookies.load({settings.LANGUAGE_COOKIE_NAME: 'en'})
        url = reverse('judge:problem', args=[problem.pk])
        response = client.get(url, follow=True)
        self.assertIn('Procedure call', response.content.decode('utf-8'))
        self.assertIn('Expected result', response.content.decode('utf-8'))

        client.cookies.load({settings.LANGUAGE_COOKIE_NAME: 'es'})
        url = reverse('judge:problem', args=[problem.pk])
        response = client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Llamada a procedimiento',
                      response.content.decode('utf-8'))
        self.assertIn('Resultado esperado', response.content.decode('utf-8'))
Пример #2
0
    def test_proc(self):
        """Tests for ProcProblem.judge()"""
        collection = Collection()
        collection.save()
        create = '''CREATE TABLE Club(
                        CIF CHAR(9) PRIMARY KEY, -- No puede ser NULL
                        Nombre VARCHAR2(40) NOT NULL UNIQUE,
                        Sede VARCHAR2(30) NOT NULL,
                        Num_Socios NUMBER(10,0) NOT NULL,
                        CONSTRAINT NumSociosPositivos CHECK (Num_Socios >= 0)
                    );'''
        insert = """INSERT INTO Club VALUES ('11111111X', 'Real Madrid CF', 'Concha Espina', 70000);
                    INSERT INTO Club VALUES ('11111112X', 'Futbol Club Barcelona', 'Aristides Maillol', 80000);
                    INSERT INTO Club VALUES ('11111113X', 'PSG', 'Rue du Commandant Guilbaud', 1000);"""
        solution = """
            CREATE OR REPLACE PROCEDURE inserta(x NUMBER) IS
                num_equipos NUMBER;
            BEGIN
                SELECT COUNT(*) INTO num_equipos FROM Club;
                INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos + x);
            END;"""
        call = "inserta(4)"

        # Time-limit
        tle = """
                CREATE OR REPLACE PROCEDURE inserta(x NUMBER) IS
                    num_equipos NUMBER;
                    IN_TIME INT := 11; --num seconds
                    v_now DATE;
                BEGIN
                    SELECT SYSDATE INTO v_now FROM DUAL;
                    SELECT COUNT(*) INTO num_equipos FROM Club;
                    LOOP
                        EXIT WHEN v_now + (IN_TIME * (1/86400)) <= SYSDATE;
                    END LOOP;  
                    INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos + x);
                END;"""
        # Error in the procedure code
        compile_error = """
                CREATE OR REPLACE PROCEDURE inserta(x NUMBER) IS
                    num_equipos NUMBER;
                BEGIN
                    SELECT SYSDATE INTO v_now DUAL; -- Falta FROM
                    INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos + x);
                END;"""
        # Division by zero
        runtime_error1 = """
                CREATE OR REPLACE PROCEDURE inserta(x NUMBER) IS
                    num_equipos NUMBER;
                BEGIN
                    SELECT COUNT(*) INTO num_equipos FROM Club;
                    INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos / 0); -- Division by zero
                END;"""
        # Incompatible type in parameter
        runtime_error2 = """
                CREATE OR REPLACE PROCEDURE inserta(x DATE) IS -- Incorrect parameter when invoked
                    num_equipos NUMBER;
                BEGIN
                    SELECT COUNT(*) INTO num_equipos FROM Club;
                    INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos);
                END;"""
        wrong_answer = """
            CREATE OR REPLACE PROCEDURE inserta(x NUMBER) IS
                num_equipos NUMBER;
            BEGIN
                SELECT COUNT(*) INTO num_equipos FROM Club;
                INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos + x + 2);
            END;"""
        bad_name = """
                    CREATE OR REPLACE PROCEDURE insertaR(x NUMBER) IS
                        num_equipos NUMBER;
                    BEGIN
                        SELECT COUNT(*) INTO num_equipos FROM Club;
                        INSERT INTO CLUB VALUES ('22222222X', 'A', 'B', num_equipos + x);
                    END;"""

        oracle = OracleExecutor.get()
        problem = ProcProblem(title_md='Test Function',
                              text_md='bla bla bla',
                              create_sql=create,
                              insert_sql=insert,
                              collection=collection,
                              author=None,
                              solution=solution,
                              proc_call=call)
        problem.clean()  # Needed to compute extra HTML fields and solutions
        problem.save()

        # Time-limit
        self.assert_executor_exception(lambda: problem.judge(tle, oracle),
                                       OracleStatusCode.TLE_USER_CODE)

        # Error when compiling user function
        self.assert_executor_exception(
            lambda: problem.judge(compile_error, oracle),
            OracleStatusCode.COMPILATION_ERROR)

        # Error when invoking user function
        self.assert_executor_exception(
            lambda: problem.judge(runtime_error1, oracle),
            OracleStatusCode.EXECUTE_USER_CODE)
        self.assert_executor_exception(
            lambda: problem.judge(runtime_error2, oracle),
            OracleStatusCode.EXECUTE_USER_CODE)
        self.assert_executor_exception(lambda: problem.judge(bad_name, oracle),
                                       OracleStatusCode.EXECUTE_USER_CODE)

        # Correct solution
        self.assertEqual(problem.judge(solution, oracle)[0], VeredictCode.AC)

        # Incorrect solution
        self.assertEqual(
            problem.judge(wrong_answer, oracle)[0], VeredictCode.WA)