Some tests
authorJavier Sancho <jsf@jsancho.org>
Wed, 28 Aug 2019 17:32:22 +0000 (19:32 +0200)
committerJavier Sancho <jsf@jsancho.org>
Wed, 28 Aug 2019 17:32:22 +0000 (19:32 +0200)
.gitignore [new file with mode: 0644]
tests/point.scm [new file with mode: 0644]
tests/triangle.scm [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..397b4a7
--- /dev/null
@@ -0,0 +1 @@
+*.log
diff --git a/tests/point.scm b/tests/point.scm
new file mode 100644 (file)
index 0000000..e88e96a
--- /dev/null
@@ -0,0 +1,46 @@
+;;; Dungeon Master --- Adventure generator for GNU Guile
+;;; Copyright © 2019 Javier Sancho <jsf@jsancho.org>
+;;;
+;;; Dungeon Master 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.
+;;;
+;;; Dungeon Master 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
+;;; along with Haunt.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (test-point)
+  #:use-module (srfi srfi-64)
+  #:use-module (dungeon-master geom point))
+
+(test-begin "point")
+
+(test-equal
+ "distance"
+ (points-distance
+  (make-point 0 0)
+  (make-point 0 -10))
+ 10)
+
+(test-equal
+ "sum points"
+ (sum-points
+  (make-point 1 2)
+  (make-point 3 4)
+  (make-point 5 6))
+ (make-point 9 12))
+
+(test-equal
+ "scale point"
+ (scale-point (make-point 2 5) 2.5)
+ (make-point 5.0 12.5))
+
+(test-end)
+
+(exit (zero? (test-runner-fail-count (test-runner-current))))
diff --git a/tests/triangle.scm b/tests/triangle.scm
new file mode 100644 (file)
index 0000000..8aa151a
--- /dev/null
@@ -0,0 +1,50 @@
+;;; Dungeon Master --- Adventure generator for GNU Guile
+;;; Copyright © 2019 Javier Sancho <jsf@jsancho.org>
+;;;
+;;; Dungeon Master 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.
+;;;
+;;; Dungeon Master 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
+;;; along with Haunt.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (test-point)
+  #:use-module (srfi srfi-64)
+  #:use-module (dungeon-master geom point)
+  #:use-module (dungeon-master geom triangle))
+
+(test-begin "triangle")
+
+(define p1 (make-point 0 0))
+(define p2 (make-point 0 10))
+(define p3 (make-point 10 0))
+(define tr (make-triangle p1 p2 p3))
+
+(test-equal
+ "circumcenter"
+ (triangle-center tr)
+ (make-point 5 5))
+
+(test-assert
+ "radius"
+ (= (triangle-radius tr)
+    (points-distance (triangle-center tr) p1)
+    (points-distance (triangle-center tr) p2)
+    (points-distance (triangle-center tr) p3)))
+
+(test-assert
+ "has edge"
+ (and (triangle-has-edge tr p1 p2)
+      (triangle-has-edge tr p2 p1)
+      (triangle-has-edge tr p3 p1)))
+
+(test-end)
+
+(exit (zero? (test-runner-fail-count (test-runner-current))))