Permalink
Browse files

Move test suites to separate files

  • Loading branch information...
uint committed Sep 4, 2017
1 parent 4956424 commit 47a80731f7aab6e5c81026b041d86f38c2a70a32
Showing with 51 additions and 42 deletions.
  1. +3 −1 quasirpg.asd
  2. +15 −0 tests/char-gen-tests.lisp
  3. +0 −41 tests/main.lisp
  4. +33 −0 tests/random-utils-tests.lisp
View
@@ -17,4 +17,6 @@
:components ((:module "tests"
:serial t
:components ((:file "package")
(:file "main")))))
(:file "main")
(:file "random-utils-tests")
(:file "char-gen-tests")))))
View
@@ -0,0 +1,15 @@
;;;; tests/char-gen-tests.lisp
(in-package #:quasirpg-tests)
(def-suite character-generation-tests
:description "Test the character generation stuff."
:in all-tests)
(in-suite character-generation-tests)
(test make-character-tests
:description "Test the `make-character` function."
(let ((name (quasirpg::name (quasirpg::make-character "tom" '("str" "dex")))))
(is (string= "Tom" name)
"MAKE-CHARACTER should capitalize the name \"tom\", but we got: ~s" name)))
View
@@ -14,44 +14,3 @@
(min (1- most-negative-long-float)))
(lambda () (+ min (random (1+ (- max min))))))
(def-suite random-utils-tests
:description "Test the random utilities."
:in all-tests)
(in-suite random-utils-tests)
(test dice-tests
:description "Test the `roll-dice` function."
(is (= 1 (quasirpg::roll-dice 1 1)))
(is (= 3 (quasirpg::roll-dice 3 1)))
(for-all ((n (gen-integer :min 1 :max 10))
(sides (gen-integer :min 1 :max 10)))
"Test whether calls with random positive integers give results within expected bounds."
(let ((min n)
(max (* n sides))
(result (quasirpg::roll-dice n sides)))
(is (<= min result))
(is (>= max result))))
(for-all ((valid-float (gen-long-float :min 1 :max 100)))
"Test whether floats are rounded down."
(is (= (floor valid-float) (quasirpg::roll-dice valid-float 1)))
(is (>= (floor valid-float) (quasirpg::roll-dice 1 valid-float))))
(for-all ((invalid-int (gen-integer :max 0))
(invalid-int2 (gen-integer :max 0))
(valid-int (gen-integer :min 1)))
"Test whether non-positive numbers signal SIMPLE-TYPE-ERROR."
(signals simple-type-error (quasirpg::roll-dice valid-int invalid-int))
(signals simple-type-error (quasirpg::roll-dice invalid-int valid-int))
(signals simple-type-error (quasirpg::roll-dice invalid-int invalid-int2))))
(def-suite character-generation-tests
:description "Test the random utilities."
:in all-tests)
(in-suite character-generation-tests)
(test make-character-tests
:description "Test the `make-character` function."
(let ((name (quasirpg::name (quasirpg::make-character "tom" '("str" "dex")))))
(is (string= "Tom" name)
"MAKE-CHARACTER should capitalize the name \"tom\", but we got: ~s" name)))
@@ -0,0 +1,33 @@
;;;; tests/random-utils-tests.lisp
(in-package #:quasirpg-tests)
(def-suite random-utils-tests
:description "Test the random utilities."
:in all-tests)
(in-suite random-utils-tests)
(test dice-tests
:description "Test the `roll-dice` function."
(is (= 1 (quasirpg::roll-dice 1 1)))
(is (= 3 (quasirpg::roll-dice 3 1)))
(for-all ((n (gen-integer :min 1 :max 10))
(sides (gen-integer :min 1 :max 10)))
"Test whether calls with random positive integers give results within expected bounds."
(let ((min n)
(max (* n sides))
(result (quasirpg::roll-dice n sides)))
(is (<= min result))
(is (>= max result))))
(for-all ((valid-float (gen-long-float :min 1 :max 100)))
"Test whether floats are rounded down."
(is (= (floor valid-float) (quasirpg::roll-dice valid-float 1)))
(is (>= (floor valid-float) (quasirpg::roll-dice 1 valid-float))))
(for-all ((invalid-int (gen-integer :max 0))
(invalid-int2 (gen-integer :max 0))
(valid-int (gen-integer :min 1)))
"Test whether non-positive numbers signal SIMPLE-TYPE-ERROR."
(signals simple-type-error (quasirpg::roll-dice valid-int invalid-int))
(signals simple-type-error (quasirpg::roll-dice invalid-int valid-int))
(signals simple-type-error (quasirpg::roll-dice invalid-int invalid-int2))))

0 comments on commit 47a8073

Please sign in to comment.