2020-02-16 21:39:42 +01:00
|
|
|
#lang typed/racket
|
|
|
|
|
|
|
|
;;; Tests for dds/utils.
|
|
|
|
|
|
|
|
(require typed/rackunit "utils.rkt")
|
|
|
|
|
2020-02-19 22:09:09 +01:00
|
|
|
(test-case "HashTable Injection"
|
2020-02-16 21:39:42 +01:00
|
|
|
(test-case "auto-hash-ref/explicit"
|
|
|
|
(let ([mytable #hash((a . 3) (b . 4))])
|
|
|
|
(check-equal? (auto-hash-ref/explicit (mytable b a)
|
|
|
|
(* a b))
|
|
|
|
12))
|
|
|
|
(let ([ht #hash((a . #t) (b . #f))])
|
|
|
|
(check-equal? (auto-hash-ref/explicit (ht a b)
|
|
|
|
(and (not a) b))
|
2020-02-17 00:16:44 +01:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(test-case "auto-hash-ref/:"
|
|
|
|
(let ([ht #hash((x . #t) (y . #t) (t . #f))]
|
|
|
|
[z #t])
|
|
|
|
(check-equal? (auto-hash-ref/: ht
|
|
|
|
(and :x (not :y) z (or (and :t) :x)))
|
|
|
|
#f))
|
|
|
|
(let ([ht #hash((a . 1) (b . 2))])
|
|
|
|
(check-equal? (auto-hash-ref/: ht (+ :a (* 2 :b)))
|
2020-02-17 23:52:15 +01:00
|
|
|
5)))
|
|
|
|
|
|
|
|
(test-case "eval-with"
|
|
|
|
(check-equal? (let ([ht #hash((a . 1) (b . 1))])
|
|
|
|
(eval-with1 ht '(+ b a 1)))
|
|
|
|
3)))
|