aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/util/table.scm
blob: 564dff7476afdbc6db87ae11ca50d6d0b228bf7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(define-module (test table)
  :use-module (srfi srfi-64)
  :use-module (srfi srfi-88)
  :use-module ((hnh util) :select (->))
  :use-module (hnh util table))

(test-expect-fail "Equivalent tables are equal")

(define t (table))

(test-assert "Empty tables are empty" (null? (table->list t)))

(test-equal "Adding elements work"
  '((a . 10) (b . 20))
  (-> t
      (table-put 'a 10)
      (table-put 'b 20)
      table->list))

(test-assert "Original table is unchanged"
  (null? (table->list t)))

(test-equal "Insertion order doesn't matter, when serializing to lists"
  (-> t
      (table-put 'a 10)
      (table-put 'b 20)
      table->list)
  (-> t
      (table-put 'b 20)
      (table-put 'a 10)
      table->list))

;;; TODO this doesn't work, since the trees don't rebalance
(test-equal "Equivalent tables are equal"
  (-> t
      (table-put 'a 10)
      (table-put 'b 20)
      (table-put 'c 30))
  (-> t
      (table-put 'c 30)
      (table-put 'b 20)
      (table-put 'a 10)))

;;; TODO test table-get
;; (table-get t 'key)
;; (table-put t 'key value)

'((hnh util table))