def test_disjoint_sets_have_no_intersection():
    wire1 = WireStub(set())
    wire2 = WireStub(set())

    wire1.points_visited.add(Coord(1, 2))
    wire2.points_visited.add(Coord(2, 3))

    with pytest.raises(IntersectionNotFoundError):
        find_closest_intersection(wire1, wire2)
def test_actually_finds_smallest_intersection():
    wire1 = WireStub(set([Coord(0, 0), Coord(2, 3), Coord(1, 20), Coord(10, 0)]))
    wire2 = WireStub(set([Coord(0, 0), Coord(2, 3), Coord(10, 0), Coord(1, 20)]))

    assert find_closest_intersection(wire1, wire2) == Coord(2, 3)
def test_if_only_00_is_common_have_no_intersection():
    wire1 = WireStub(set([Coord(0, 0)]))
    wire2 = WireStub(set([Coord(0, 0)]))

    with pytest.raises(IntersectionNotFoundError):
        find_closest_intersection(wire1, wire2)
def test_equal_one_item_sets_intersect_at_that_item():
    wire1 = WireStub(set([Coord(1, 2)]))
    wire2 = WireStub(set([Coord(1, 2)]))

    assert find_closest_intersection(wire1, wire2) == Coord(1, 2)
def test_empty_sets_have_no_intersection():
    wire1 = WireStub(set())
    wire2 = WireStub(set())

    with pytest.raises(IntersectionNotFoundError):
        find_closest_intersection(wire1, wire2)
Esempio n. 6
0
from helpers import get_data
from intersection_finder import find_closest_intersection, find_shortest_intersection
from wire_reader import WireReader

lines = [line.split(',') for line in get_data(day=3).split('\n')]

wire1 = WireReader(lines[0])
wire2 = WireReader(lines[1])

smallest_intersection = find_closest_intersection(wire1, wire2)

print(f"The smallest intersection is at {smallest_intersection} with a distance of {smallest_intersection.manhattan}")

shortest_intersection, total_steps = find_shortest_intersection(wire1, wire2)

print(f"The shortest intersection is at {shortest_intersection} with a step count of {total_steps}")