From 2ebd6d2a0f1cfddee5e7869dcfd6077b1864c692 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Fri, 2 Jul 2021 00:45:36 +0100 Subject: [PATCH] writing tests for validating light reading data. These tests check the shape of the data produced by the light meters in the welding in booths in Ritherdon. I've place a note with the factory3 tests explaining the reason why there is a factory3 in the system but there is not actual light meter in the third welding booth in Ritherdon. --- tests/main.lisp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/main.lisp diff --git a/tests/main.lisp b/tests/main.lisp new file mode 100644 index 0000000..73cd9e1 --- /dev/null +++ b/tests/main.lisp @@ -0,0 +1,76 @@ +;;;; tests/main.lisp + +(in-package #:ritherdon-rest-tests) + +(def-suite all-tests + :description "The master suite of all ritherdon-rest tests.") + +(in-suite all-tests) + +;; These two examples show the 'full' call to the fiveAm test +;; functions. This is just for reference. The 'namespace' is already +;; 'imported' in 'package.lisp'. + +;; (fiveam:test sum-1 +;; (fiveam:is (= 3 (+ 1 2)))) + +;; (fiveam:run!) + +;; How you would normally create the tests -- with fiveAM already +;; set-up in 'package.lisp' and not needing to be explicit about it +;; here. This is similar to 'using static' in C#. + +(defun test-quasi() + (run! 'all-tests)) + +(test factory-1-light-reading-data + :description "Validates the (reading) data produced by `FACTORY1'." + (let ((data (ritherdon-rest:parse-request "/status/latest/1"))) + ;; Data should look something like: + ;; ((:ID . 79) (:STATUS . "off") (:TIME . "2021-07-01T16:00:001")). + (is (= 3 (length data))) + (is (equal t (consp data))) + (is (equal ':id (first (nth 0 data)))) + (is (equal ':status (first (nth 1 data)))) + (is (equal ':time (first (nth 2 data)))) + (is (equal t (typep (cdr (car data)) 'integer))) ; :id number + (is (> (cdr (car data)) 0)) + (is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value + (is (equal t (or (string-equal (cdr (car (cdr data))) "off") + (string-equal (cdr (car (cdr data))) "on")))))) + +(test factory-2-light-reading-data + :description "Validates the (reading) data produced by `FACTORY2'." + (let ((data (ritherdon-rest:parse-request "/status/latest/2"))) + ;; Data should look something like: + ;; ((:ID . 79) (:STATUS . "off") (:TIME . "2021-07-01T16:00:001")). + (is (= 3 (length data))) + (is (equal t (consp data))) + (is (equal ':id (first (nth 0 data)))) + (is (equal ':status (first (nth 1 data)))) + (is (equal ':time (first (nth 2 data)))) + (is (equal t (typep (cdr (car data)) 'integer))) ; :id number + (is (> (cdr (car data)) 0)) + (is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value + (is (equal t (or (string-equal (cdr (car (cdr data))) "off") + (string-equal (cdr (car (cdr data))) "on")))))) + +(test factory-3-light-reading-data + :description "Validates the (reading) data produced by `FACTORY3'." + (let ((data (ritherdon-rest:parse-request "/status/latest/3"))) + ;; Ritherdon has a third welding booth but it was not included in + ;; the art project so no light sensor was installed. Therefore, + ;; this should always return the 'default/initial/seed' data + ;; readings. + ;; Data should still take the same shape as factory1 and factory 2: + ;; ((:ID . 1) (:STATUS . "off") (:TIME . "2021-04-26T20:42:19.400868")). + (is (= 3 (length data))) + (is (equal t (consp data))) + (is (equal ':id (first (nth 0 data)))) + (is (equal ':status (first (nth 1 data)))) + (is (equal ':time (first (nth 2 data)))) + (is (equal t (typep (cdr (car data)) 'integer))) ; :id number + (is (> (cdr (car data)) 0)) + (is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value + (is (equal t (or (string-equal (cdr (car (cdr data))) "off") + (string-equal (cdr (car (cdr data))) "on"))))))