def test_callback(self): def compiling_callback(code, err): self.assertFalse(code) self.assertFalse(err) def judging_callback(id, status, duration): statuses = ['AC', 'WA', 'RE'] self.assertEqual(status, statuses[id]) result = judge({'image': 'gcc:4.8', 'source': 'a.c', 'compile': 'gcc a.c', 'judge': '%s/a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' long long a, b;''\n' r' scanf("%lld %lld", &a, &b);''\n' r' printf("%d\n", a / b);''\n' r' return 0;''\n' r'}''\n', [('1 1', '1'), ('1 2', '0.5'), ('1 0', '')], callback={'compiling': compiling_callback, 'judging': judging_callback}) self.assertEqual(result[0][0][0], 'AC') self.assertEqual(result[0][1][0], 'WA') self.assertEqual(result[0][2][0], '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_processor_dict(self): result = judge( ("Python", {"version": "3"}), b"print('Hello, world!')", [(b"", b"Hello, world!")], ) self.assertEqual(result[0][0][0], Status.AC)
def test_processor_tuple(self): result = judge( ("Python", ("3",)), b"print('Hello, world!')", [(b"", b"Hello, world!")], ) self.assertEqual(result[0][0][0], Status.AC)
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_pypy3(self): result = judge( PyPy(3), b'a, b = [int(i) for i in input().split()]; print(a / b)', [(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')]) self.assertEqual(result[0][0][0], Status.WA) self.assertEqual(result[0][1][0], Status.AC) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][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_CE(self): result = judge(Python('3'), b'import', [(b'', b''), (b'', b'')]) self.assertEqual(result[0][0][0], Status.CE) self.assertEqual(result[0][1][0], Status.CE) self.assertTrue(result[1]) self.assertFalse(result[0][0][1][0]) self.assertFalse(result[0][0][1][1]) self.assertFalse(result[0][1][1][0]) self.assertFalse(result[0][1][1][1])
def test_CE(self): result = judge(Python("3"), b"import", [(b"", b""), (b"", b"")]) self.assertEqual(result[0][0][0], Status.CE) self.assertEqual(result[0][1][0], Status.CE) self.assertTrue(result[1]) self.assertFalse(result[0][0][1][0]) self.assertFalse(result[0][0][1][1]) self.assertFalse(result[0][1][1][0]) self.assertFalse(result[0][1][1][1])
def test_python2(self): result = judge( Python('2'), b'a, b = [int(i) for i in raw_input().split()]; print a / b', [(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])
def test_pypy3(self): result = judge( PyPy(3), b"a, b = [int(i) for i in input().split()]; print(a / b)", [(b"1 1", b"1"), (b"1 2", b"0.5"), (b"0 0", b"")], ) self.assertEqual(result[0][0][0], Status.WA) self.assertEqual(result[0][1][0], Status.AC) self.assertEqual(result[0][2][0], Status.RE) self.assertTrue(result[0][2][1][1])
def test_python2(self): result = judge( Python("2"), b"a, b = [int(i) for i in raw_input().split()]; print a / b", [(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])
def test_openjdk(self): result = judge( OpenJDK(), b''' public class Main { public static void main(String[] args) { System.out.println("Hello, world!"); } } ''', [(b'', b'Hello, world!')]) 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_go(self): result = judge( Go(1), br''' package main import "fmt" func main() { fmt.Printf("hello, world\n") } ''', [(b'', b'hello, world')]) self.assertEqual(result[0][0][0], Status.AC)
def test_vb(self): result = judge( Mono(Mono.Language.vb), b''' Imports System Module HelloWorld Sub Main() Console.WriteLine("Hello World!") End Sub End Module ''', [(b'', b'Hello World!')]) self.assertEqual(result[0][0][0], Status.AC)
def test_csharp(self): result = judge( Mono(Mono.Language.csharp), b''' using System; public class HelloWorld { public static void Main(string[] args) { Console.WriteLine ("Hello Mono World"); } } ''', [(b'', b'Hello Mono World')]) self.assertEqual(result[0][0][0], Status.AC)
def test_go(self): result = judge( Go(1), br""" package main import "fmt" func main() { fmt.Printf("hello, world\n") } """, [(b"", b"hello, world")], ) self.assertEqual(result[0][0][0], Status.AC)
def test_tle(self): result = judge({'image': 'gcc:4.8', 'source': 'a.cpp', 'compile': 'g++ a.cpp', 'judge': '%s/a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' while (true)''\n' r' ;''\n' r'}''\n', [('', '')], 0.05) self.assertEqual(result[0][0][0], 'TLE') self.assertAlmostEqual(result[0][0][1], 0.05, 1) self.assertFalse(result[1])
def test_ce(self): result = judge({'image': 'gcc:4.8', 'source': 'a.cpp', 'compile': 'gcc a.cpp', 'judge': '%s/a.out'}, r'#include <iostream>''\n' r'int main() {''\n' r' long long a, b;''\n' r' std::cin >> a >> b;''\n' r' std::cout << a + b;''\n' r' return 0;''\n' r'}''\n', [('1 2', '3')]) self.assertEqual(result[0][0][0], 'CE') self.assertTrue(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_before_judging(self): result = judge({'image': 'gcc:4.8', 'source': 'a.c', 'compile': 'gcc a.c', 'before_judging': 'rm {}/a.out', 'judge': '%s/a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' long long a, b;''\n' r' scanf("%lld %lld", &a, &b);''\n' r' printf("%d\n", a + b);''\n' r' return 0;''\n' r'}''\n', [('1 2', '3')]) self.assertEqual(result[0][0][0], 'RE') self.assertFalse(result[1])
def test_split(self): t = time() result = judge({'image': 'gcc:4.8', 'source': 'a.cpp', 'compile': 'g++ a.cpp', 'judge': '%s/a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' while (true)''\n' r' ;''\n' r'}''\n', [('', '')] * 3, 3, split=2) self.assertEqual(result[0][0][0], 'TLE') self.assertEqual(result[0][1][0], 'TLE') self.assertEqual(result[0][2][0], 'TLE') self.assertGreater(time() - t, 6) self.assertFalse(result[1])
def test_after_judging(self): result = judge({'image': 'gcc:4.8', 'source': 'a.c', 'compile': 'gcc a.c', 'judge': '%s/a.out', 'after_judging': 'rm a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' freopen("a.out", "w", stdout);''\n' r' long long a, b;''\n' r' scanf("%lld %lld", &a, &b);''\n' r' printf("%d\n", a + b);''\n' r' return 0;''\n' r'}''\n', [('1 2', '3')], iofile=(None, 'a.out')) self.assertEqual(result[0][0][0], 'ONF') 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_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_judge(self): result = judge({'image': 'gcc:4.8', 'source': 'a.c', 'compile': 'gcc a.c', 'judge': '%s/a.out'}, r'#include <stdio.h>''\n' r'int main() {''\n' r' long long a, b;''\n' r' scanf("%lld %lld", &a, &b);''\n' r' printf("%d\n", a / b);''\n' r' return 0;''\n' r'}''\n', [('1 1', '1'), ('1 2', '0.5'), ('1 0', '')]) self.assertEqual(result[0][0][0], 'AC') self.assertEqual(result[0][1][0], 'WA') self.assertEqual(result[0][2][0], 'RE') 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_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])