blob: b1b98bd6d2e99b7ad2496758f066fd31d3af73c2 (
plain) (
blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
(import (scheme base)
(only (csc sort) sort)
(only (csc testing)
assert-equal
test)
(csc hash-map))
(define (hash-symbol s)
(hash-bytevector (string->utf8 (symbol->string s))))
(define (symbol<? s1 s2)
(string<? (symbol->string s1) (symbol->string s2)))
(define (alist->hash-map->alist l)
(hash-map->alist (alist->hash-map hash-symbol symbol<? l)))
(define (sort-alist l)
(sort (lambda (x1 x2) (symbol<? (car x1) (car x2))) l))
(test hash-map->alist-singleton
(assert-equal (sort-alist '((a . 1))) (sort-alist (alist->hash-map->alist '((a . 1))))))
(test hash-map->alist-two
(assert-equal (sort-alist '((a . 1) (b . 2))) (sort-alist (alist->hash-map->alist '((a . 1) (b . 2))))))
(test hash-map->alist-longer
(assert-equal
(sort-alist '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5) (f . 6)))
(sort-alist (alist->hash-map->alist '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5) (f . 6))))))
(test hash-map->alist-larger
(assert-equal
(sort-alist '((f . 5) (m . 1) (n . 7) (q . 3) (x . 8)))
(sort-alist (alist->hash-map->alist '((m . 1) (n . 2) (q . 3) (f . 5) (n . 7) (x . 8))))))
(test hash-map->alist-in-order
(assert-equal
(sort-alist '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ())))
(sort-alist (alist->hash-map->alist '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()))))))
(test hash-map->alist-reversed
(assert-equal
(sort-alist '((h . ()) (g . ()) (f . ()) (e . ()) (d . ()) (c . ()) (b . ()) (a . ())))
(sort-alist (alist->hash-map->alist '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()))))))
(test hash-map->alist-overwrite
(assert-equal
(sort-alist '((a . 2)))
(sort-alist (alist->hash-map->alist '((a . 1) (a . 2))))))
(test hash-map->alist-alternating
(assert-equal
(sort-alist '((h . ()) (g . ()) (i . ()) (f . ()) (j . ()) (e . ()) (k . ()) (d . ()) (l . ()) (c . ())))
(sort-alist (alist->hash-map->alist '((c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()) (i . ()) (j . ()) (k . ()) (l . ()))))))
|