-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
56 lines (37 loc) · 1.23 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import time
import datetime
__test = True
__baseDir = os.path.dirname(__file__)
__testSet = [
[os.path.join(__baseDir, "INSERT TEST INPUT FILE NAME"), "INSERT EXPECTED SOLUTION"]
]
__inputFile = os.path.join(__baseDir, 'input.txt')
def solve(input):
solution = 0
### Write solution here ###
return solution
def test(testSet):
for i, [testInputFile, solution] in enumerate(testSet, 1):
try:
testInput = open(testInputFile, 'r')
except FileNotFoundError as e:
raise(e)
if solve(testInput) != solution:
raise RuntimeError(f'Test {i} failed!')
else:
yield f'Test {i} passed'
if __test:
__startTime = time.time()
for msg in test(__testSet):
print(msg)
__runTime = datetime.datetime.fromtimestamp(time.time()-__startTime).strftime('%S.%fs')
print(f'Tests completed succesfully in: {__runTime}\n{'='*45}')
try:
input = open(__inputFile, 'r')
except FileNotFoundError as e:
raise (e)
__startTime = time.time()
solution = solve(input)
__runTime = datetime.datetime.fromtimestamp(time.time()-__startTime).strftime('%S.%fs')
print(f'Solution for the puzzle: {solution}\nElapsed time: {__runTime}')