dds/rs-tests.rkt
Sergiu Ivanov 77c0106ea2 rs: Add some functions for showing RS as Org tables.
Also add an example to example.org.
2020-03-01 21:10:01 +01:00

25 lines
996 B
Racket

#lang racket
;;; Tests for dds/rs.
(require rackunit "rs.rkt")
(test-case "Basic definitions"
(let* ([r1 (reaction (set 'x) (set 'y) (set 'z))]
[r2 (reaction (set 'x) (set) (set 'y))]
[rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2)))]
[s1 (set 'x 'z)]
[s2 (set 'x 'y)])
(check-true (enabled? r1 s1))
(check-false (enabled? r1 s2))
(check-equal? (list-enabled rs s1) '(a b))
(check-equal? (list-enabled rs s2) '(b))
(check-equal? (union-products rs '(a b)) (set 'y 'z))
(check-equal? (apply-rs rs s1) (set 'y 'z))
(check-equal? (apply-rs rs s2) (set 'y))))
(test-case "Org-mode interaction"
(check-equal? (ht-str-triples->rs #hash((a . ("x t" "y" "z"))))
(make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))
(check-equal? (rs->ht-str-triples (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))
#hash((a . ("t x" "y" "z")))))