(module test-relations mzscheme (require "relations.ss" (planet "test.ss" ("schematics" "schemeunit.plt" 2)) (planet "text-ui.ss" ("schematics" "schemeunit.plt" 2)) (only (lib "1.ss" "srfi") lset=)) (provide check-relation relations-test-suite) (define-simple-check (check-relation a-rel val-lists) (lset= equal? (relation->list a-rel) val-lists)) (define relations-test-suite (test-suite "relations.ss tests" (test-equal? "checking tuple creation" (tuple->list (make-tuple "hola")) '("hola")) (test-equal? "checking tuple creation" (tuple->list (make-tuple "hola")) '("hola")) (test-true "equality of tuples" (tuple-equal? (make-tuple "hello") (make-tuple "hello"))) (test-false "inequality of tuples" (tuple-equal? (make-tuple 1 2 3) (make-tuple "one" 2 "three"))) (test-case "just create a relation, check its size" (check-equal? (relation-size (make-relation (make-tuple "hello" "world"))) 1)) (test-case "just create a relation, check its size 2" (check-equal? (relation-size (make-relation (make-tuple "hello" "world") (make-tuple "testing"))) 2)) (test-equal? "convert a relation to a list" (relation->list (make-relation (make-tuple "simple" "tuple" "test"))) '(("simple" "tuple" "test"))) (test-case "create two relations, and add them together" (check-relation (relation-add (list->relation '((a 1))) (list->relation '((b 2)))) '((a 1) (b 2)))) (test-case "check that relations act as sets of tuples, and not sequences" (check-relation (relation-add (list->relation '((a 1))) (list->relation '((a 1)))) '((a 1)))) (test-case "relational subtraction" (check-relation (relation-subtract (list->relation '((a 1) (b 2) (c 3))) (list->relation '((b 2)))) '((a 1) (c 3)))) (test-case "simple relational cross-product" (check-relation (relation-cross (list->relation '((a))) (list->relation '((b)))) '((a b)))) (test-case "another relational cross-product" (check-relation (relation-cross (list->relation '((a) (b) (c))) (list->relation '((1) (2) (3)))) '((a 1) (a 2) (a 3) (b 1) (b 2) (b 3) (c 1) (c 2) (c 3)))) (test-case "natural join" (check-relation (relation-natural-join (list->relation '((foo a))) (list->relation '((a 1) (b 2)))) '((foo 1)))) (test-case "another natural join using strings" (check-relation (relation-natural-join (list->relation `((foo , (string #\a)))) (list->relation '(("a" 1) (b 2)))) '((foo 1)))) (test-case "context-set! and context-get" (let ([context (make-context)]) (context-set! context 'sample (list->relation '((x) (y) (z)))) (check-relation (context-get context 'sample) '((x) (y) (z))))))))