From 15d838868b6dd7993d3f04c0a22bd9addaf731af Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 6 Oct 2021 17:11:01 -0400 Subject: Collapse test hierarchy into a single directory. --- tests/array-list.scm | 42 ++++++++++++++++ tests/data/array-list.scm | 42 ---------------- tests/data/heap.scm | 33 ------------- tests/data/quadtree.scm | 122 ---------------------------------------------- tests/data/queue.scm | 31 ------------ tests/heap.scm | 33 +++++++++++++ tests/math/vector.scm | 93 ----------------------------------- tests/quadtree.scm | 122 ++++++++++++++++++++++++++++++++++++++++++++++ tests/queue.scm | 31 ++++++++++++ tests/vector.scm | 93 +++++++++++++++++++++++++++++++++++ 10 files changed, 321 insertions(+), 321 deletions(-) create mode 100644 tests/array-list.scm delete mode 100644 tests/data/array-list.scm delete mode 100644 tests/data/heap.scm delete mode 100644 tests/data/quadtree.scm delete mode 100644 tests/data/queue.scm create mode 100644 tests/heap.scm delete mode 100644 tests/math/vector.scm create mode 100644 tests/quadtree.scm create mode 100644 tests/queue.scm create mode 100644 tests/vector.scm (limited to 'tests') diff --git a/tests/array-list.scm b/tests/array-list.scm new file mode 100644 index 0000000..3907b02 --- /dev/null +++ b/tests/array-list.scm @@ -0,0 +1,42 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson +;;; +;;; 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 +;;; . + +(define-module (tests array-list) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee data array-list)) + +(with-tests "array-list" + ;; Using an initial capacity of 2 to force an expansion when adding + ;; the third element. + (let ((a (make-array-list 2))) + (array-list-push! a 'a) + (array-list-push! a 'b) + (array-list-push! a 'c) + (test-equal "array-list-fold" + (array-list-fold (lambda (i item prev) + (cons item prev)) + '() a) + '(c b a)) + (test-equal "array-list-push!" (array-list-size a) 3) + (test-equal "array-list-pop!" (array-list-pop! a) 'c) + (array-list-set! a 1 'd) + (test-equal "array-list-set!" (array-list-ref a 1) 'd) + (array-list-delete! a 'a) + (test-equal "array-list-delete!" (array-list-ref a 0) 'd) + (array-list-clear! a) + (test-assert "array-list-clear!" (array-list-empty? a)))) diff --git a/tests/data/array-list.scm b/tests/data/array-list.scm deleted file mode 100644 index f93b6fa..0000000 --- a/tests/data/array-list.scm +++ /dev/null @@ -1,42 +0,0 @@ -;;; Chickadee Game Toolkit -;;; Copyright © 2021 David Thompson -;;; -;;; 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 -;;; . - -(define-module (tests data array-list) - #:use-module (tests utils) - #:use-module (srfi srfi-64) - #:use-module (chickadee data array-list)) - -(with-tests "array-list" - ;; Using an initial capacity of 2 to force an expansion when adding - ;; the third element. - (let ((a (make-array-list 2))) - (array-list-push! a 'a) - (array-list-push! a 'b) - (array-list-push! a 'c) - (test-equal "array-list-fold" - (array-list-fold (lambda (i item prev) - (cons item prev)) - '() a) - '(c b a)) - (test-equal "array-list-push!" (array-list-size a) 3) - (test-equal "array-list-pop!" (array-list-pop! a) 'c) - (array-list-set! a 1 'd) - (test-equal "array-list-set!" (array-list-ref a 1) 'd) - (array-list-delete! a 'a) - (test-equal "array-list-delete!" (array-list-ref a 0) 'd) - (array-list-clear! a) - (test-assert "array-list-clear!" (array-list-empty? a)))) diff --git a/tests/data/heap.scm b/tests/data/heap.scm deleted file mode 100644 index 351d20c..0000000 --- a/tests/data/heap.scm +++ /dev/null @@ -1,33 +0,0 @@ -;;; Chickadee Game Toolkit -;;; Copyright © 2021 David Thompson -;;; -;;; 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 -;;; . - -(define-module (tests data heap) - #:use-module (tests utils) - #:use-module (srfi srfi-64) - #:use-module (chickadee data heap)) - -(with-tests "heap" - (let ((h (make-heap))) - (heap-insert! h 3) - (heap-insert! h 1) - (heap-insert! h 2) - (test-equal "heap-insert!" (heap-size h) 3) - (test-equal "heap-min!" (heap-min h) 1) - (heap-remove! h) - (test-equal "heap-remove!" (heap-min h) 2) - (heap-clear! h) - (test-assert "heap-clear!" (heap-empty? h)))) diff --git a/tests/data/quadtree.scm b/tests/data/quadtree.scm deleted file mode 100644 index 1dd37cc..0000000 --- a/tests/data/quadtree.scm +++ /dev/null @@ -1,122 +0,0 @@ -;;; Chickadee Game Toolkit -;;; Copyright © 2021 David Thompson -;;; -;;; 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 -;;; . - -(define-module (tests data quadtree) - #:use-module (tests utils) - #:use-module (srfi srfi-64) - #:use-module (chickadee data quadtree) - #:use-module (chickadee math rect)) - -(define (quadtree) - (make-quadtree (make-rect 0 0 100 100) #:max-size 3 #:max-depth 2)) - -(with-tests "quadtree" - (test-group "quadtree-insert!" - (test-group "inserting a single object" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (test-equal (quadtree-size q) 1) - (test-assert (quadtree-leaf? q)))) - (test-group "inserting maximum objects for one node" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'baz) - (test-equal (quadtree-size q) 3) - (test-assert (quadtree-leaf? q)))) - (test-group "splitting where all objects move to child nodes" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'baz) - (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'frob) - (test-equal (quadtree-size q) 0) - (test-assert (not (quadtree-leaf? q))))) - (test-group "splitting where all objects stay in parent node" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'baz) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'frob) - (test-equal (quadtree-size q) 4) - (test-assert (quadtree-leaf? q))))) - (test-group "quadtree-delete!" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (quadtree-delete! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (test-equal "deleting from a root node with 1 object" - (quadtree-size q) 0)) - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 30.0 10.0 10.0 10.0) 'baz) - (quadtree-delete! q (make-rect 30.0 10.0 10.0 10.0) 'bar) - (test-equal "deleting from a root node with multiple objects" - (quadtree-size q) 2)) - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 15.0 10.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'baz) - (quadtree-insert! q (make-rect 25.0 10.0 10.0 10.0) 'frob) - (test-assert "deleting from a lower node" - (quadtree-delete! q (make-rect 25.0 10.0 10.0 10.0) 'frob))) - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (quadtree-insert! q (make-rect 15.0 10.0 10.0 10.0) 'bar) - (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'baz) - (quadtree-insert! q (make-rect 25.0 10.0 10.0 10.0) 'frob) - (quadtree-delete! q (make-rect 10.0 10.0 10.0 10.0) 'foo) - (test-assert "clearing out a level" - (quadtree-leaf? (quadtree-q3 q))))) - (test-group "quadtree-fold" - (test-equal "rect within a single leaf node at level 0" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'one) - (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'two) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'three) - (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'four) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) - (quadtree-fold q (make-rect 0.0 0.0 40.0 40.0) '() cons)) - '(three five)) - (test-equal "rect spans multiple nodes at level 1" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'one) - (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'two) - (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'three) - (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'four) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) - (quadtree-fold q (make-rect 0.0 0.0 60.0 40.0) '() cons)) - '(four three five)) - (test-equal "rect within a single leaf node at level 2" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 80.0 80.0 10.0 10.0) 'one) - (quadtree-insert! q (make-rect 60.0 80.0 10.0 10.0) 'two) - (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'three) - (quadtree-insert! q (make-rect 80.0 60.0 10.0 10.0) 'four) - (quadtree-insert! q (make-rect 65.0 65.0 10.0 10.0) 'five) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'six) - (quadtree-fold q (make-rect 76.0 76.0 20.0 20.0) '() cons)) - '(one five six)) - (test-equal "rect spans multiple nodes at level 2" - (let ((q (quadtree))) - (quadtree-insert! q (make-rect 70.0 70.0 10.0 10.0) 'one) - (quadtree-insert! q (make-rect 60.0 80.0 10.0 10.0) 'two) - (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'three) - (quadtree-insert! q (make-rect 80.0 60.0 10.0 10.0) 'four) - (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) - (quadtree-fold q (make-rect 70.0 70.0 20.0 20.0) '() cons)) - '(four three two one five)))) diff --git a/tests/data/queue.scm b/tests/data/queue.scm deleted file mode 100644 index 0ccc808..0000000 --- a/tests/data/queue.scm +++ /dev/null @@ -1,31 +0,0 @@ -;;; Chickadee Game Toolkit -;;; Copyright © 2021 David Thompson -;;; -;;; 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 -;;; . - -(define-module (tests data queue) - #:use-module (tests utils) - #:use-module (srfi srfi-64) - #:use-module (chickadee data queue)) - -(with-tests "queue" - (let ((q (make-queue))) - (enqueue! q 'a) - (enqueue! q 'b) - (enqueue! q 'c) - (test-equal "enqueue!" (queue-length q) 3) - (test-equal "dequeue!" (dequeue! q) 'a) - (queue-clear! q) - (test-assert "queue-clear!" (queue-empty? q)))) diff --git a/tests/heap.scm b/tests/heap.scm new file mode 100644 index 0000000..9c87384 --- /dev/null +++ b/tests/heap.scm @@ -0,0 +1,33 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson +;;; +;;; 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 +;;; . + +(define-module (tests heap) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee data heap)) + +(with-tests "heap" + (let ((h (make-heap))) + (heap-insert! h 3) + (heap-insert! h 1) + (heap-insert! h 2) + (test-equal "heap-insert!" (heap-size h) 3) + (test-equal "heap-min!" (heap-min h) 1) + (heap-remove! h) + (test-equal "heap-remove!" (heap-min h) 2) + (heap-clear! h) + (test-assert "heap-clear!" (heap-empty? h)))) diff --git a/tests/math/vector.scm b/tests/math/vector.scm deleted file mode 100644 index c3fc900..0000000 --- a/tests/math/vector.scm +++ /dev/null @@ -1,93 +0,0 @@ -;;; Chickadee Game Toolkit -;;; Copyright © 2021 David Thompson -;;; -;;; 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 -;;; . - -(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-group "vec2-cross" - (test-equal "same line" - (vec2-cross (vec2 1.0 2.0) (vec2 2.0 4.0)) 0.0) - (test-equal "clockwise" - (vec2-cross (vec2 1.0 2.0) (vec2 0.0 2.0)) 2.0) - (test-equal "counter-clockwise" - (vec2-cross (vec2 1.0 2.0) (vec2 2.0 0.0)) -4.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/quadtree.scm b/tests/quadtree.scm new file mode 100644 index 0000000..fa578cd --- /dev/null +++ b/tests/quadtree.scm @@ -0,0 +1,122 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson +;;; +;;; 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 +;;; . + +(define-module (tests quadtree) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee data quadtree) + #:use-module (chickadee math rect)) + +(define (quadtree) + (make-quadtree (make-rect 0 0 100 100) #:max-size 3 #:max-depth 2)) + +(with-tests "quadtree" + (test-group "quadtree-insert!" + (test-group "inserting a single object" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (test-equal (quadtree-size q) 1) + (test-assert (quadtree-leaf? q)))) + (test-group "inserting maximum objects for one node" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'baz) + (test-equal (quadtree-size q) 3) + (test-assert (quadtree-leaf? q)))) + (test-group "splitting where all objects move to child nodes" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'baz) + (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'frob) + (test-equal (quadtree-size q) 0) + (test-assert (not (quadtree-leaf? q))))) + (test-group "splitting where all objects stay in parent node" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'baz) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'frob) + (test-equal (quadtree-size q) 4) + (test-assert (quadtree-leaf? q))))) + (test-group "quadtree-delete!" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (quadtree-delete! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (test-equal "deleting from a root node with 1 object" + (quadtree-size q) 0)) + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 30.0 10.0 10.0 10.0) 'baz) + (quadtree-delete! q (make-rect 30.0 10.0 10.0 10.0) 'bar) + (test-equal "deleting from a root node with multiple objects" + (quadtree-size q) 2)) + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 15.0 10.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'baz) + (quadtree-insert! q (make-rect 25.0 10.0 10.0 10.0) 'frob) + (test-assert "deleting from a lower node" + (quadtree-delete! q (make-rect 25.0 10.0 10.0 10.0) 'frob))) + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (quadtree-insert! q (make-rect 15.0 10.0 10.0 10.0) 'bar) + (quadtree-insert! q (make-rect 20.0 10.0 10.0 10.0) 'baz) + (quadtree-insert! q (make-rect 25.0 10.0 10.0 10.0) 'frob) + (quadtree-delete! q (make-rect 10.0 10.0 10.0 10.0) 'foo) + (test-assert "clearing out a level" + (quadtree-leaf? (quadtree-q3 q))))) + (test-group "quadtree-fold" + (test-equal "rect within a single leaf node at level 0" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'one) + (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'two) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'three) + (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'four) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) + (quadtree-fold q (make-rect 0.0 0.0 40.0 40.0) '() cons)) + '(three five)) + (test-equal "rect spans multiple nodes at level 1" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'one) + (quadtree-insert! q (make-rect 10.0 60.0 10.0 10.0) 'two) + (quadtree-insert! q (make-rect 10.0 10.0 10.0 10.0) 'three) + (quadtree-insert! q (make-rect 60.0 10.0 10.0 10.0) 'four) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) + (quadtree-fold q (make-rect 0.0 0.0 60.0 40.0) '() cons)) + '(four three five)) + (test-equal "rect within a single leaf node at level 2" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 80.0 80.0 10.0 10.0) 'one) + (quadtree-insert! q (make-rect 60.0 80.0 10.0 10.0) 'two) + (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'three) + (quadtree-insert! q (make-rect 80.0 60.0 10.0 10.0) 'four) + (quadtree-insert! q (make-rect 65.0 65.0 10.0 10.0) 'five) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'six) + (quadtree-fold q (make-rect 76.0 76.0 20.0 20.0) '() cons)) + '(one five six)) + (test-equal "rect spans multiple nodes at level 2" + (let ((q (quadtree))) + (quadtree-insert! q (make-rect 70.0 70.0 10.0 10.0) 'one) + (quadtree-insert! q (make-rect 60.0 80.0 10.0 10.0) 'two) + (quadtree-insert! q (make-rect 60.0 60.0 10.0 10.0) 'three) + (quadtree-insert! q (make-rect 80.0 60.0 10.0 10.0) 'four) + (quadtree-insert! q (make-rect 45.0 45.0 10.0 10.0) 'five) + (quadtree-fold q (make-rect 70.0 70.0 20.0 20.0) '() cons)) + '(four three two one five)))) diff --git a/tests/queue.scm b/tests/queue.scm new file mode 100644 index 0000000..03eaa01 --- /dev/null +++ b/tests/queue.scm @@ -0,0 +1,31 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson +;;; +;;; 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 +;;; . + +(define-module (tests queue) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee data queue)) + +(with-tests "queue" + (let ((q (make-queue))) + (enqueue! q 'a) + (enqueue! q 'b) + (enqueue! q 'c) + (test-equal "enqueue!" (queue-length q) 3) + (test-equal "dequeue!" (dequeue! q) 'a) + (queue-clear! q) + (test-assert "queue-clear!" (queue-empty? q)))) diff --git a/tests/vector.scm b/tests/vector.scm new file mode 100644 index 0000000..aba5fd1 --- /dev/null +++ b/tests/vector.scm @@ -0,0 +1,93 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2021 David Thompson +;;; +;;; 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 +;;; . + +(define-module (tests 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-group "vec2-cross" + (test-equal "same line" + (vec2-cross (vec2 1.0 2.0) (vec2 2.0 4.0)) 0.0) + (test-equal "clockwise" + (vec2-cross (vec2 1.0 2.0) (vec2 0.0 2.0)) 2.0) + (test-equal "counter-clockwise" + (vec2-cross (vec2 1.0 2.0) (vec2 2.0 0.0)) -4.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))))) -- cgit v1.2.3