From 4b76eb5e4f6c29dc21c3a6c217b20f0b511f0a42 Mon Sep 17 00:00:00 2001 From: Simon Brooke <simon@journeyman.cc> Date: Wed, 3 Jun 2020 16:26:30 +0100 Subject: [PATCH] More tests, all pass. --- .gitignore | 6 + docs/cloverage/index.html | 106 +++++++------ docs/cloverage/walkmap/path.clj.html | 2 +- docs/cloverage/walkmap/polygon.clj.html | 142 ++++++++++-------- docs/cloverage/walkmap/stl.clj.html | 2 +- .../cloverage/walkmap/superstructure.clj.html | 2 +- docs/cloverage/walkmap/svg.clj.html | 4 +- docs/cloverage/walkmap/tag.clj.html | 2 +- docs/cloverage/walkmap/utils.clj.html | 26 ++-- docs/cloverage/walkmap/vertex.clj.html | 29 ++-- test/walkmap/utils_test.clj | 88 ++++++++++- 11 files changed, 257 insertions(+), 152 deletions(-) diff --git a/.gitignore b/.gitignore index f747809..97b570a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,9 @@ resources/small_hill.svg s.edn .eastwood + +settlement_1.edn + +small_hill.edn + +small_hill.html diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html index 93248aa..1c568a3 100644 --- a/docs/cloverage/index.html +++ b/docs/cloverage/index.html @@ -68,11 +68,11 @@ </tr> <tr> <td><a href="walkmap/path.clj.html">walkmap.path</a></td><td class="with-bar"><div class="covered" - style="width:93.60902255639098%; - float:left;"> 249 </div><div class="not-covered" - style="width:6.390977443609023%; - float:left;"> 17 </div></td> -<td class="with-number">93.61 %</td> + style="width:93.98496240601504%; + float:left;"> 250 </div><div class="not-covered" + style="width:6.015037593984962%; + float:left;"> 16 </div></td> +<td class="with-number">93.98 %</td> <td class="with-bar"><div class="covered" style="width:89.74358974358974%; float:left;"> 35 </div><div class="partial" @@ -85,20 +85,20 @@ </tr> <tr> <td><a href="walkmap/polygon.clj.html">walkmap.polygon</a></td><td class="with-bar"><div class="covered" - style="width:71.45969498910675%; - float:left;"> 328 </div><div class="not-covered" - style="width:28.540305010893245%; + style="width:72.0682302771855%; + float:left;"> 338 </div><div class="not-covered" + style="width:27.931769722814497%; float:left;"> 131 </div></td> -<td class="with-number">71.46 %</td> +<td class="with-number">72.07 %</td> <td class="with-bar"><div class="covered" - style="width:76.78571428571429%; - float:left;"> 43 </div><div class="partial" - style="width:10.714285714285714%; + style="width:77.58620689655173%; + float:left;"> 45 </div><div class="partial" + style="width:10.344827586206897%; float:left;"> 6 </div><div class="not-covered" - style="width:12.5%; + style="width:12.068965517241379%; float:left;"> 7 </div></td> -<td class="with-number">87.50 %</td> -<td class="with-number">114</td><td class="with-number">13</td><td class="with-number">56</td> +<td class="with-number">87.93 %</td> +<td class="with-number">118</td><td class="with-number">13</td><td class="with-number">58</td> </tr> <tr> <td><a href="walkmap/read_svg.clj.html">walkmap.read-svg</a></td><td class="with-bar"><div class="covered" @@ -128,11 +128,11 @@ </tr> <tr> <td><a href="walkmap/stl.clj.html">walkmap.stl</a></td><td class="with-bar"><div class="covered" - style="width:49.07216494845361%; + style="width:50.638297872340424%; float:left;"> 238 </div><div class="not-covered" - style="width:50.92783505154639%; - float:left;"> 247 </div></td> -<td class="with-number">49.07 %</td> + style="width:49.361702127659576%; + float:left;"> 232 </div></td> +<td class="with-number">50.64 %</td> <td class="with-bar"><div class="covered" style="width:40.56603773584906%; float:left;"> 43 </div><div class="partial" @@ -145,11 +145,11 @@ </tr> <tr> <td><a href="walkmap/superstructure.clj.html">walkmap.superstructure</a></td><td class="with-bar"><div class="covered" - style="width:71.76781002638522%; - float:left;"> 272 </div><div class="not-covered" - style="width:28.232189973614776%; + style="width:70.6043956043956%; + float:left;"> 257 </div><div class="not-covered" + style="width:29.395604395604394%; float:left;"> 107 </div></td> -<td class="with-number">71.77 %</td> +<td class="with-number">70.60 %</td> <td class="with-bar"><div class="covered" style="width:71.26436781609195%; float:left;"> 62 </div><div class="partial" @@ -162,11 +162,11 @@ </tr> <tr> <td><a href="walkmap/svg.clj.html">walkmap.svg</a></td><td class="with-bar"><div class="covered" - style="width:3.7542662116040955%; + style="width:4.21455938697318%; float:left;"> 11 </div><div class="not-covered" - style="width:96.24573378839591%; - float:left;"> 282 </div></td> -<td class="with-number">3.75 %</td> + style="width:95.78544061302682%; + float:left;"> 250 </div></td> +<td class="with-number">4.21 %</td> <td class="with-bar"><div class="covered" style="width:12.121212121212121%; float:left;"> 8 </div><div class="not-covered" @@ -178,7 +178,7 @@ <tr> <td><a href="walkmap/tag.clj.html">walkmap.tag</a></td><td class="with-bar"><div class="covered" style="width:100.0%; - float:left;"> 178 </div></td> + float:left;"> 159 </div></td> <td class="with-number">100.00 %</td> <td class="with-bar"><div class="covered" style="width:100.0%; @@ -188,43 +188,41 @@ </tr> <tr> <td><a href="walkmap/utils.clj.html">walkmap.utils</a></td><td class="with-bar"><div class="covered" - style="width:56.216931216931215%; - float:left;"> 425 </div><div class="not-covered" - style="width:43.783068783068785%; - float:left;"> 331 </div></td> -<td class="with-number">56.22 %</td> + style="width:99.86772486772487%; + float:left;"> 755 </div><div class="not-covered" + style="width:0.13227513227513227%; + float:left;"> 1 </div></td> +<td class="with-number">99.87 %</td> <td class="with-bar"><div class="covered" - style="width:69.44444444444444%; - float:left;"> 25 </div><div class="partial" - style="width:11.11111111111111%; - float:left;"> 4 </div><div class="not-covered" - style="width:19.444444444444443%; - float:left;"> 7 </div></td> -<td class="with-number">80.56 %</td> + style="width:97.22222222222223%; + float:left;"> 35 </div><div class="partial" + style="width:2.7777777777777777%; + float:left;"> 1 </div></td> +<td class="with-number">100.00 %</td> <td class="with-number">101</td><td class="with-number">9</td><td class="with-number">36</td> </tr> <tr> <td><a href="walkmap/vertex.clj.html">walkmap.vertex</a></td><td class="with-bar"><div class="covered" - style="width:86.52094717668488%; - float:left;"> 475 </div><div class="not-covered" - style="width:13.479052823315119%; - float:left;"> 74 </div></td> -<td class="with-number">86.52 %</td> + style="width:89.45454545454545%; + float:left;"> 492 </div><div class="not-covered" + style="width:10.545454545454545%; + float:left;"> 58 </div></td> +<td class="with-number">89.45 %</td> <td class="with-bar"><div class="covered" - style="width:82.1917808219178%; - float:left;"> 60 </div><div class="partial" - style="width:15.068493150684931%; - float:left;"> 11 </div><div class="not-covered" - style="width:2.73972602739726%; + style="width:83.78378378378379%; + float:left;"> 62 </div><div class="partial" + style="width:13.513513513513514%; + float:left;"> 10 </div><div class="not-covered" + style="width:2.7027027027027026%; float:left;"> 2 </div></td> -<td class="with-number">97.26 %</td> -<td class="with-number">150</td><td class="with-number">15</td><td class="with-number">73</td> +<td class="with-number">97.30 %</td> +<td class="with-number">151</td><td class="with-number">15</td><td class="with-number">74</td> </tr> <tr><td>Totals:</td> <td class="with-bar"></td> -<td class="with-number">64.52 %</td> +<td class="with-number">72.81 %</td> <td class="with-bar"></td> -<td class="with-number">67.67 %</td> +<td class="with-number">68.80 %</td> </tr> </table> </body> diff --git a/docs/cloverage/walkmap/path.clj.html b/docs/cloverage/walkmap/path.clj.html index 907a2e7..4df3664 100644 --- a/docs/cloverage/walkmap/path.clj.html +++ b/docs/cloverage/walkmap/path.clj.html @@ -58,7 +58,7 @@ <span class="covered" title="3 out of 3 forms covered"> 018 [v (:vertices o)] </span><br/> -<span class="partial" title="18 out of 22 forms covered"> +<span class="partial" title="19 out of 22 forms covered"> 019 (and </span><br/> <span class="covered" title="3 out of 3 forms covered"> diff --git a/docs/cloverage/walkmap/polygon.clj.html b/docs/cloverage/walkmap/polygon.clj.html index c3b5f51..a7c5f47 100644 --- a/docs/cloverage/walkmap/polygon.clj.html +++ b/docs/cloverage/walkmap/polygon.clj.html @@ -166,185 +166,197 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 054 [& vertices] </span><br/> -<span class="covered" title="30 out of 30 forms covered"> - 055 {:vertices (check-vertices vertices) +<span class="covered" title="1 out of 1 forms covered"> + 055 (if </span><br/> -<span class="covered" title="5 out of 5 forms covered"> - 056 :walkmap.id/id (keyword (gensym "poly")) +<span class="covered" title="6 out of 6 forms covered"> + 056 (> (count vertices) 2) + </span><br/> +<span class="covered" title="30 out of 30 forms covered"> + 057 {:vertices (check-vertices vertices) + </span><br/> +<span class="covered" title="6 out of 6 forms covered"> + 058 :walkmap.id/id (keyword (gensym "poly")) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 057 :kind :polygon}) + 059 :kind :polygon} </span><br/> -<span class="blank" title="1 out of 1 forms covered"> - 058 +<span class="covered" title="3 out of 3 forms covered"> + 060 (throw (IllegalArgumentException. + </span><br/> +<span class="not-tracked" title="0 out of 0 forms covered"> + 061 "A polygon must have at least 3 vertices.")))) + </span><br/> +<span class="blank" title="0 out of 0 forms covered"> + 062 </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 059 (defn rectangle + 063 (defn rectangle </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 060 "Return a rectangle, with edges aligned east-west and north-south, whose + 064 "Return a rectangle, with edges aligned east-west and north-south, whose </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 061 south-west corner is the vertex `vsw` and whose north-east corner is the + 065 south-west corner is the vertex `vsw` and whose north-east corner is the </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 062 vertex `vne`." + 066 vertex `vne`." </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 063 [vsw vne] + 067 [vsw vne] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 064 ;; we can actually create any rectangle in the xy plane based on two opposite + 068 ;; we can actually create any rectangle in the xy plane based on two opposite </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 065 ;; corners, but the maths are a bit to advanced for me today. TODO: do it! + 069 ;; corners, but the maths are a bit to advanced for me today. TODO: do it! </span><br/> -<span class="not-covered" title="0 out of 21 forms covered"> - 066 (let [vnw (vertex (:x (check-vertex vsw)) +<span class="partial" title="9 out of 30 forms covered"> + 070 (let [vnw (vertex (:x (check-vertex vsw)) </span><br/> <span class="not-covered" title="0 out of 18 forms covered"> - 067 (:y (check-vertex vne)) + 071 (:y (check-vertex vne)) </span><br/> <span class="not-covered" title="0 out of 20 forms covered"> - 068 (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2)) + 072 (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2)) </span><br/> <span class="not-covered" title="0 out of 5 forms covered"> - 069 vse (vertex (:x vne) + 073 vse (vertex (:x vne) </span><br/> -<span class="partial" title="9 out of 12 forms covered"> - 070 (:y vsw) +<span class="not-covered" title="0 out of 3 forms covered"> + 074 (:y vsw) </span><br/> <span class="not-covered" title="0 out of 20 forms covered"> - 071 (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2))] + 075 (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2))] </span><br/> <span class="not-covered" title="0 out of 9 forms covered"> - 072 (t/tag (polygon vsw vnw vne vse) :rectangle))) + 076 (t/tag (polygon vsw vnw vne vse) :rectangle))) </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 073 + 077 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 074 ;; (rectangle (vertex 1 2 3) (vertex 7 9 4)) + 078 ;; (rectangle (vertex 1 2 3) (vertex 7 9 4)) </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 075 + 079 </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 076 (defn gradient + 080 (defn gradient </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 077 "Return a polygon like `triangle` but with a key `:gradient` whose value is a + 081 "Return a polygon like `triangle` but with a key `:gradient` whose value is a </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 078 unit vector representing the gradient across `triangle`." + 082 unit vector representing the gradient across `triangle`." </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 079 [triangle] + 083 [triangle] </span><br/> <span class="covered" title="12 out of 12 forms covered"> - 080 (let [order (sort #(max (:z %1) (:z %2)) + 084 (let [order (sort #(max (:z %1) (:z %2)) </span><br/> <span class="partial" title="8 out of 18 forms covered"> - 081 (:vertices (check-triangle triangle))) + 085 (:vertices (check-triangle triangle))) </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 082 highest (first order) + 086 highest (first order) </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 083 lowest (last order)] + 087 lowest (last order)] </span><br/> <span class="covered" title="10 out of 10 forms covered"> - 084 (assoc triangle :gradient (e/unit-vector (e/edge lowest highest))))) + 088 (assoc triangle :gradient (e/unit-vector (e/edge lowest highest))))) </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 085 + 089 </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 086 (defn triangle-centre + 090 (defn triangle-centre </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 087 "Return a canonicalised `facet` (i.e. a triangular polygon) with an added + 091 "Return a canonicalised `facet` (i.e. a triangular polygon) with an added </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 088 key `:centre` whose value represents the centre of this facet in 3 + 092 key `:centre` whose value represents the centre of this facet in 3 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 089 dimensions. This only works for triangles, so is here not in + 093 dimensions. This only works for triangles, so is here not in </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 090 `walkmap.polygon`. It is an error (although no exception is currently + 094 `walkmap.polygon`. It is an error (although no exception is currently </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 091 thrown) if the object past is not a triangular polygon." + 095 thrown) if the object past is not a triangular polygon." </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 092 [facet] + 096 [facet] </span><br/> <span class="partial" title="9 out of 19 forms covered"> - 093 (let [vs (:vertices (check-triangle facet)) + 097 (let [vs (:vertices (check-triangle facet)) </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 094 v1 (first vs) + 098 v1 (first vs) </span><br/> <span class="covered" title="10 out of 10 forms covered"> - 095 opposite (e/edge (nth vs 1) (nth vs 2)) + 099 opposite (e/edge (nth vs 1) (nth vs 2)) </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 096 oc (e/centre opposite)] + 100 oc (e/centre opposite)] </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 097 (assoc + 101 (assoc </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 098 facet + 102 facet </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 099 :centre + 103 :centre </span><br/> <span class="covered" title="2 out of 2 forms covered"> - 100 (vertex + 104 (vertex </span><br/> <span class="covered" title="16 out of 16 forms covered"> - 101 (+ (:x v1) (* (- (:x oc) (:x v1)) 2/3)) + 105 (+ (:x v1) (* (- (:x oc) (:x v1)) 2/3)) </span><br/> <span class="covered" title="16 out of 16 forms covered"> - 102 (+ (:y v1) (* (- (:y oc) (:y v1)) 2/3)) + 106 (+ (:y v1) (* (- (:y oc) (:y v1)) 2/3)) </span><br/> <span class="covered" title="16 out of 16 forms covered"> - 103 (+ (:z v1) (* (- (:z oc) (:z v1)) 2/3)))))) + 107 (+ (:z v1) (* (- (:z oc) (:z v1)) 2/3)))))) </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 104 + 108 </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 105 (defn centre + 109 (defn centre </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 106 [poly] + 110 [poly] </span><br/> <span class="covered" title="22 out of 22 forms covered"> - 107 (case (count (:vertices (check-polygon poly))) + 111 (case (count (:vertices (check-polygon poly))) </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 108 3 (triangle-centre poly) + 112 3 (triangle-centre poly) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 109 ;; else + 113 ;; else </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 110 (throw + 114 (throw </span><br/> <span class="covered" title="2 out of 2 forms covered"> - 111 (UnsupportedOperationException. + 115 (UnsupportedOperationException. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 112 "The general case of centre for polygons is not yet implemented.")))) + 116 "The general case of centre for polygons is not yet implemented.")))) </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 113 + 117 </span><br/> <span class="blank" title="0 out of 0 forms covered"> - 114 + 118 </span><br/> </body> </html> diff --git a/docs/cloverage/walkmap/stl.clj.html b/docs/cloverage/walkmap/stl.clj.html index 5240aa8..ff71dd2 100644 --- a/docs/cloverage/walkmap/stl.clj.html +++ b/docs/cloverage/walkmap/stl.clj.html @@ -550,7 +550,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 182 ([filename stl solidname] </span><br/> -<span class="not-covered" title="0 out of 16 forms covered"> +<span class="not-covered" title="0 out of 1 forms covered"> 183 (l/debug "Solid name is " solidname) </span><br/> <span class="not-covered" title="0 out of 2 forms covered"> diff --git a/docs/cloverage/walkmap/superstructure.clj.html b/docs/cloverage/walkmap/superstructure.clj.html index a83ad6d..229b2b9 100644 --- a/docs/cloverage/walkmap/superstructure.clj.html +++ b/docs/cloverage/walkmap/superstructure.clj.html @@ -355,7 +355,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 117 ([o s] </span><br/> -<span class="covered" title="16 out of 16 forms covered"> +<span class="covered" title="1 out of 1 forms covered"> 118 (l/debug "Finding objects in:" o) </span><br/> <span class="covered" title="4 out of 4 forms covered"> diff --git a/docs/cloverage/walkmap/svg.clj.html b/docs/cloverage/walkmap/svg.clj.html index c04a8b4..29fe91d 100644 --- a/docs/cloverage/walkmap/svg.clj.html +++ b/docs/cloverage/walkmap/svg.clj.html @@ -274,7 +274,7 @@ <span class="not-covered" title="0 out of 3 forms covered"> 090 (:facets stl)))] </span><br/> -<span class="not-covered" title="0 out of 17 forms covered"> +<span class="not-covered" title="0 out of 1 forms covered"> 091 (l/info "Generating SVG for " *preferred-svg-render* " renderer") </span><br/> <span class="not-covered" title="0 out of 3 forms covered"> @@ -316,7 +316,7 @@ <span class="not-covered" title="0 out of 4 forms covered"> 104 (let [s (binary-stl-file->svg in-filename)] </span><br/> -<span class="not-covered" title="0 out of 17 forms covered"> +<span class="not-covered" title="0 out of 1 forms covered"> 105 (l/info "Emitting SVG with " *preferred-svg-render* " renderer") </span><br/> <span class="not-covered" title="0 out of 3 forms covered"> diff --git a/docs/cloverage/walkmap/tag.clj.html b/docs/cloverage/walkmap/tag.clj.html index d26ce5f..1a20e0b 100644 --- a/docs/cloverage/walkmap/tag.clj.html +++ b/docs/cloverage/walkmap/tag.clj.html @@ -118,7 +118,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 038 [object & tags] </span><br/> -<span class="covered" title="20 out of 20 forms covered"> +<span class="covered" title="1 out of 1 forms covered"> 039 (l/debug "Tagging" (kind-type object) "with" tags) </span><br/> <span class="covered" title="6 out of 6 forms covered"> diff --git a/docs/cloverage/walkmap/utils.clj.html b/docs/cloverage/walkmap/utils.clj.html index 84e02ec..1ed6104 100644 --- a/docs/cloverage/walkmap/utils.clj.html +++ b/docs/cloverage/walkmap/utils.clj.html @@ -61,7 +61,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 019 [s n] </span><br/> -<span class="partial" title="19 out of 21 forms covered"> +<span class="partial" title="20 out of 21 forms covered"> 020 (if (and (string? s) (number? n) (> (count s) n)) </span><br/> <span class="covered" title="5 out of 5 forms covered"> @@ -91,7 +91,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 029 [object] </span><br/> -<span class="partial" title="14 out of 15 forms covered"> +<span class="covered" title="15 out of 15 forms covered"> 030 (or (:kind object) (type object) "nil")) </span><br/> <span class="blank" title="0 out of 0 forms covered"> @@ -104,7 +104,7 @@ 033 "True if numbers `n1`, `n2` are roughly equal; that is to say, equal to </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 034 within `tolerance` (defaults to one part in a million)." + 034 within `tolerance` (defaults to one part in one hundred thousand)." </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 035 ([n1 n2] @@ -116,7 +116,7 @@ 037 (let [m (m/abs (min n1 n2)) </span><br/> <span class="covered" title="9 out of 9 forms covered"> - 038 t (if (zero? m) 0.000001 (* 0.000001 m))] + 038 t (if (zero? m) 0.00001 (* 0.00001 m))] </span><br/> <span class="covered" title="5 out of 5 forms covered"> 039 (=ish n1 n2 t)) @@ -139,7 +139,7 @@ <span class="blank" title="0 out of 0 forms covered"> 045 </span><br/> -<span class="partial" title="94 out of 198 forms covered"> +<span class="covered" title="198 out of 198 forms covered"> 046 (defmacro check-kind-type </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> @@ -163,7 +163,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 053 ([object expected] </span><br/> -<span class="not-covered" title="0 out of 2 forms covered"> +<span class="covered" title="2 out of 2 forms covered"> 054 `(if-not (= (kind-type ~object) ~expected) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> @@ -178,10 +178,10 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 058 " " </span><br/> -<span class="not-covered" title="0 out of 2 forms covered"> +<span class="covered" title="2 out of 2 forms covered"> 059 ["Expected" ~expected "but found" (kind-type ~object)]))) </span><br/> -<span class="not-covered" title="0 out of 1 forms covered"> +<span class="covered" title="1 out of 1 forms covered"> 060 ~object)) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> @@ -211,7 +211,7 @@ <span class="blank" title="0 out of 0 forms covered"> 069 </span><br/> -<span class="partial" title="203 out of 416 forms covered"> +<span class="covered" title="416 out of 416 forms covered"> 070 (defmacro check-kind-type-seq </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> @@ -235,7 +235,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 077 ([s expected] </span><br/> -<span class="not-covered" title="0 out of 2 forms covered"> +<span class="covered" title="2 out of 2 forms covered"> 078 `(if-not (every? #(= (kind-type %) ~expected) ~s) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> @@ -253,19 +253,19 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 083 ["Expected sequence of" </span><br/> -<span class="not-covered" title="0 out of 1 forms covered"> +<span class="covered" title="1 out of 1 forms covered"> 084 ~expected </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 085 "but found (" </span><br/> -<span class="not-covered" title="0 out of 2 forms covered"> +<span class="covered" title="2 out of 2 forms covered"> 086 (s/join ", " (remove #(= ~expected %) (map kind-type ~s))) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 087 ")"]))) </span><br/> -<span class="not-covered" title="0 out of 1 forms covered"> +<span class="covered" title="1 out of 1 forms covered"> 088 ~s)) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> diff --git a/docs/cloverage/walkmap/vertex.clj.html b/docs/cloverage/walkmap/vertex.clj.html index b1ca90f..6495272 100644 --- a/docs/cloverage/walkmap/vertex.clj.html +++ b/docs/cloverage/walkmap/vertex.clj.html @@ -130,7 +130,7 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 042 [o] </span><br/> -<span class="partial" title="23 out of 26 forms covered"> +<span class="partial" title="24 out of 26 forms covered"> 043 (and </span><br/> <span class="covered" title="3 out of 3 forms covered"> @@ -139,7 +139,7 @@ <span class="covered" title="3 out of 3 forms covered"> 045 (:walkmap.id/id o) </span><br/> -<span class="partial" title="13 out of 17 forms covered"> +<span class="partial" title="11 out of 17 forms covered"> 046 (number? (:x o)) </span><br/> <span class="covered" title="5 out of 5 forms covered"> @@ -205,13 +205,13 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 067 [v1 v2] </span><br/> -<span class="covered" title="16 out of 16 forms covered"> +<span class="partial" title="6 out of 16 forms covered"> 068 (check-vertex v1) </span><br/> <span class="covered" title="16 out of 16 forms covered"> 069 (check-vertex v2) </span><br/> -<span class="partial" title="5 out of 12 forms covered"> +<span class="covered" title="12 out of 12 forms covered"> 070 (every? </span><br/> <span class="covered" title="8 out of 8 forms covered"> @@ -430,29 +430,32 @@ <span class="not-tracked" title="0 out of 0 forms covered"> 142 [target minv maxv] </span><br/> -<span class="partial" title="14 out of 34 forms covered"> - 143 (check-vertices [target minv maxv]) +<span class="covered" title="1 out of 1 forms covered"> + 143 (do + </span><br/> +<span class="covered" title="34 out of 34 forms covered"> + 144 (check-vertices [target minv maxv]) </span><br/> <span class="covered" title="2 out of 2 forms covered"> - 144 (every? + 145 (every? </span><br/> <span class="covered" title="1 out of 1 forms covered"> - 145 true? + 146 true? </span><br/> <span class="covered" title="3 out of 3 forms covered"> - 146 (map + 147 (map </span><br/> <span class="covered" title="5 out of 5 forms covered"> - 147 #(if (% target) + 148 #(if (% target) </span><br/> <span class="covered" title="11 out of 11 forms covered"> - 148 (<= (% minv) (% target) (% maxv)) + 149 (<= (% minv) (% target) (% maxv)) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> - 149 true) + 150 true) </span><br/> <span class="covered" title="4 out of 4 forms covered"> - 150 [:x :y :z]))) + 151 [:x :y :z])))) </span><br/> </body> </html> diff --git a/test/walkmap/utils_test.clj b/test/walkmap/utils_test.clj index 3a09b01..d2ce375 100644 --- a/test/walkmap/utils_test.clj +++ b/test/walkmap/utils_test.clj @@ -1,6 +1,7 @@ (ns walkmap.utils-test (:require [clojure.test :refer :all] - [walkmap.utils :refer :all])) + [walkmap.utils :refer :all] + [walkmap.vertex :refer [vertex vertex?]])) (deftest =ish-tests (testing "Rough equality" @@ -12,3 +13,88 @@ (is (=ish :foo :foo) "Fails over to plain old equals for non-numbers.") (is (=ish 6 5 10000) "If tolerance is wide enough, anything can be equal.") (is (not (=ish "hello" "goodbye" 10000)) "Well, except non-numbers, of course."))) + +(deftest truncate-tests + (testing "String truncation" + (is (= (truncate "The quick brown fox jumped over the lazy dog" 19) + "The quick brown fox") + "If it's a sting, and longer than the desired length, it should be + truncated.") + (is (= (truncate "The quick brown fox jumped over the lazy dog" 100) + "The quick brown fox jumped over the lazy dog") + "If it's a sting, and shorter than the desired length, it should not be + truncated.") + (is (= (truncate :the-quick-brown-fox 10) :the-quick-brown-fox) + "If it's not a string, it should not be truncated, regardless."))) + + +(deftest kind-type-tests + (testing "Type identification." + (is (= (kind-type {:kind :test}) :test) + "Maps with a value for `:kind` return that as their kind.") + (is (= (kind-type {:dnik :test}) clojure.lang.PersistentArrayMap) + "Maps with no value for `:kind` are just maps.") + (is (= (kind-type nil) "nil") + "As a special case, the kind of `nil` is the string \"nil\".") + (is (= (kind-type "Fred") java.lang.String) + "The kind-type of anything else is just its Java class."))) + +(deftest check-kind-type-tests + (testing "Exception thrown if kind not as expected." + (let [v {:kind :test}] + (is (= (check-kind-type v :test) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (= (check-kind-type v java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (= (check-kind-type v string? java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v (vertex 1 1 1)] + (is (= (check-kind-type v :vertex) v) + "If the check passes, the object is returned.")) + (let [v (vertex 1 1 1)] + (is (= (check-kind-type v vertex? :vertex) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (thrown? IllegalArgumentException + (check-kind-type v :test)) + "If the check doesn't pass, an exception is thrown.")) + (let [v {:kind :test}] + (is (thrown? IllegalArgumentException + (check-kind-type v vertex? :vertex)) + "If the check doesn't pass, an exception is thrown.")))) + +(deftest check-kind-type-seq-tests + (testing "Exception thrown if kind not as expected: sequence variant." + (let [v [{:kind :test} {:kind :test}]] + (is (= (check-kind-type-seq v :test) v) + "If the check passes, the object is returned.")) + (let [v (list "another" "test")] + (is (= (check-kind-type-seq v java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v ["more" "test" "strings"]] + (is (= (check-kind-type-seq v string? java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v (list (vertex 1 1 1) (vertex 2 2 2) (vertex 3 3 3))] + (is (= (check-kind-type-seq v :vertex) v) + "If the check passes, the object is returned.")) + (let [v (list (vertex 1 1 1))] + (is (= (check-kind-type-seq v vertex? :vertex) v) + "If the check passes, the object is returned.")) + (let [v :test] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v :test)) + "If the arg isn't a sequence, an exception is thrown.")) + (let [v (list (vertex 1 1 1) "test" (vertex 3 3 3))] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v :test)) + "If the check doesn't pass for any item, an exception is thrown.")) + (let [v (list (vertex 1 1 1) (vertex 2 2 2) "test")] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v vertex? :vertex)) + "If the check doesn't pass, an exception is thrown.")))) + + + +