diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-09-08 09:04:44 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-09-08 09:05:35 -0400 |
commit | 37312bb2c9ce6f2bb778e043a8697729bce81a0a (patch) | |
tree | a406ec66f4b3dc95996476b43541a6a818c6aa0c | |
parent | 7e4a2e25e86aed646621f2a4ba019fa0a6307b51 (diff) |
Add the start of a test suite.
-rw-r--r-- | .dir-locals.el | 4 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | test-env.in | 5 | ||||
-rw-r--r-- | tests/math/vector.scm | 88 | ||||
-rw-r--r-- | tests/utils.scm | 26 |
7 files changed, 134 insertions, 2 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 15dce46..8b26cb4 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,7 +1,9 @@ ((nil . ((compile-command . "make -j$(nproc)"))) (scheme-mode . - ((eval . (put 'sdl2:call-with-surface 'scheme-indent-function 1)) + ((eval . (put 'with-tests 'scheme-indent-function 1)) + (eval . (put 'test-group 'scheme-indent-function 1)) + (eval . (put 'sdl2:call-with-surface 'scheme-indent-function 1)) (eval . (put 'call-with-loaded-image 'scheme-indent-function 3)) (eval . (put 'with-blend-mode 'scheme-indent-function 1)) (eval . (put 'with-polygon-mode 'scheme-indent-function 1)) @@ -2,6 +2,8 @@ *.tar.gz *.tar.gz.asc *~ +*.log +*.trs /configure /config.status diff --git a/Makefile.am b/Makefile.am index 0c10d13..806157f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,13 @@ SOURCES = \ chickadee/scripting.scm \ chickadee.scm +TESTS = \ + tests/math/vector.scm + +TEST_EXTENSIONS = .scm +SCM_LOG_COMPILER = $(top_builddir)/test-env $(GUILE) +AM_SCM_LOG_FLAGS = --no-auto-compile -L "$(top_srcdir)" + EXTRA_DIST += \ COPYING \ run-example \ @@ -121,7 +128,8 @@ EXTRA_DIST += \ examples/images/serene-village.png \ examples/maps/example.tmx \ examples/maps/serene-village.tsx \ - examples/models/suzanne.obj + examples/models/suzanne.obj \ + tests/utils.scm dist_pkgdata_DATA = \ data/AUTHORS \ diff --git a/configure.ac b/configure.ac index a0dda9d..aa53707 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,7 @@ AM_SILENT_RULES([yes]) AC_PATH_PROG([GUILE], [guile]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env]) +AC_CONFIG_FILES([test-env], [chmod +x test-env]) AC_CONFIG_FILES([chickadee/config.scm]) # Prepare a version of $datadir that does not contain references to diff --git a/test-env.in b/test-env.in new file mode 100644 index 0000000..1ab197a --- /dev/null +++ b/test-env.in @@ -0,0 +1,5 @@ +#!/bin/sh + +"@abs_top_builddir@/pre-inst-env" "$@" + +exit $? diff --git a/tests/math/vector.scm b/tests/math/vector.scm new file mode 100644 index 0000000..e87c241 --- /dev/null +++ b/tests/math/vector.scm @@ -0,0 +1,88 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson <davet@gnu.org> +;;; +;;; Chickadee 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. +;;; +;;; Chickadee 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 this program. If not, see +;;; <http://www.gnu.org/licenses/>. + +(define-module (tests math vector) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee math) + #:use-module (chickadee math vector)) + +(with-tests "vector" + (test-group "2D vectors" + (test-assert "vec2=" + (vec2= (vec2 1.0 2.0) (vec2 1.0 2.0))) + (test-group "vec2/polar" + (test-equal (vec2/polar (vec2 1.0 1.0) 2.0 0.0) (vec2 3.0 1.0)) + (test-equal (vec2/polar (vec2 1.0 1.0) 2.0 (/ pi 2)) (vec2 1.0 3.0)) + (test-equal (vec2/polar (vec2 1.0 1.0) 2.0 pi) (vec2 -1.0 1.0)) + (test-equal (vec2/polar (vec2 1.0 1.0) 2.0 (* pi 1.5)) (vec2 1.0 -1.0)) + (test-equal (vec2/polar (vec2 1.0 1.0) 2.0 tau) (vec2 3.0 1.0))) + (test-group "vec2-magnitude" + (test-equal "normal case" + (vec2-magnitude (vec2 -3.0 4.0)) 5.0) + (test-equal "division by zero edge case" + (vec2-magnitude (vec2 0.0 0.0)) 0.0)) + (test-equal "vec2-dot" + (vec2-dot (vec2 1.0 2.0) (vec2 3.0 4.0)) 11.0) + (test-equal "vec2-cross" + (vec2-cross (vec2 1.0 2.0) (vec2 3.0 4.0)) -5.0) + (test-approximate "vec2-normalize" + (vec2-magnitude (vec2-normalize (vec2 3.7 4.9))) 1.0 0.001) + (test-group "vec2*" + (test-equal "vec2 * vec2" + (vec2* (vec2 2.0 3.0) (vec2 4.0 5.0)) (vec2 8.0 15.0)) + (test-equal "vec2 * scalar" + (vec2* (vec2 2.0 3.0) 4.0) (vec2 8.0 12.0))) + (test-group "vec2+" + (test-equal "vec2 + vec2" + (vec2+ (vec2 1.0 2.0) (vec2 3.0 4.0)) (vec2 4.0 6.0)) + (test-equal "vec2 + scalar" + (vec2+ (vec2 1.0 2.0) 3.0) (vec2 4.0 5.0))) + (test-group "vec2-" + (test-equal "vec2 - vec2" + (vec2- (vec2 1.0 2.0) (vec2 3.0 4.0)) (vec2 -2.0 -2.0)) + (test-equal "vec2 - scalar" + (vec2- (vec2 1.0 2.0) 3.0) (vec2 -2.0 -1.0)))) + (test-group "3D vectors" + (test-assert "vec3=" + (vec3= (vec3 1.0 2.0 3.0) (vec3 1.0 2.0 3.0))) + (test-group "vec3-magnitude" + (test-equal "normal case" + (vec3-magnitude (vec3 -2.0 3.0 -6.0)) 7.0) + (test-equal "division by zero edge case" + (vec3-magnitude (vec3 0.0 0.0 0.0)) 0.0)) + (test-equal "vec3-dot" + (vec3-dot (vec3 1.0 2.0 3.0) (vec3 4.0 5.0 6.0)) 32.0) + (test-equal "vec3-cross" + (vec3-cross (vec3 2.0 3.0 4.0) (vec3 5.0 6.0 7.0)) (vec3 -3.0 6.0 -3.0)) + (test-approximate "vec3-normalize" + (vec3-magnitude (vec3-normalize (vec3 3.7 4.9 9.2))) 1.0 0.001) + (test-group "vec3*" + (test-equal "vec3 * vec3" + (vec3* (vec3 2.0 3.0 4.0) (vec3 5.0 6.0 7.0)) (vec3 10.0 18.0 28.0)) + (test-equal "vec3 * scalar" + (vec3* (vec3 2.0 3.0 4.0) 5.0) (vec3 10.0 15.0 20.0))) + (test-group "vec3+" + (test-equal "vec3 + vec3" + (vec3+ (vec3 1.0 2.0 3.0) (vec3 4.0 5.0 6.0)) (vec3 5.0 7.0 9.0)) + (test-equal "vec3 + scalar" + (vec3+ (vec3 1.0 2.0 3.0) 4.0) (vec3 5.0 6.0 7.0))) + (test-group "vec3-" + (test-equal "vec3 - vec3" + (vec3- (vec3 1.0 2.0 3.0) (vec3 4.0 5.0 6.0)) (vec3 -3.0 -3.0 -3.0)) + (test-equal "vec3 - scalar" + (vec3- (vec3 1.0 2.0 3.0) 4.0) (vec3 -3.0 -2.0 -1.0))))) diff --git a/tests/utils.scm b/tests/utils.scm new file mode 100644 index 0000000..3eb89aa --- /dev/null +++ b/tests/utils.scm @@ -0,0 +1,26 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson <davet@gnu.org> +;;; +;;; Chickadee 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. +;;; +;;; Chickadee 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 this program. If not, see +;;; <http://www.gnu.org/licenses/>. + +(define-module (tests utils) + #:use-module (srfi srfi-64) + #:export (with-tests)) + +(define-syntax-rule (with-tests name body ...) + (begin + (test-begin name) + body ... + (exit (zero? (test-runner-fail-count (test-end)))))) |