aoc-cl/tests/2024/day02-test.lisp

42 lines
1.4 KiB
Common Lisp
Raw Permalink Normal View History

2024-12-02 08:53:49 +01:00
(defpackage :aoc/2024/02/tests
(:use :cl :aoc :aoc/tests :aoc/2024/tests :parachute :aoc/2024/02))
(in-package :aoc/2024/02/tests)
(define-test suite-2024-02
;:parent suite-2024
)
(define-test+run test-deltas
:parent suite-2024-02
(true (equalp '(1 1 1) (deltas '(1 2 3 4)))))
(define-test+run test-safe-levels
:parent suite-2024-02
(true (safe-levels '(7 6 4 2 1))) ; Safe because the levels are all decreasing by 1 or 2.
(false (safe-levels '(1 2 7 8 9))) ; Unsafe because 2 7 is an increase of 5.
(false (safe-levels '(9 7 6 2 1))) ; Unsafe because 6 2 is a decrease of 4.
(false (safe-levels '(1 3 2 4 5))) ; Unsafe because 1 3 is increasing but 3 2 is decreasing.
(false (safe-levels '(8 6 4 4 1))) ; Unsafe because 4 4 is neither an increase or a decrease.
(true (safe-levels '(1 3 6 7 9))) ; Safe because the levels are all increasing by 1, 2, or 3.
)
(define-test+run test-safe-levels-with-dampener
:parent suite-2024-02
(true (safe-levels-with-dampener '(7 6 4 2 1)))
(false (safe-levels-with-dampener '(1 2 7 8 9)))
(false (safe-levels-with-dampener '(9 7 6 2 1)))
(true (safe-levels-with-dampener '(1 3 2 4 5)))
(true (safe-levels-with-dampener '(8 6 4 4 1)))
(true (safe-levels-with-dampener '(1 3 6 7 9)))
)
(define-test+run test-part1
:parent suite-2024-02
(true (equalp 2 (part1 sample-data))))
(define-test+run test-part2
:parent suite-2024-02
(true (equalp 31 (part2 sample-data))))