advent-of-code-2024

My solutions to AoC 2024
Log | Files | Refs

commit e5bbdca6d8fff8576b98fcbe5cb98a9167d20a59
parent 35dfaacf7838e916e7bebf9a02c17488493785b6
Author: Lukas Henkel <lh@entf.net>
Date:   Tue,  3 Dec 2024 22:14:24 +0100

Fix tests

Diffstat:
Msrc/day-2.lisp | 4+++-
Msrc/main.lisp | 32++++++++++++++++----------------
Mt/day-1.lisp | 3++-
Mt/day-2.lisp | 9+++++----
Mt/day-3.lisp | 3++-
5 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/day-2.lisp b/src/day-2.lisp @@ -1,6 +1,8 @@ (defpackage #:aoc/day-2 (:use #:cl #:aoc/utils) - (:export #:day-2)) + (:export + #:report-safe-p + #:day-2)) (in-package #:aoc/day-2) (defun report-safe-p (report &key direction allow-skip) diff --git a/src/main.lisp b/src/main.lisp @@ -91,34 +91,34 @@ :value *cookie* :domain ".adventofcode.com")))) input-pathname)) - (values - (unless (probe-file source-pathname) - (with-open-file (stream source-pathname :direction :output) - (let ((fun (make-symbol (format nil "DAY-~A" day))) - (package (make-symbol (format nil "AOC/DAY-~A" day))) - (*print-case* :downcase)) + (let ((package (make-symbol (format nil "AOC/DAY-~A" day))) + (test-package (make-symbol (format nil "AOC-TEST/DAY-~A" day))) + (fun (make-symbol (format nil "DAY-~A" day))) + (*print-case* :downcase)) + (values + (unless (probe-file source-pathname) + (with-open-file (stream source-pathname :direction :output) (format stream "~S~%~S~%~%(defun ~A (input)~% )" `(defpackage ,package (:use #:cl #:aoc/utils) (:export ,fun)) `(in-package ,package) - fun))) - ;; return function, makes it easy to jump into the file from Emacs - (day-fun day)) - (unless (probe-file test-pathname) - (let ((package (make-symbol (format nil "AOC-TEST/DAY-~A" day))) - (*print-case* :downcase)) + fun)) + ;; return function, makes it easy to jump into the file from Emacs + (day-fun day)) + (unless (probe-file test-pathname) (with-open-file (stream test-pathname :direction :output) (format stream "~S~%~S~%~%(define-test test-day-~A~% ()~% )" - `(defpackage ,package - (:use #:cl #:lisp-unit2)) - `(in-package ,package) + `(defpackage ,test-package + (:use #:cl #:lisp-unit2) + (:import-from ,package)) + `(in-package ,test-package) day)) (asdf:load-system (format nil "aoc-test/day-~A" day)) (symbol-function (find-symbol (format nil "TEST-DAY-~A" day) - (find-package package)))))))) + (find-package test-package)))))))) (defun main () (let* ((args (uiop:command-line-arguments)) diff --git a/t/day-1.lisp b/t/day-1.lisp @@ -1,5 +1,6 @@ (defpackage #:aoc-test/day-1 - (:use #:cl #:lisp-unit2)) + (:use #:cl #:lisp-unit2) + (:import-from aoc/day-1)) (in-package #:aoc-test/day-1) (define-test test-day-1 diff --git a/t/day-2.lisp b/t/day-2.lisp @@ -1,16 +1,17 @@ (defpackage #:aoc-test/day-2 - (:use #:cl #:lisp-unit2)) + (:use #:cl #:lisp-unit2) + (:import-from aoc/day-2)) (in-package #:aoc-test/day-2) (define-test test-day-2 () ;;; Test resets ;; Report where the first item needs to be skipped - (assert (aoc/day-2::report-safe-p (list 30 24 25 28 31 33 35) :allow-skip t)) + (assert (aoc/day-2:report-safe-p (list 30 24 25 28 31 33 35) :allow-skip t)) ;; Report where the second item needs to be skipped - (assert (aoc/day-2::report-safe-p (list 24 21 25 28 31 33 35) :allow-skip t)) + (assert (aoc/day-2:report-safe-p (list 24 21 25 28 31 33 35) :allow-skip t)) ;; Report where reset target needs to be removed - (assert (aoc/day-2::report-safe-p (list 25 22 19 21 20 17 14 13) :allow-skip t)) + (assert (aoc/day-2:report-safe-p (list 25 22 19 21 20 17 14 13) :allow-skip t)) ;;; Test task 1 & 2 (multiple-value-bind (task-1 task-2) (aoc:run-day 2 "7 6 4 2 1 diff --git a/t/day-3.lisp b/t/day-3.lisp @@ -1,5 +1,6 @@ (defpackage #:aoc-test/day-3 - (:use #:cl #:lisp-unit2)) + (:use #:cl #:lisp-unit2) + (:import-from aoc/day-3)) (in-package #:aoc-test/day-3) (define-test test-day-3