dengine/test/dengine/feature_test.clj

46 lines
2.1 KiB
Clojure

(ns dengine.feature-test
(:require
[arboretum.dengine.case :refer [make-case]]
[arboretum.dengine.core :refer [add-case! add-feature!]]
[arboretum.dengine.feature :refer [make-feature]]
[arboretum.dengine.kb :refer [!kb]]
[clojure.pprint :refer [pprint]]
[clojure.test :refer [deftest is testing]])
(:import
[arboretum.dengine.kb KBImpl]))
(def testkb (KBImpl. {:case-1 (make-case :case-1 "Mrs Nora Trellis"
{:married {:value true
:authority :user
:reason "I have been told that married is true of Mrs Norah Trellis"}
:divorced {:value false
:authority :default
:reason "I assumed that divorced is false of Mrs Norah Trellis"}
:is-entitled-to-widows-benefit {:value true
:authority :rule
:reason "I infered that is-entitled-to-widows-benefit is true of Mrs Norah Trellis"}})}
{:widowed (make-feature "Widowed" :widowed false nil)
:married (make-feature "Married" :married false nil)}))
(reset! !kb testkb)
(pprint @!kb)
(deftest feature-impl-test
(testing "Testing feature implementation"
(let [f1 (.get-feature @!kb :widowed)
c (.get-case @!kb :case-1)]
(pprint {:f f1
:c c})
(let [expected :widowed
actual (.feature-id f1)]
(is (= actual expected)))
(let [expected false
actual (.default f1)]
(is (= actual expected)))
(let [expected false
actual (.decide f1 c)]
(is (= actual expected) "If we have no knowledge and no decision method, take the defualt."))
(let [expected true
actual (.decide (.get-feature @!kb :married) :case-1)]
(is (= actual expected) "If we have knowledge, return it.")))))