def test_callback(self): def compiling_callback(code, stderr): self.assertFalse(code) self.assertFalse(stderr) def judging_callback( id, status, stderr, duration # pylint: disable = W0622 ): # pylint: disable = W0613 statuses = [Status.AC, Status.WA, Status.RE] self.assertEqual(status, statuses[id]) result = judge( GCC("c", "4.8"), b""" #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } """, [(b"1 1", b"1"), (b"1 2", b"0.5"), (b"0 0", b"")], { "callback": { "compile": compiling_callback, "judge": judging_callback, } }, ) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertFalse(result[1])
def test_callback(self): def compiling_callback(code, stderr): self.assertFalse(code) self.assertFalse(stderr) def judging_callback( id, status, # pylint: disable = W0622 stderr, duration): # pylint: disable = W0613 statuses = [Status.AC, Status.WA, Status.RE] self.assertEqual(status, statuses[id]) result = judge( GCC('c', '4.8'), b''' #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } ''', [(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')], { 'callback': { 'compile': compiling_callback, 'judge': judging_callback } }) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertFalse(result[1])
def test_gccgo(self): result = judge( GCC('go', 4.9), b'package main\n' b'import "fmt"\n' b'func main() {\n' br' fmt.Printf("hello, world\n")' b'\n' b'}\n', [(b'', b'hello, world\n')]) self.assertEqual(result[0][0][0], Status.AC)
def test_gccgo(self): result = judge( GCC("go", 4.9), b"package main\n" b'import "fmt"\n' b"func main() {\n" br' fmt.Printf("hello, world\n")' b"\n" b"}\n", [(b"", b"hello, world\n")], ) self.assertEqual(result[0][0][0], Status.AC)
def test_judge(self): result = judge( GCC('c', '4.8'), b''' #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } ''', [(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')]) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][1]) self.assertFalse(result[1])
def test_ONF(self): result = judge( GCC('c', '4.8'), b''' #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } ''', [(b'1 1', b'1'), (b'0 0', b'')], {'iofilename': { 'out': 'out.txt' }}) self.assertEqual(result[0][0][0], Status.ONF) self.assertEqual(result[0][1][0], Status.RE) self.assertTrue(result[0][1][1][1]) self.assertFalse(result[1])
def test_TLE(self): result = judge( GCC('cpp', '4.8'), b''' #include <cstdio> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); while (true) ; } ''', [(b'1 1', b'1'), (b'0 0', b'')], {'limit': { 'time': .8 }}) self.assertEqual(result[0][0][0], Status.TLE) self.assertEqual(result[0][1][0], Status.RE) self.assertAlmostEqual(result[0][0][2], .8, 0) self.assertLess(result[0][1][2], .8, 0) self.assertFalse(result[1])
def test_judge(self): result = judge( GCC("c", "4.8"), b""" #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } """, [(b"1 1", b"1"), (b"1 2", b"0.5"), (b"0 0", b"")], ) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][1]) self.assertFalse(result[1])
def test_ONF(self): result = judge( GCC("c", "4.8"), b""" #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } """, [(b"1 1", b"1"), (b"0 0", b"")], {"iofilename": {"out": "out.txt"}}, ) self.assertEqual(result[0][0][0], Status.ONF) self.assertEqual(result[0][1][0], Status.RE) self.assertTrue(result[0][1][1][1]) self.assertFalse(result[1])
def test_TLE(self): result = judge( GCC("cpp", "4.8"), b""" #include <cstdio> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); while (true) ; } """, [(b"1 1", b"1"), (b"0 0", b"")], {"limit": {"time": 0.8}}, ) self.assertEqual(result[0][0][0], Status.TLE) self.assertEqual(result[0][1][0], Status.RE) self.assertAlmostEqual(result[0][0][2], 0.8, 0) self.assertLess(result[0][1][2], 0.8, 0) self.assertFalse(result[1])
def test_threads(self): t = time() result = judge( GCC("cpp", "4.8"), b""" int main() { while (true) ; } """, [(b"", b"")] * 3, {"limit": {"time": 5}, "threads": 2}, ) self.assertEqual(result[0][0][0], Status.TLE) self.assertEqual(result[0][1][0], Status.TLE) self.assertEqual(result[0][2][0], Status.TLE) self.assertAlmostEqual(result[0][0][2], 5, 0) self.assertAlmostEqual(result[0][1][2], 5, 0) self.assertAlmostEqual(result[0][2][2], 5, 0) self.assertFalse(result[1]) self.assertGreater(time() - t, 10)
def test_iofile(self): result = judge( GCC('c', '4.8'), b''' #include <stdio.h> int main() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } ''', [(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')], {'iofilename': { 'in': 'in.txt', 'out': 'out.txt' }}) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][1]) self.assertFalse(result[1])
def test_threads(self): t = time() result = judge( GCC('cpp', '4.8'), b''' int main() { while (true) ; } ''', [(b'', b'')] * 3, { 'limit': { 'time': 5 }, 'threads': 2 }) self.assertEqual(result[0][0][0], Status.TLE) self.assertEqual(result[0][1][0], Status.TLE) self.assertEqual(result[0][2][0], Status.TLE) self.assertAlmostEqual(result[0][0][2], 5, 0) self.assertAlmostEqual(result[0][1][2], 5, 0) self.assertAlmostEqual(result[0][2][2], 5, 0) self.assertFalse(result[1]) self.assertGreater(time() - t, 10)
def test_iofile(self): result = judge( GCC("c", "4.8"), b""" #include <stdio.h> int main() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int a, b; scanf("%d %d", &a, &b); printf("%d", a / b); return 0; } """, [(b"1 1", b"1"), (b"1 2", b"0.5"), (b"0 0", b"")], {"iofilename": {"in": "in.txt", "out": "out.txt"}}, ) self.assertEqual(result[0][0][0], Status.AC) self.assertEqual(result[0][1][0], Status.WA) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][1]) self.assertFalse(result[1])
def test_GCC(self): self.assertEqual(GCC(GCC.Language.c, 4.8).image, 'gcc:4.8') self.assertEqual(GCC(GCC.Language.c, '4.8').image, 'gcc:4.8') self.assertEqual(GCC(GCC.Language.c).source, GCC('c').source) self.assertEqual(GCC(GCC.Language.c).source, GCC('C').source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC('cpp').source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC('C++').source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC('c++').source) self.assertEqual(GCC(GCC.Language.go).source, GCC('go').source) self.assertEqual(GCC(GCC.Language.go).source, GCC('Go').source) self.assertEqual(GCC(GCC.Language.c).compile[0], 'gcc') self.assertEqual(GCC(GCC.Language.cpp).compile[0], 'g++') self.assertEqual(GCC(GCC.Language.go).compile[0], 'gccgo')
def test_GCC(self): self.assertEqual(GCC(GCC.Language.c, 4.8).image, "gcc:4.8") self.assertEqual(GCC(GCC.Language.c, "4.8").image, "gcc:4.8") self.assertEqual(GCC(GCC.Language.c).source, GCC("c").source) self.assertEqual(GCC(GCC.Language.c).source, GCC("C").source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC("cpp").source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC("C++").source) self.assertEqual(GCC(GCC.Language.cpp).source, GCC("c++").source) self.assertEqual(GCC(GCC.Language.go).source, GCC("go").source) self.assertEqual(GCC(GCC.Language.go).source, GCC("Go").source) self.assertEqual(GCC(GCC.Language.c).compile[0], "gcc") self.assertEqual(GCC(GCC.Language.cpp).compile[0], "g++") self.assertEqual(GCC(GCC.Language.go).compile[0], "gccgo")