Skip to content

Commit 57a4200

Browse files
committed
Add support for more languages, set compiler flags
- Add support for Ruby and Haskell - Set compiler flags as done by online judges - Fix error code for TLE
1 parent 9d6aa58 commit 57a4200

File tree

4 files changed

+67
-105
lines changed

4 files changed

+67
-105
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ A command line tool to run your code against sample test cases. Without leaving
2020
+ C++
2121
+ Python
2222
+ Java
23+
+ Ruby
24+
+ Haskell
2325

2426
#### Installation
2527
##### Build from source

README.rst

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
|contributions welcome| |Open Source Love| |MIT Licence|
2-
3-
.. raw:: html
4-
5-
<h1 align="center">
6-
7-
.. raw:: html
8-
9-
<img src="https://github.com/coderick14/ACedIt/blob/master/images/logo.png" width="500"/><br/>
10-
11-
.. raw:: html
12-
13-
</h1>
14-
151
A command line tool to run your code against sample test cases. Without leaving the terminal :)
162

17-
Demo
18-
^^^^
19-
20-
.. figure:: https://github.com/coderick14/ACedIt/blob/master/images/demo.gif
21-
:alt: Simple demo of how ACedIt works
22-
233
Supported sites
244
^^^^^^^^^^^^^^^
255

@@ -35,6 +15,8 @@ Supported languages
3515
- C++
3616
- Python
3717
- Java
18+
- Ruby
19+
- Haskell
3820

3921
Installation
4022
^^^^^^^^^^^^
@@ -136,11 +118,4 @@ Note :
136118

137119
- The working directory structure mentioned in the previous versions is no longer required and supported.
138120

139-
- There might be some issues with Spoj, as they have widely varying DOM trees for different problems. Feel free to contribute on this. Or anything else that you can come up with :)
140-
141-
.. |contributions welcome| image:: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat
142-
:target: https://github.com/coderick14/ACedIt/issues
143-
.. |Open Source Love| image:: https://badges.frapsoft.com/os/v2/open-source.svg?v=103
144-
:target: https://github.com/coderick14/ACedIt/
145-
.. |MIT Licence| image:: https://badges.frapsoft.com/os/mit/mit.svg?v=103
146-
:target: https://opensource.org/licenses/mit-license.php
121+
- There might be some issues with Spoj, as they have widely varying DOM trees for different problems. Feel free to contribute on this. Or anything else that you can come up with :)

acedit/util.py

+61-76
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def run_solution(args):
286286
print 'ERROR : No such file'
287287
sys.exit(0)
288288

289-
problem_code = args['problem'] if args['problem'] else problem
289+
problem_code = args['problem'] if args['problem'] else basename
290290
contest_code = '' if args['site'] == 'spoj' else args['contest']
291291

292292
testcases_path = os.path.join(Utilities.cache_dir, args[
@@ -296,89 +296,74 @@ def run_solution(args):
296296
num_cases = len(os.listdir(testcases_path)) / 2
297297
results, expected_outputs, user_outputs = [], [], []
298298

299-
if extension == 'py':
300-
301-
for i in xrange(num_cases):
302-
status = os.system('cat ' + os.path.join(testcases_path, 'Input' + str(
303-
i)) + ' | timeout 3s python \'' + problem_path + '.py\' > temp_output' + str(i))
304-
if status == 124:
305-
# Time Limit Exceeded
306-
results += [Utilities.colors['BOLD'] +
307-
Utilities.colors['YELLOW'] + 'TLE' + Utilities.colors['ENDC']]
308-
309-
elif status == 0:
310-
# Ran successfully
311-
with open('temp_output' + str(i), 'r') as temp_handler, open(os.path.join(testcases_path, 'Output' + str(i)), 'r') as out_handler:
312-
expected_output = out_handler.read().strip().split('\n')
313-
user_output = temp_handler.read().strip().split('\n')
314-
315-
expected_output = '\n'.join(
316-
[line.strip() for line in expected_output])
317-
user_output = '\n'.join(
318-
[line.strip() for line in user_output])
319-
320-
expected_outputs += [expected_output]
321-
user_outputs += [user_output]
322-
323-
if expected_output == user_output:
324-
# All Correct
325-
results += [Utilities.colors['BOLD'] + Utilities.colors[
326-
'GREEN'] + 'AC' + Utilities.colors['ENDC']]
327-
else:
328-
# Wrong Answer
329-
results += [Utilities.colors['BOLD'] +
330-
Utilities.colors['RED'] + 'WA' + Utilities.colors['ENDC']]
331-
332-
else:
333-
# Runtime Error
334-
results += [Utilities.colors['BOLD'] +
335-
Utilities.colors['RED'] + 'RTE' + Utilities.colors['ENDC']]
336-
337-
elif extension in ['c', 'cpp', 'java']:
338-
339-
compiler = {'c': 'gcc', 'cpp': 'g++', 'java': 'javac -d .'}[extension]
340-
execute_command = {'c': './a.out', 'cpp': './a.out', 'java': 'java ' + basename}[extension]
341-
compile_status = os.system(
342-
compiler + ' \'' + problem_path + '.' + extension + '\'')
299+
if extension in ['c', 'cpp', 'java', 'py', 'hs', 'rb']:
300+
301+
# Compiler flags taken from http://codeforces.com/blog/entry/79
302+
compiler = {
303+
'hs': 'ghc --make -O -dynamic -o ' + basename,
304+
'py': None,
305+
'rb': None,
306+
'c': 'gcc -static -DONLINE_JUDGE -fno-asm -lm -s -O2 -o ' + basename,
307+
'cpp': 'g++ -static -DONLINE_JUDGE -lm -s -x c++ -O2 -std=c++14 -o ' + basename,
308+
'java': 'javac -d .'
309+
}[extension]
310+
311+
execute_command = {
312+
'py': 'python \'' + problem_path + '.' + extension + '\'',
313+
'rb': 'ruby \'' + problem_path + '.' + extension + '\'',
314+
'hs': './' + basename,
315+
'c': './' + basename,
316+
'cpp': './' + basename,
317+
'java': 'java -DONLINE_JUDGE=true -Duser.language=en -Duser.region=US -Duser.variant=US ' + basename
318+
}[extension]
319+
320+
if compiler is None:
321+
compile_status = 0
322+
else:
323+
compile_status = os.system(
324+
compiler + ' \'' + problem_path + '.' + extension + '\'')
343325

344326
if compile_status == 0:
345327

346328
# Compiled successfully
347329
for i in xrange(num_cases):
348330
status = os.system('timeout 2s ' + execute_command + ' < ' + os.path.join(
349331
testcases_path, 'Input' + str(i)) + ' > temp_output' + str(i))
350-
if status == 124:
351-
# Time Limit Exceeded
352-
results += [Utilities.colors['BOLD'] + Utilities.colors[
353-
'YELLOW'] + 'TLE' + Utilities.colors['ENDC']]
354-
355-
elif status == 0:
356-
# Ran successfully
357-
with open('temp_output' + str(i), 'r') as temp_handler, open(os.path.join(testcases_path, 'Output' + str(i)), 'r') as out_handler:
358-
expected_output = out_handler.read().strip().split('\n')
359-
user_output = temp_handler.read().strip().split('\n')
360-
361-
expected_output = '\n'.join(
362-
[line.strip() for line in expected_output])
363-
user_output = '\n'.join(
364-
[line.strip() for line in user_output])
365-
366-
expected_outputs += [expected_output]
367-
user_outputs += [user_output]
368-
369-
if expected_output == user_output:
370-
# All Correct
371-
results += [Utilities.colors['BOLD'] + Utilities.colors[
372-
'GREEN'] + 'AC' + Utilities.colors['ENDC']]
373-
else:
374-
# Wrong Answer
332+
333+
with open(os.path.join(testcases_path, 'Output' + str(i)), 'r') as out_handler:
334+
expected_output = out_handler.read().strip().split('\n')
335+
expected_output = '\n'.join(
336+
[line.strip() for line in expected_output])
337+
expected_outputs += [expected_output]
338+
339+
if status == 31744:
340+
# Time Limit Exceeded
375341
results += [Utilities.colors['BOLD'] + Utilities.colors[
376-
'RED'] + 'WA' + Utilities.colors['ENDC']]
342+
'YELLOW'] + 'TLE' + Utilities.colors['ENDC']]
343+
user_outputs += ['']
344+
345+
elif status == 0:
346+
# Ran successfully
347+
with open('temp_output' + str(i), 'r') as temp_handler:
348+
user_output = temp_handler.read().strip().split('\n')
349+
user_output = '\n'.join(
350+
[line.strip() for line in user_output])
351+
user_outputs += [user_output]
352+
353+
if expected_output == user_output:
354+
# All Correct
355+
results += [Utilities.colors['BOLD'] + Utilities.colors[
356+
'GREEN'] + 'AC' + Utilities.colors['ENDC']]
357+
else:
358+
# Wrong Answer
359+
results += [Utilities.colors['BOLD'] + Utilities.colors[
360+
'RED'] + 'WA' + Utilities.colors['ENDC']]
377361

378-
else:
379-
# Runtime Error
380-
results += [Utilities.colors['BOLD'] +
381-
Utilities.colors['RED'] + 'RTE' + Utilities.colors['ENDC']]
362+
else:
363+
# Runtime Error
364+
results += [Utilities.colors['BOLD'] +
365+
Utilities.colors['RED'] + 'RTE' + Utilities.colors['ENDC']]
366+
user_outputs += ['']
382367
else:
383368
# Compilation error occurred
384369
message = Utilities.colors['BOLD'] + Utilities.colors[
@@ -387,7 +372,7 @@ def run_solution(args):
387372
sys.exit(0)
388373

389374
else:
390-
print 'Supports only C, C++, Python and Java as of now.'
375+
print 'Supports only C, C++, Python, Java, Ruby and Haskell as of now.'
391376
sys.exit(0)
392377

393378
from terminaltables import AsciiTable

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
packages=['acedit'],
2424

25-
version='1.1.0',
25+
version='1.1.1',
2626

2727
description='Download and test against sample test cases from any competitive programming website',
2828

0 commit comments

Comments
 (0)