diff options
| -rw-r--r-- | tests/test.lisp | 67 | ||||
| -rw-r--r-- | transacc.asd | 14 |
2 files changed, 79 insertions, 2 deletions
diff --git a/tests/test.lisp b/tests/test.lisp new file mode 100644 index 0000000..f2136d6 --- /dev/null +++ b/tests/test.lisp @@ -0,0 +1,67 @@ +(in-package :cl-user) +(defpackage transacc-tests + (:use :cl + :fiveam)) +(in-package :transacc-tests) + +(def-suite transacc-suite + :description "Test transacc") + + +;;; TESTING COMMODITIES +(def-suite* commodities-suite + :description "Test object and methods for commodities" + :in transacc-suite) + +;; we make sure creating a commodity returns one +(test commodity-creation + (let ((c1 (commodities:new-commodity "apple" 1)) + (c2 (commodities:new-commodity "pear" 4)) + (c3 (commodities:new-commodity "petrol" -3)) + (c4 (commodities:new-commodity "void" 0))) + (is (equal (type-of c1) 'commodities::commodity)) + (is (equal (type-of c2) 'commodities::commodity)) + (is (eq c3 nil)) + (is (eq c4 nil)))) + +;; we make sure a commodity created with given values +;; in fact contains said values +(test commodity-values + (let ((c (commodities:new-commodity "car" 10000))) + (is (equal (commodities:name c) "car")) + (is (= (commodities:price c) 10000)))) + + +;;; TESTING INVENTORY +(def-suite* inventory-suite + :description "Test object and methods for inventory" + :in transacc-suite) + +;; test for creation of inventories +(test inventory-creation + (let ((i1 (inventory:new-inventory 100)) + (i2 (inventory:new-inventory 25)) + (i3 (inventory:new-inventory -100)) + (i4 (inventory:new-inventory 0))) + (is (eq (type-of i1) 'inventory::inventory)) + (is (eq (type-of i2) 'inventory::inventory)) + (is (eq i3 nil)) + (is (eq i4 nil)))) + +;; test for init values +(test inventory-init-values + (let ((i (inventory:new-inventory 100))) + (is (= (inventory::size i) 100)) + (is (= (inventory:filled i) 0)) + (is (eq (inventory::items i) nil)))) + +;; test add and substract +(test inventory-add-and-substract + (let ((i (inventory:new-inventory 100)) + (c (commodities:new-commodity "apple" 2))) + (inventory:add-item i c 10) + (is (= (inventory:filled i) 10)) + (is (equal (inventory:remove-item i "apple" 4) + (cons c 4))))) + +;; creating inventory adding diff --git a/transacc.asd b/transacc.asd index ad44aae..a6e1934 100644 --- a/transacc.asd +++ b/transacc.asd @@ -8,8 +8,18 @@ :components ((:file "main" :depends-on ("game")) (:file "game" :depends-on ("zone" "player")) - (:file "zone" :depends-on ("commodities")) (:file "player" :depends-on ("commodities" "inventory")) + (:file "zone" :depends-on ("commodities")) (:file "inventory" :depends-on ("commodities")) (:file "commodities")))) - :description "Buy and sell to greatness") + :description "Buy and sell to greatness" + :in-order-to ((test-op (test-op "transacc/tests")))) + +(asdf:defsystem "transacc/tests" + :depends-on ("transacc" "fiveam") + :components ((:module "tests" + :components + ((:file "test")))) + :perform (test-op (op c) + (symbol-call :fiveam :run! + (find-symbol* :transacc-suite :transacc-tests)))) |
