;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :nova-test.search)

(deftestsuite decision-search-test-suite (fresh-path-test-suite-mixin-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 30)) ;open
                                                        '((a 7) (a 8) (a 9) (a 10)
                                                          (b 6) (b 7) (b 8)
                                                          (c 3) (c 4)
                                                          (d 10) (d 50) (d 70))
                                                        )
                                          ;;1
                                          (create-state '() ;ignore
                                                        '((a 6) (b 5) (b 6) (c 2) (d 30)) ;open
                                                        '((a 7) (a 8) (a 9) (a 10)
                                                          (b 7) (b 8)
                                                          (c 3) (c 4)
                                                          (d 10) (d 50) (d 70))
                                                        )
                                          ;;2
                                          (create-state '() ;ignore
                                                        '((a 6) (b 5) (b 6) (b 7) (c 2) (d 30)) ;open
                                                        '((a 7) (a 8) (a 9) (a 10)
                                                          (b 8)
                                                          (c 3) (c 4)
                                                          (d 10) (d 50) (d 70))
                                                        )
                                          ;;3
                                          (create-state '() ;ignore
                                                        '((a 6) (b 5) (b 6) (b 7) (b 8) (c 2) (d 30)) ;open
                                                        '((a 7) (a 8) (a 9) (a 10)
                                                          (c 3) (c 4)
                                                          (d 10) (d 50) (d 70))
                                                        ))))))

(addtest check-path2decisions
  (ensure-same (path2decisions *path*)
               (list (make-decision :added-constraints '((b 6))
                                    :constraints '((D 30) (C 2) (B 5 6) (A 6)))
                     (make-decision :added-constraints '((b 7))
                                    :constraints '((D 30) (C 2) (B 5 6 7) (A 6)))
                     (make-decision :removed-constraints '((b 7 6 5))
                                    :constraints '((D 30) (C 2) (A 6))))
               :test #'equalp
               :report "path2decisions not the same when adding decisions"))