cl-scopes/test/test-csys.lisp

66 lines
2.1 KiB
Common Lisp

;;;; cl-scopes/test-csys - testing for the scopes-csys system.
(defpackage :scopes/test-csys
(:use :common-lisp)
(:local-nicknames (:alx :alexandria)
(:actor :scopes/core/actor)
(:async :scopes/util/async)
(:config :scopes/config)
(:core :scopes/core)
(:csys :scopes/csys)
(:logging :scopes/logging)
(:message :scopes/core/message)
(:shape :scopes/shape)
(:util :scopes/util)
(:t :scopes/testing))
(:export #:run)
(:import-from :scopes/testing #:deftest #:== #:!= #:in-seq))
(in-package :scopes/test-csys)
;;;; testing environment
(defclass test-env (csys:environment)
((test-suite :reader test-suite :initarg :test-suite)))
(defun probe (msg state syns env)
(let ((t:*test-suite* (test-suite env))
(val (shape:data msg)))
(util:lgi msg state)
(unless (consp val)
(let ((nst (in-seq val state :remove t)))
(csys:update-neuron #'probe nst syns env)))))
(defvar *probe* nil)
(defun add (msg state syns env)
(list msg (+ (shape:data msg) state) syns env))
;;;; test runner
(defun run ()
(async:init)
(let* ((t:*test-suite* (make-instance 't:test-suite :name "csys"))
(csys:*environment* (make-instance 'test-env :test-suite t:*test-suite*))
(*probe* (actor:create
(csys:neuron #'probe '(1 3 4 5)
nil csys:*environment*))))
(load (t:test-path "config-csys" "etc"))
(core:setup-services)
(unwind-protect
(progn
(test-init))
(sleep 0.1)
(async:finish)
(t:show-result))))
(deftest test-init ()
(csys:init *probe*)
(csys:send-message '(:csys :sensor :init :zero) '(:std :s1))
(csys:send-message '(:csys :sensor :init :zero) '(:std :s2))
(sleep 0.1)
(csys:send-message '(:csys :add :std :s1) 1)
(csys:send-message '(:csys :add :std :s1) 3)
(csys:send-message '(:csys :sub :std :s2) 4)
(csys:send-message '(:csys :add :std :s2) 5)
)