(defpackage :aoc/2024/09/tests (:use :cl :aoc :aoc/tests :aoc/2024/tests :parachute :aoc/2024/09)) (in-package :aoc/2024/09/tests) (define-test suite-2024-09 ;:parent suite-2024 ) (define-test test-blocks-to-fs :parent suite-2024-09 (let ((fs sample-data)) (is equalp (make-inode :id 0 :start 0 :length 2) (nth 0 fs)) (is equalp (make-freespace :start 2 :length 3) (nth 1 fs)) (is equalp (make-inode :id 1 :start 5 :length 3) (nth 2 fs)) (is equalp (make-freespace :start 8 :length 3) (nth 3 fs)))) (define-test test-compact-fs :parent suite-2024-09 ;; last block fits exactly in first free space (is equalp (list (make-inode :id 0 :start 0 :length 2) (make-inode :id 1 :start 2 :length 2)) (fs-compact-step (list (make-inode :id 0 :start 0 :length 2) (make-freespace :start 2 :length 2) (make-inode :id 1 :start 4 :length 2) ))) ;; last block bigger than first free space (is equalp (list (make-inode :id 0 :start 0 :length 2) (make-inode :id 2 :start 2 :length 2) (make-inode :id 1 :start 4 :length 2) (make-freespace :start 6 :length 2) (make-inode :id 2 :start 8 :length 2)) (fs-compact-step (list (make-inode :id 0 :start 0 :length 2) (make-freespace :start 2 :length 2) (make-inode :id 1 :start 4 :length 2) (make-freespace :start 6 :length 2) (make-inode :id 2 :start 8 :length 4) ))) ;; last block smaller than first free space (is equalp (list (make-inode :id 0 :start 0 :length 2) (make-inode :id 2 :start 2 :length 2) (make-freespace :start 4 :length 2) (make-inode :id 1 :start 6 :length 2) ) (fs-compact-step (list (make-inode :id 0 :start 0 :length 2) (make-freespace :start 2 :length 4) (make-inode :id 1 :start 6 :length 2) (make-freespace :start 8 :length 2) (make-inode :id 2 :start 10 :length 2) ))) ) (define-test+run test-part1 :parent suite-2024-09 (true (equal "1928" (part1 sample-data)))) (define-test+run test-part2 :parent suite-2024-09 (true (equal "2858" (part2 sample-data))))