day16.lisp (1825B)
1 (in-package #:adventofcode2022/test) 2 3 (define-constant +testdata-day16+ "Valve AA has flow rate=0; tunnels lead to valves DD, II, BB 4 Valve BB has flow rate=13; tunnels lead to valves CC, AA 5 Valve CC has flow rate=2; tunnels lead to valves DD, BB 6 Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE 7 Valve EE has flow rate=3; tunnels lead to valves FF, DD 8 Valve FF has flow rate=0; tunnels lead to valves EE, GG 9 Valve GG has flow rate=0; tunnels lead to valves FF, HH 10 Valve HH has flow rate=22; tunnel leads to valve GG 11 Valve II has flow rate=0; tunnels lead to valves AA, JJ 12 Valve JJ has flow rate=21; tunnel leads to valve II" 13 :test 'equal) 14 15 (def-test day16-find-shortest-path () 16 (let ((adventofcode2022/day16::*distance-cache* 17 (make-hash-table :test 'equal))) 18 (multiple-value-bind (start unopened-valves) 19 (adventofcode2022/day16::make-graph 20 (mapcar #'adventofcode2022/day16::parse-line 21 (str:lines +testdata-day16+))) 22 (loop for unopened-valve in unopened-valves 23 for valve-id = (adventofcode2022/day16::vid unopened-valve) 24 for path-length = (adventofcode2022/day16::find-shortest-path start unopened-valve) 25 for expected = (case valve-id 26 (:BB 1) 27 (:CC 2) 28 (:DD 1) 29 (:EE 2) 30 (:HH 5) 31 (:JJ 2) 32 (otherwise 0)) 33 do (is-true (= path-length expected)))))) 34 35 (def-test day16-task1 () 36 (is-true 37 (= 1651 38 (run-task 16 1 39 (make-string-input-stream +testdata-day16+))))) 40 41 (def-test day16-task2 () 42 (is-true 43 (= 1707 44 (run-task 16 2 45 (make-string-input-stream +testdata-day16+)))))