Skip to content

Commit ac06fea

Browse files
committed
TLE added to test solution
1 parent 2e276ab commit ac06fea

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

Diff for: data/cpp_template_info.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Problem Name : $%PROBLEM_NAME%$
66
* Problem Limit : $%TIMELIMIT%$ , $%MEMORYLIMIT%$
77
* Problem Url : $%PROBLEM_URL%$
8-
* @genarated by ai-virtual-assistant
8+
* @genarated by : ai-virtual-assistant
99
**/
1010

1111
#include<bits/stdc++.h>

Diff for: data/py_template_info.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
Problem Url : $%PROBLEM_URL%$
66
Problem Limit : $%TIMELIMIT%$ , $%MEMORYLIMIT%$
77
Problem Url : $%PROBLEM_URL%$
8-
@genarated by ai-virtual-assistant
8+
@genarated by : ai-virtual-assistant
99

1010
"""

Diff for: system/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__email__ = '[email protected]'
55
__license__ = 'MIT License'
66
__url__ = 'https://github.com/Saurav-Paul/AI-virtual-assistant-python'
7-
__version_info__ = (1, 0, 1, 'alpha', 1)
7+
__version_info__ = (1, 0, 2, 'alpha', 1)
88
__version__ = '.'.join(map(str, __version_info__[:3]))
99
__description__ = 'CLI virtual assitant for competitive programming'
1010

Diff for: tools/OJ/cp.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import webbrowser
44
import subprocess
55
import json
6+
from threading import Timer
67
from termcolor import colored as clr , cprint
78
import time
89
from itertools import zip_longest
@@ -280,8 +281,34 @@ def different(self,value,output,expected,case):
280281
# tle = True
281282
# return (result,tle)
282283

284+
def sub_process(self,cmd,value) :
283285

284-
def sub_process(self,cmd,value):
286+
t = time.time()
287+
288+
tle = False
289+
kill = lambda process: process.kill()
290+
x = subprocess.Popen(
291+
cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
292+
my_timer = Timer(self.TLE, kill, [x])
293+
294+
try:
295+
my_timer.start()
296+
with x.stdin as f:
297+
f.write(value.encode())
298+
result = (x.communicate()[0]).decode('utf-8')
299+
finally:
300+
my_timer.cancel()
301+
pass
302+
303+
t = time.time() - t
304+
305+
if(t >= self.TLE) :
306+
tle = True
307+
308+
return (result,tle)
309+
310+
311+
def sub_process_old(self,cmd,value):
285312

286313
x = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
287314
with x.stdin as f:
@@ -347,7 +374,7 @@ def test(self,file_name,show=False):
347374
pt='-'*20+file_name+'-'*20
348375
cprint(pt,'magenta')
349376
pt = (' '*17+"...Testing...")
350-
cprint(pt,'blue')
377+
cprint(pt,'cyan')
351378
print()
352379

353380
case_folder = 'testcases'
@@ -388,7 +415,7 @@ def test(self,file_name,show=False):
388415
t = time.time() - t
389416
t = '{:.4f}'.format(t)
390417
pt = (f' # Compilation time {t} s')
391-
cprint(pt,'blue')
418+
cprint(pt,'cyan')
392419
passed = 0
393420
failed = 0
394421
test_files =[]
@@ -426,6 +453,8 @@ def test(self,file_name,show=False):
426453
with open(os.path.join(file_path,file),'r') as f:
427454
value = f.read()
428455
t = time.time()
456+
print()
457+
cprint(' * '+ext[0],'yellow')
429458
if type == 'cpp':
430459
result = self.sub_process(['./test.out'],value)
431460
elif type =='py':
@@ -442,8 +471,6 @@ def test(self,file_name,show=False):
442471
# t = '{:.4}'.format(t)
443472
t = f'{t:.4f}'
444473
# print('code :\n',result)
445-
print()
446-
cprint(' * '+ext[0],'yellow')
447474
cprint(' * Time : ','cyan',end='')
448475
if tle :
449476
cprint('TLE','red')

0 commit comments

Comments
 (0)