def run_specific_test(step, *args, **kwargs): t = split_specific_test_step(step) if t is None: return [] (testname, test) = t tester_class = tester_class_map[testname] global tester tester = tester_class(*args, **kwargs) print("Got %s" % str(tester)) for a in tester.tests(): if not hasattr(a, 'name'): a = Test(a[0], a[1], a[2]) print("Got %s" % (a.name)) if a.name == test: return tester.run_tests([a]) print("Failed to find test %s on %s" % (test, testname)) sys.exit(1)
def default(self, name, value, **kwargs): if self.is_valgrind: default = kwargs.get("valgrind", value) else: default = value return Test.default(self, name, default, **kwargs)
def __init__(self, *args): Test.__init__(self, *args) self.is_valgrind = False
".#... => #", ".#.#. => #", ".#.## => #", ".##.. => #", ".#### => #", "#.#.# => #", "#.### => #", "##.#. => #", "##.## => #", "###.. => #", "###.# => #", "####. => #", ] TESTS = [ Test(parse_initial_state, ("initial state: #..##....",), "#..##...."), Test(parse_initial_state, ("invalid initial state: #..##....",), None), Test(parse_rule, ("..#.. => .",), SpreadRule("..#..", False)), Test(parse_rule, (".##.# => #",), SpreadRule(".##.#", True)), Test(parse_rule, (".##.# <= #",), None), Test( parse_notes, (TEST_LINES[:4],), ( {SpreadRule("...##", True), SpreadRule("..#..", True)}, "#..#.#..##......###...###", ), ), Test(sum_planted_pots, parse_notes(TEST_LINES) + (20,), 325), ]
from common import Test, run_test_cases from .charge import power_level, power_square TESTS = [ Test(power_level, (3, 5, 8), 4), Test(power_level, (122, 79, 57), -5), Test(power_level, (217, 196, 39), 0), Test(power_level, (101, 153, 71), 4), Test(power_square, (300, 18, 3), (33, 45, 3)), Test(power_square, (300, 42, 3), (21, 61, 3)), Test(power_square, (300, 18), (90, 269, 16)), Test(power_square, (300, 42), (232, 251, 12)), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .polymer import react, reduction, best_reduction TESTS = [ Test(react, ("a", "A"), True), Test(react, ("A", "a"), True), Test(react, ("a", "a"), False), Test(react, ("A", "A"), False), Test(react, ("a", "b"), False), Test(react, ("a", "B"), False), Test(reduction, ("aA", ), 0), Test(reduction, ("abBA", ), 0), Test(reduction, ("abAB", ), 4), Test(reduction, ("aabAAB", ), 6), Test(reduction, ("dabAcCaCBAcCcaDA", ), 10), Test(reduction, ("dabAcCaCBAcCcaDA", {"a", "A"}), 6), Test(reduction, ("dabAcCaCBAcCcaDA", {"b", "B"}), 8), Test(reduction, ("dabAcCaCBAcCcaDA", {"c", "C"}), 4), Test(reduction, ("dabAcCaCBAcCcaDA", {"d", "D"}), 6), Test(best_reduction, ("dabAcCaCBAcCcaDA", ), 4) ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
"position=<10, -3> velocity=<-1, 1>", "position=< 5, 11> velocity=< 1, -2>", "position=< 4, 7> velocity=< 0, -1>", "position=< 8, -2> velocity=< 0, 1>", "position=<15, 0> velocity=<-2, 0>", "position=< 1, 6> velocity=< 1, 0>", "position=< 8, 9> velocity=< 0, -1>", "position=< 3, 3> velocity=<-1, 1>", "position=< 0, 5> velocity=< 0, -1>", "position=<-2, 2> velocity=< 2, 0>", "position=< 5, -2> velocity=< 1, 2>", "position=< 1, 4> velocity=< 2, 1>", "position=<-2, 7> velocity=< 2, -2>", "position=< 3, 6> velocity=<-1, -1>", "position=< 5, 0> velocity=< 1, 0>", "position=<-6, 0> velocity=< 2, 0>", "position=< 5, 9> velocity=< 1, -2>", "position=<14, 7> velocity=<-2, 0>", "position=<-3, 6> velocity=< 2, -1>", ] TESTS = [ Test(parse_point, (TEST_POINTS[0], ), Point(9, 1, Velocity(0, 2))), Test(parse_point, (TEST_POINTS[1], ), Point(7, 0, Velocity(-1, 0))), Test(message, ([parse_point(p) for p in TEST_POINTS], ), 3) ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .coordinates import ( Coordinate, Boundaries, parse_coordinate, manhattan_distance, find_boundaries, sizes, ) TEST_COORDINATES = ["1, 1", "1, 6", "8, 3", "3, 4", "5, 5", "8, 9"] TESTS = [ Test(parse_coordinate, (TEST_COORDINATES[0], ), Coordinate(1, 1)), Test(parse_coordinate, (TEST_COORDINATES[1], ), Coordinate(1, 6)), Test(parse_coordinate, (TEST_COORDINATES[2], ), Coordinate(8, 3)), Test(manhattan_distance, (Coordinate(0, 0), Coordinate(0, 3)), 3), Test(manhattan_distance, (Coordinate(0, 0), Coordinate(3, 0)), 3), Test(manhattan_distance, (Coordinate(0, 0), Coordinate(2, 3)), 5), Test( find_boundaries, ([parse_coordinate(c) for c in TEST_COORDINATES], ), Boundaries(1, 9, 1, 8), ), Test(sizes, ([parse_coordinate(c) for c in TEST_COORDINATES], 32), (17, 16)), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .steps import Requirement, parse_requirement, complete TEST_INSTRUCTIONS = [ "Step C must be finished before step A can begin.", "Step C must be finished before step F can begin.", "Step A must be finished before step B can begin.", "Step A must be finished before step D can begin.", "Step B must be finished before step E can begin.", "Step D must be finished before step E can begin.", "Step F must be finished before step E can begin.", ] TESTS = [ Test(parse_requirement, (TEST_INSTRUCTIONS[0],), Requirement("C", "A")), Test( complete, ([parse_requirement(r) for r in TEST_INSTRUCTIONS], 2, 0), ("CABFDE", 15), ), Test( complete, ([parse_requirement(r) for r in TEST_INSTRUCTIONS], 1, 0), ("CABDFE", 21), ), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
#!/usr/bin/env python # -*- coding: utf-8 -*- from common import Common, Test, Log a = Common() b = Test() #c = Log() d = Log('./log.log') b.hello() #c.log('123123123') d.log('1231ssssssss23123', 'error')
from common import Test, run_test_cases from .calibration import final_frequency, first_frequency_twice TESTS = [ Test(final_frequency, ([+1, -2, +3, +1], ), 3), Test(final_frequency, ([+1, +1, +1], ), 3), Test(final_frequency, ([+1, +1, -2], ), 0), Test(final_frequency, ([-1, -2, -3], ), -6), Test(first_frequency_twice, ([+1, -2, +3, +1], ), 2), Test(first_frequency_twice, ([+1, -1], ), 0), Test(first_frequency_twice, ([+3, +3, +4, -2, -4], ), 10), Test(first_frequency_twice, ([-6, +3, +8, +5, -6], ), 5), Test(first_frequency_twice, ([+7, +7, -2, -7, -4], ), 14), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .inventory import classify_candidate, checksum, common_letters_prototype TESTS = [ Test(classify_candidate, ("abcdef",), (0, 0)), Test(classify_candidate, ("bababc",), (1, 1)), Test(classify_candidate, ("abbcde",), (1, 0)), Test(classify_candidate, ("abcccd",), (0, 1)), Test(classify_candidate, ("aabcdd",), (1, 0)), Test(classify_candidate, ("abcdee",), (1, 0)), Test(classify_candidate, ("ababab",), (0, 1)), Test( checksum, (["abcdef", "bababc", "abbcde", "abcccd", "aabcdd", "abcdee", "ababab"],), 12, ), Test( common_letters_prototype, (["abcde", "fghij", "klmno", "pqrst", "fguij", "axcye", "wvxyz"],), "fgij", ), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .chocolate import score_after, recipes_before TESTS = [ Test(score_after, (9, 10, (3, 7)), "5158916779"), Test(score_after, (5, 10, (3, 7)), "0124515891"), Test(score_after, (18, 10, (3, 7)), "9251071085"), Test(score_after, (2018, 10, (3, 7)), "5941429882"), Test(recipes_before, ("51589", (3, 7)), 9), Test(recipes_before, ("01245", (3, 7)), 5), Test(recipes_before, ("92510", (3, 7)), 18), Test(recipes_before, ("59414", (3, 7)), 2018), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .license import make_tree, total_metadata, value TEST_TREE_DESCRIPTION = [2, 3, 0, 3, 10, 11, 12, 1, 1, 0, 1, 99, 2, 1, 1, 2] TESTS = [ Test(total_metadata, (make_tree([0, 3, 8, 9, 10]),), 27), Test(total_metadata, (make_tree([1, 2, 0, 1, 10, 11, 12]),), 33), Test(total_metadata, (make_tree([2, 1, 0, 1, 10, 0, 1, 11, 12]),), 33), Test( total_metadata, (make_tree([2, 3, 1, 1, 0, 1, 99, 2, 0, 3, 10, 11, 12, 1, 1, 2]),), 138, ), Test(total_metadata, (make_tree(TEST_TREE_DESCRIPTION),), 138), Test(value, (make_tree(TEST_TREE_DESCRIPTION),), 66), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .marbles import parse_game_setup, highest_score TESTS = [ Test(parse_game_setup, ("10 players; last marble is worth 1618 points", ), (10, 1618)), Test(highest_score, (9, 25), 32), Test(highest_score, (10, 1618), 8317), Test(highest_score, (13, 7999), 146373), Test(highest_score, (17, 1104), 2764), Test(highest_score, (21, 6111), 54718), Test(highest_score, (30, 5807), 37305), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
"[1518-11-02 00:50] wakes up", "[1518-11-03 00:05] Guard #10 begins shift", "[1518-11-03 00:24] falls asleep", "[1518-11-03 00:29] wakes up", "[1518-11-04 00:02] Guard #99 begins shift", "[1518-11-04 00:36] falls asleep", "[1518-11-04 00:46] wakes up", "[1518-11-05 00:03] Guard #99 begins shift", "[1518-11-05 00:45] falls asleep", "[1518-11-05 00:55] wakes up", ] TESTS = [ Test( parse_record, (TEST_RECORDS[0], ), Record(datetime(1518, 11, 1, 0, 0), 10, Action.BEGIN_SHIFT), ), Test( parse_record, (TEST_RECORDS[1], ), Record(datetime(1518, 11, 1, 0, 5), None, Action.FALL_ASLEEP), ), Test( parse_record, (TEST_RECORDS[2], ), Record(datetime(1518, 11, 1, 0, 25), None, Action.WAKE_UP), ), Test(strategy_1, (guard_stats([parse_record(r) for r in TEST_RECORDS]), ), 240), ]
"| | | | v |", "\-+-/ \-+--/", " \------/ ", ] TEST_MAP_LINES_PART_2 = [ "/>-<\ ", "| | ", "| /<+-\\", "| | | v", "\>+</ |", " | ^", " \<->/", ] TESTS = [ Test(next_turn, (Turn.LEFT, ), Turn.STRAIGHT), Test(next_turn, (Turn.STRAIGHT, ), Turn.RIGHT), Test(next_turn, (Turn.RIGHT, ), Turn.LEFT), Test(Direction.UP.apply_turn, (Turn.LEFT, ), Direction.LEFT), Test(Direction.UP.apply_turn, (Turn.STRAIGHT, ), Direction.UP), Test(Direction.UP.apply_turn, (Turn.RIGHT, ), Direction.RIGHT), Test(first_crash_location, parse_map(TEST_STRAIGHT_LINES), (0, 3)), Test(first_crash_location, parse_map(TEST_MAP_LINES_PART_1), (7, 3)), Test(last_cart_location, parse_map(TEST_MAP_LINES_PART_2), (6, 4)), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)
from common import Test, run_test_cases from .fabric import Claim, parse_claim, overlapping TEST_CLAIMS_DESCRIPTIONS = ["#1 @ 1,3: 4x4", "#2 @ 3,1: 4x4", "#3 @ 5,5: 2x2"] TESTS = [ Test(parse_claim, (TEST_CLAIMS_DESCRIPTIONS[0], ), Claim(1, 1, 3, 4, 4)), Test(parse_claim, (TEST_CLAIMS_DESCRIPTIONS[1], ), Claim(2, 3, 1, 4, 4)), Test(parse_claim, (TEST_CLAIMS_DESCRIPTIONS[2], ), Claim(3, 5, 5, 2, 2)), Test(overlapping, ([parse_claim(c) for c in TEST_CLAIMS_DESCRIPTIONS], 2), (4, {3})), ] def run(verbose: bool = False) -> None: run_test_cases(TESTS, verbose)