;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This file is part of "NOVA": NOVA = search + COCOMO tools ; Copyright, 2008, Tim Menzies tim@menzies.us ; ; NOVA is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; NOVA is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; You should have received a copy of the GNU General Public License ; a long with NOVA. If not, see . ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :nova-test.search) (defvar *path* nil) (deftestsuite fresh-path-test-suite-mixin-mixin () () :documentation "By using this mixin, *path* is shadowed and after each test *path* is set to nil" :dynamic-variables (*path*) :teardown (setf *path* nil)) (deftestsuite path-search-test-suite (fresh-path-test-suite-mixin-mixin fresh-db-test-suite-mixin fresh-evaluate-state-fn-test-suite-mixin nova-tests) () :setup (progn (register-db-default-configuration-list 'test-default-configurations (list (cons 'a (make-num :min 6 :max 10 :discretize-bins 5)) (cons 'b (make-bag :range (list 5 6 7 8))) (cons 'c (make-num :min 2 :max 4 :discretize-bins 3)) (cons 'd (make-bag :range (list 10 30 50 70))) (cons 'e (make-num :min 0 :max 1 :discretize-bins 3)))) (init-db) (setf *path* (make-path :states (list ;;0 (create-state '() ;ignore '((a 6) (b 5) (c 2) (d 10)) ;open '((a 7) (a 8) (a 9) (a 10) (b 6) (b 7) (b 8) (c 3) (c 4) (d 30) (d 50) (d 70)) ) ;;1 (create-state '() ;ignore '((a 6) (b 5) (c 2) (d 10)) ;open '((a 7) (a 8) (a 9) (a 10) (b 6) (b 7) (b 8) (c 3) (c 4) (d 30) (d 50) (d 70)) ) ;;2 (create-state '() ;ignore '((a 6) (b 6) (c 2) (d 30)) ;open '((a 7) (a 8) (a 9) (a 10) (b 5) (b 7) (b 8) (c 3) (c 4) (d 10) (d 50) (d 70)) ) ;;3 (create-state '() ;ignore '((a 6) (b 7) (c 2) (d 50)) ;open '((a 7) (a 8) (a 9) (a 10) (b 5) (b 6) (b 8) (c 3) (c 4) (d 10) (d 30) (d 70)) ) ;;4 (create-state '() ;ignore '((a 6) (b 8) (c 2) (d 70)) ;open '((a 7) (a 8) (a 9) (a 10) (b 5) (b 6) (b 7) (c 3) (c 4) (d 10) (d 30) (d 50)) ) ;;5 (create-state '() ;ignore '((a 6) (b 8) (c 2) (d 70)) ;open '((a 7) (a 8) (a 9) (a 10) (b 5) (b 6) (b 7) (c 3) (c 4) (d 10) (d 30) (d 50)) )))))) (addtest check-states? (ensure *path*) (ensure-same (states? *path*) (path-states *path*))) (addtest check-first-state? (ensure *path*) (ensure-same (first-state? *path*) (first (path-states *path*)))) (addtest check-last-state? (ensure *path*) (ensure-same (last-state? *path*) (first (last (path-states *path*))))) (addtest check-finalize-path-reverse-states (ensure *path*) (let ((orig-first-state (first-state? *path*)) (orig-last-state (last-state? *path*))) (finalize-path *path*) (ensure (path-end *path*) :report "end not set") (ensure-same (first-state? *path*) orig-last-state :report "orginal last state isn't first state") (ensure-same (last-state? *path*) orig-first-state :report "oringal first state isn't last state"))) (addtest check-finalize-path-reverse-states (ensure *path*) (let ((orig-first-state (first-state? *path*)) (orig-last-state (last-state? *path*))) (finalize-path *path* :reverse-states nil) (ensure (path-end *path*) :report "end not set") (ensure-same (first-state? *path*) orig-first-state :report "original first state isn't first state") (ensure-same (last-state? *path*) orig-last-state :report "original last state isn't last state"))) (labels ((db-sum () (reduce #'+ (mapcar #'! (all-db-keys)))) (monte-carlo-db-sum () (monte-carlo :score-fn #'db-sum :combine-fn #'median))) (let ((db-sum-score (augment-evaluate-state-function-by-ids #'db-sum :with-constraints :ignore-state)) (monte-carlo-db-sum-score (augment-evaluate-state-function-by-ids #'monte-carlo-db-sum :with-constraints :ignore-state))) (addtest check-max-score-state-of-path? (ensure *path*) (with-evaluate-state-function monte-carlo-db-sum-score (ensure (member (position (max-score-state-of-path? *path*) (states? *path*)) '(4 5))))) (addtest check-min-score-state-of-path? (ensure *path*) (with-evaluate-state-function monte-carlo-db-sum-score (ensure (member (position (min-score-state-of-path? *path*) (states? *path*)) '(0 1))))) (addtest check-max-score-state-of-path-by-ttest? (ensure *path*) (with-evaluate-state-function db-sum-score (ensure-same (position (max-score-state-of-path-by-ttest? *path*) (states? *path*)) 4))) (addtest check-min-score-state-of-path-by-ttest? (ensure *path*) (with-evaluate-state-function db-sum-score (ensure-same (position (min-score-state-of-path-by-ttest? *path*) (states? *path*)) 0))))) (addtest check-print-paths (ensure *path*) (with-evaluate-state-function #'(lambda (state) (declare (ignore state)) 0) (ensure-no-warning (print-paths (as-list *path*)))))