add test option
This commit is contained in:
parent
a0408e9873
commit
6348ae58a3
@ -4,12 +4,17 @@ BASE_PATH = os.path.dirname(os.path.dirname(__file__))
|
|||||||
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
|
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
|
||||||
|
|
||||||
|
|
||||||
def getInputLineAsArray(day, return_type=None):
|
def getInputLineAsArray(day, return_type=None, test=False):
|
||||||
"""
|
"""
|
||||||
get input for day x as array, each line representing one array entry
|
get input for day x as array, each line representing one array entry
|
||||||
when type is given, each entry will be converted to the specified type
|
when type is given, each entry will be converted to the specified type
|
||||||
"""
|
"""
|
||||||
with open(os.path.join(INPUTS_PATH, str(day)), "r") as f:
|
if test:
|
||||||
|
file = os.path.join(INPUTS_PATH, str(day) + "_test")
|
||||||
|
else:
|
||||||
|
file = os.path.join(INPUTS_PATH, str(day))
|
||||||
|
|
||||||
|
with open(file, "r") as f:
|
||||||
input_array = f.readlines()
|
input_array = f.readlines()
|
||||||
|
|
||||||
if return_type:
|
if return_type:
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
def printSolution(day, part, solution):
|
def printSolution(day, part, solution, test=False):
|
||||||
|
if test:
|
||||||
|
print("(TEST) ", end="")
|
||||||
|
|
||||||
print(f"Solution to day {day}, part {part}: {solution}")
|
print(f"Solution to day {day}, part {part}: {solution}")
|
||||||
|
|||||||
8
day01.py
8
day01.py
@ -1,14 +1,16 @@
|
|||||||
import aoclib
|
import aoclib
|
||||||
|
|
||||||
# my_input = [1721, 979, 366, 299, 675, 1456] # debug input
|
if 'TEST' not in globals():
|
||||||
my_input = aoclib.getInputLineAsArray(1, int)
|
TEST = False
|
||||||
|
|
||||||
|
my_input = aoclib.getInputLineAsArray(day=1, return_type=int, test=TEST)
|
||||||
|
|
||||||
globalBreak = False
|
globalBreak = False
|
||||||
while len(my_input) > 0:
|
while len(my_input) > 0:
|
||||||
try_value = my_input.pop()
|
try_value = my_input.pop()
|
||||||
for value in my_input:
|
for value in my_input:
|
||||||
if try_value + value == 2020:
|
if try_value + value == 2020:
|
||||||
aoclib.printSolution(1, 1, try_value * value)
|
aoclib.printSolution(1, 1, try_value * value, test=TEST)
|
||||||
globalBreak = True
|
globalBreak = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import aoclib
|
import aoclib
|
||||||
|
|
||||||
# my_input = [1721, 979, 366, 299, 675, 1456] # debug input
|
if 'TEST' not in globals():
|
||||||
my_input = aoclib.getInputLineAsArray(1, int)
|
TEST = False
|
||||||
|
|
||||||
|
my_input = aoclib.getInputLineAsArray(1, int, test=TEST)
|
||||||
|
|
||||||
globalBreak = False
|
globalBreak = False
|
||||||
while len(my_input) > 0:
|
while len(my_input) > 0:
|
||||||
@ -11,7 +13,7 @@ while len(my_input) > 0:
|
|||||||
if value_1 == value_2:
|
if value_1 == value_2:
|
||||||
continue
|
continue
|
||||||
if try_value + value_1 + value_2 == 2020:
|
if try_value + value_1 + value_2 == 2020:
|
||||||
aoclib.printSolution(1, 2, try_value * value_1 * value_2)
|
aoclib.printSolution(1, 2, try_value * value_1 * value_2, test=TEST)
|
||||||
globalBreak = True
|
globalBreak = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
6
inputs/1_test
Normal file
6
inputs/1_test
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
1721
|
||||||
|
979
|
||||||
|
366
|
||||||
|
299
|
||||||
|
675
|
||||||
|
1456
|
||||||
22
main.py
Normal file → Executable file
22
main.py
Normal file → Executable file
@ -1,9 +1,29 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
import aoclib
|
import aoclib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
argument_parser = argparse.ArgumentParser()
|
||||||
|
argument_parser.add_argument("day", help="specify day to process; leave empty for ALL days")
|
||||||
|
argument_parser.add_argument("-t", "--test", help="also run test cases", action="store_true", default=False)
|
||||||
|
argument_parser.add_argument("-d", "--debug", help="turn on debug mode", action="store_true", default=False)
|
||||||
|
flags = argument_parser.parse_args()
|
||||||
|
|
||||||
|
DEBUG = flags.debug
|
||||||
|
|
||||||
|
day = ""
|
||||||
|
if flags.day:
|
||||||
|
day = "%02d" % int(flags.day)
|
||||||
|
|
||||||
for _, _, files in os.walk(aoclib.BASE_PATH):
|
for _, _, files in os.walk(aoclib.BASE_PATH):
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.startswith('day') and f.endswith('.py'):
|
if f.startswith('day' + day) and f.endswith('.py'):
|
||||||
|
if flags.test:
|
||||||
|
TEST = True
|
||||||
|
exec(open(f).read())
|
||||||
|
|
||||||
|
TEST = False
|
||||||
exec(open(f).read())
|
exec(open(f).read())
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user