alists and plists now
This commit is contained in:
+54
-1
@@ -1,7 +1,7 @@
|
||||
(import "alist.slime")
|
||||
|
||||
(define a (make-alist))
|
||||
;; a == ()
|
||||
;; a == (())
|
||||
|
||||
(assert (= (first a) ()))
|
||||
|
||||
@@ -46,3 +46,56 @@
|
||||
(assert (= (length (first a)) 2))
|
||||
(assert (= (alist-get a 'key1) 'value1))
|
||||
(assert (= (alist-get a 'key2) 'value2))
|
||||
|
||||
|
||||
;; -------------
|
||||
;;
|
||||
;; PLISTS
|
||||
;;
|
||||
;; -------------
|
||||
|
||||
(define p (make-plist))
|
||||
;; p == (())
|
||||
|
||||
(assert (= (first p) ()))
|
||||
|
||||
(plist-set! p :key1 'value1)
|
||||
;; p == ((:key1 value1))
|
||||
|
||||
(assert (= (plist-get p :key1) 'value1))
|
||||
(assert (plist-prop-exists? p :key1))
|
||||
(assert (not (plist-prop-exists? p :key2)))
|
||||
|
||||
(plist-set! p :key2 'value2)
|
||||
;; p == ((:key2 value2,
|
||||
;; :key1 value1))
|
||||
|
||||
(assert (= (plist-get p :key2) 'value2))
|
||||
(assert (plist-prop-exists? p :key2))
|
||||
(assert (= (plist-find p :key2) 0))
|
||||
(assert (= (plist-find p :key1) 1))
|
||||
(assert (= (length (first p)) 4))
|
||||
|
||||
(plist-set! p :key1 'value3)
|
||||
;; p == ((:key1 value3,
|
||||
;; :key2 value2,
|
||||
;; :key1 value1))
|
||||
|
||||
(assert (= (length (first p)) 6))
|
||||
(assert (= (plist-get p :key1) 'value3))
|
||||
|
||||
(plist-set-overwrite! p :key1 'value4)
|
||||
;; p == ((:key1 value4,
|
||||
;; :key2 value2,
|
||||
;; :key1 value1))
|
||||
|
||||
(assert (= (length (first p)) 6))
|
||||
(assert (= (plist-get p :key1) 'value4))
|
||||
|
||||
(plist-remove! p :key1)
|
||||
;; p == ((:key2 value2,
|
||||
;; :key1 value1))
|
||||
|
||||
(assert (= (length (first p)) 4))
|
||||
(assert (= (plist-get p :key1) 'value1))
|
||||
(assert (= (plist-get p :key2) 'value2))
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
(define (test-cond x)
|
||||
(cond ((< 0 x) +1)
|
||||
((> 0 x) -1)
|
||||
(else 0)))
|
||||
|
||||
(assert (= (test-cond 10) 1))
|
||||
(assert (= (test-cond 1) 1))
|
||||
(assert (= (test-cond 123) 1))
|
||||
|
||||
(assert (= (test-cond -10) -1))
|
||||
(assert (= (test-cond -1) -1))
|
||||
(assert (= (test-cond -123) -1))
|
||||
|
||||
(assert (= (test-cond 0) 0))
|
||||
(assert (= (test-cond -0) 0))
|
||||
(assert (= (test-cond +0) 0))
|
||||
|
||||
|
||||
(define (test-case x)
|
||||
(case x
|
||||
((a b 3) 1)
|
||||
((4 5 6) -1)
|
||||
(else 'xD)))
|
||||
|
||||
|
||||
(assert (= (test-case 'a) 1))
|
||||
(assert (= (test-case 'b) 1))
|
||||
(assert (= (test-case 3) 1))
|
||||
|
||||
(assert (= (test-case 4) -1))
|
||||
(assert (= (test-case 5) -1))
|
||||
(assert (= (test-case 6) -1))
|
||||
|
||||
(assert (= (test-case 0) 'xD))
|
||||
(assert (= (test-case 1) 'xD))
|
||||
(assert (= (test-case :asd) 'xD))
|
||||
|
||||
Reference in New Issue
Block a user