Skip to content

Commit

Permalink
day25: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 25, 2023
1 parent d782efc commit b39914a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions day25/day25.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

INPUT_SMALL = "day25/input-small.txt"
INPUT = "day25/input.txt"
SHOW_GRAPH = False


@dataclass
Expand Down Expand Up @@ -38,7 +39,7 @@ def show_graph(graph: nx.Graph) -> None:
plt.show()


def graph_nodes(connections: list[Connection]) -> int:
def solve_nodes(connections: list[Connection]) -> int:
"""Graphs the modules"""
G = nx.Graph()

Expand All @@ -51,16 +52,16 @@ def graph_nodes(connections: list[Connection]) -> int:
G.add_node(node_name)
if node_name != connection.src:
G.add_edge(connection.src, node_name)

show_graph(G)
if SHOW_GRAPH:
show_graph(G)
cut_value, partition = nx.stoer_wagner(G)
print(f"num_cuts: {cut_value}")
return len(partition[0]) * len(partition[1])


def main() -> None:
conns = get_data(INPUT)
result = graph_nodes(conns)
result = solve_nodes(conns)
print(result)


Expand Down
Empty file removed day25/lib/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions day25/tests/test_day25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from day25.day25 import INPUT_SMALL, Connection, get_data, parse_connection, solve_nodes


def test_get_data() -> None:
conns: list[Connection] = get_data(INPUT_SMALL)
assert len(conns) == 13
assert conns[0].src == "jqt"


def test_parse_connection() -> None:
conn: Connection = parse_connection("zmx: vfl mgb tmr bsn")
assert conn.src == "zmx"
assert set(conn.dests) == {"vfl", "mgb", "tmr", "bsn"}


def test_day25() -> None:
conns: list[Connection] = get_data(INPUT_SMALL)
assert solve_nodes(conns) == 54

0 comments on commit b39914a

Please sign in to comment.