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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
(in-package :cl-user)
(defpackage xsubseq-test
(:use :cl
:xsubseq
:prove))
(in-package :xsubseq-test)
(plan nil)
(defparameter *data1*
(make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(1 2 3)))
(defparameter *data2*
(make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(11 22 33)))
(defparameter *str1* "Hello")
(defparameter *str2* "World")
(subtest "xsubseq"
(is-type (xsubseq *data1* 0 1) 'xsubseq
"Can create a new XSUBSEQ")
(is-type (xsubseq *data1* 0) 'xsubseq
"Can omit END")
(is-type (xsubseq *str1* 0 1) 'xsubseq
"Can create a new XSUBSEQ (string)")
(is-type (xsubseq *str2* 0) 'xsubseq
"Can omit END (string)"))
(subtest "xnconc"
(is-type (xnconc (xsubseq *data1* 0 1))
'xsubseq
"1 XSUBSEQ")
(is-type (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2))
'concatenated-xsubseqs
"2 XSUBSEQs")
(is-type (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2)
(xsubseq *data1* 1))
'concatenated-xsubseqs
"3 XSUBSEQs")
(is-type (xnconc (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2))
(xsubseq *data1* 1))
'concatenated-xsubseqs
"Concat a CONCATENATED-XSUBSEQS and a XSUBSEQ")
(is-type (xnconc (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2))
(xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2)))
'concatenated-xsubseqs
"Concat 2 CONCATENATED-XSUBSEQSs"))
(subtest "coerce-to-sequence"
(is (coerce-to-sequence (xsubseq *data1* 0 2))
#(1 2)
:test #'equalp
"XSUBSEQ")
(is (coerce-to-sequence (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2)
(xsubseq *data1* 1)))
#(1 33 2 3)
:test #'equalp
"CONCATENATED-XSUBSEQ")
(is (coerce-to-sequence (xsubseq *str1* 0 2))
"He"
:test #'equal
"XSUBSEQ (string)")
(is (coerce-to-sequence (xnconc (xsubseq *str1* 0 1)
(xsubseq *str2* 2)
(xsubseq *str1* 1)))
"Hrldello"
:test #'equal
"CONCATENATED-XSUBSEQ (string)"))
(subtest "coerce-to-string"
(is (coerce-to-string (xnconc (xsubseq *data2* 2)
(xsubseq *data2* 2)))
"!!"
:test #'equal)
(is (coerce-to-string (xnconc (xsubseq *str1* 0 1)
(xsubseq *str2* 2)))
"Hrld"
:test #'equal))
(subtest "xlength"
(is (xlength (xsubseq *data1* 0 1)) 1)
(is (xlength (xsubseq *data1* 2)) 1)
(is (xlength (xnconc (xsubseq *data1* 0 1)
(xsubseq *data2* 2)))
2))
(subtest "with-xsubseqs"
(is (with-xsubseqs (result)
(xnconcf result (xsubseq *data1* 0 1))
(xnconcf result (xsubseq *data2* 2))
(xnconcf result (xsubseq *data1* 1)))
#(1 33 2 3)
:test #'equalp)
(is (with-xsubseqs (result :initial-value (xsubseq *data1* 0))
(xnconcf result (xsubseq *data2* 2))
(xnconcf result (xsubseq *data1* 1)))
#(1 2 3 33 2 3)
:test #'equalp))
(finalize)
|