#3 Inching forward, positively

This commit is contained in:
Simon Brooke 2020-05-26 23:30:07 +01:00
parent 9ee365b987
commit 79174af2c1
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
30 changed files with 766 additions and 410 deletions

View file

@ -1,12 +1,12 @@
(ns walkmap.edge-test
(:require [clojure.test :refer :all]
[walkmap.edge :refer :all]
[walkmap.vertex :refer [make-vertex]]))
[walkmap.vertex :refer [vertex]]))
(deftest edge-test
(testing "identification of edges."
(is (edge? {:start (make-vertex 0.0 0.0 0.0)
:end (make-vertex 3 4 0.0)}) "It is.")
(is (edge? {:start (vertex 0.0 0.0 0.0)
:end (vertex 3 4 0.0)}) "It is.")
(is (not (edge? {:start {:y 0.0 :z 0.0 :id 'foo}
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Start lacks :x key")
(is (not (edge? {:start {:x nil :y 0.0 :z 0.0 :id 'foo}
@ -17,7 +17,16 @@
:finish {:x 3 :y 4 :z 0.0 :id 'bar}})) "Lacks end key")
(is (not (edge? {:start {:x "zero" :y 0.0 :z 0.0 :id 'foo}
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Value of x in start is not a number")
))
(is (false? (edge? "I am not an edge")) "Edge mustbe a map.")))
(deftest construction-test
(testing "Construction of edges."
(is (edge? (edge (vertex 1.0 2.0 3.0) (vertex 4.0 8.0 12.0)))
"If both arguments are vertices, we should get an edge")
(is (thrown? IllegalArgumentException (edge "Not a vertex" (vertex 1 2)))
"If first argument is not a vertex, we should get an exception.")
(is (thrown? IllegalArgumentException (edge (vertex 1 2) "Not a vertex"))
"If second argument is not a vertex, we should get an exception.")))
(deftest length-test
(testing "length of an edge"

View file

@ -5,7 +5,7 @@
(deftest tag-tests
(testing "Tagging"
(is (set? (:walkmap.tag/tags (tag {} :foo :bar :ban :froboz)))
"The value of `:walkmap.tag/tags should be a set.")
"The value of `:walkmap.tag/tags` should be a set.")
(is (= (count (:walkmap.tag/tags (tag {} :foo :bar :ban :froboz))) 4)
"All the tags passed should be added.")
(is (:walkmap.tag/tags (tag {} :foo :bar :ban :froboz) :ban)
@ -17,12 +17,18 @@
"`tagged?` should return an explicit `true`, not any other value.")
(is (tagged? (tag {} :foo :bar :ban :froboz) :bar :froboz)
"We should be able to test for the presence of more than one tag")
(is (false? (tagged? {} :foo))
"A missing `:walkmap.tag/tags` should not cause an error.")
(is (= (tagged? (tag {} :foo :bar :ban :froboz) :bar :cornflakes) false)
"If any of the queried tags is missing, false should be returned")
(is (tagged? (tag (tag {} :foo) :bar) :foo :bar)
"We should be able to add tags to an already tagged object")
(is (false? (tagged? (tag {} :foo :bar) :cornflakes))
"`tagged?` should return an explicit `false` if a queried tag is missing.")
(is (= (tags (tag {} :foo)) #{:foo})
"`tags` should return the tags on the object, if any.")
(is (every? nil? (map #(tags %) [1 :one "one" [:one] {:one 1}]))
"Things which don't have tags don't have tags, and that's not a problem.")
(let [object (tag {} :foo :bar :ban :froboz)]
(is (= (untag object :cornflakes) object)
"Removing a missing tag should have no effect.")