(define-test-module (test module sph storage dg dictionary) (import (sph random-data) (sph storage dg) (test helper sph storage dg) (sph storage dg dictionary)) (define (test-dg-ds-dictionary inp exp) (list-set-equal? (list->alist inp) (dg-ds-dictionary-read->alist (apply dg-ds-dictionary inp)))) (define (test-dg-ds-dictionary-add inp exp) (let (ide (apply dg-ds-dictionary (first inp))) (each (l (ele) (dg-ds-dictionary-add (list ide) (list (first ele)) (list (tail ele)))) (tail inp)) (if (list-set-equal? exp (dg-ds-dictionary-read->alist ide)) exp (dg-ds-dictionary-read->alist ide)))) (define (test-dg-ds-dictionary-keys) (let (associations (map-integers 4 (l (n) (cons (+ 1 n) (+ n 100))))) (list-set-equal? (map first associations) (dg-ds-dictionary-keys (dg-ds-dictionary-from-alist associations))))) (define (test-dg-ds-dictionary-ref) (eqv? 4 (simplify (dg-ds-dictionary-ref (list (dg-ds-dictionary 1 2 3 4)) (list 3))))) (define (test-dg-ds-dictionary-remove) (and (equal? (list (cons 1 2)) (apply dg-ds-dictionary-read->alist (dg-ds-dictionary-remove (list (dg-ds-dictionary 1 2 3 4)) (list 3)))) (let (dict-2 (dg-ds-dictionary-remove (list (dg-ds-dictionary 1 2 3 (list 4 5))) (list 3) (list 4))) (equal? (list 5) (dg-ds-dictionary-ref dict-2 (list 3)))))) (define (test-dg-ds-dictionary-set!) (equal? (list 5) (dg-ds-dictionary-ref (dg-ds-dictionary-set! (list (dg-ds-dictionary 1 2 3 4)) (list 3) (list 5)) (list 3)))) (define (test-dg-ds-dictionary-value->key) (and (equal? (list 3) (dg-ds-dictionary-value->key (list (dg-ds-dictionary 1 2 3 4)) (list 4))) (not (equal? (list 5) (dg-ds-dictionary-value->key (list (dg-ds-dictionary 1 2 3 4)) (list 4)))))) dg-ds-dictionary-set! (dg-ds-dictionary (1 2 3 4) #t) (dg-ds-dictionary-add ((1 2 3 4) (5 . 6) (3 . 4)) ((5 . 6) (3 . 4) (1 . 2))) dg-ds-dictionary-keysdg-ds-dictionary-ref dg-ds-dictionary-remove dg-ds-dictionary-value->key (define-test (dictionary) (dg-txn-call-write (l (txn) (let* ( (size-before (test-helper-dg-count-btree-entries)) (names (test-helper-dg-data-random-string 2)) (passwords (test-helper-dg-data-random-string 2)) (user-ids (map (l (a b) (user-create txn a b)) names passwords))) (assert-and (assert-true "exists" (every (l (a) (user-exists? txn a)) names)) (assert-true "id->name" (list-set-equal? names (user-id->name txn user-ids))) (assert-true "name->id" (list-set-equal? user-ids (user-name->id txn names))) (assert-true "authenticate" (match (produce (l (a b) (user-authenticate txn a b)) names passwords) (((? integer?) #f #f (? integer?)) #t) (_ #f))) (assert-true "deletion" (begin (apply user-delete user-ids) (every not (produce (l (a b) (user-authenticate txn a b)) names passwords)))) (assert-true "size-after" (= size-before (test-helper-dg-count-btree-entries)))))))) (define-procedure-tests tests (user-create-delete)) (l (settings) (let* ( (settings (test-helper-dg-default-test-settings settings)) (result (test-execute-procedures settings tests))) (test-helper-dg-database-exit) result)))