Template fixed, and license applied to the dataframe unittests.
[CommonLispStat.git] / src / unittests / unittests-dataframe.lisp
blob0b3babb1a73a4e5c307e3c6b333d2c021fd9041f
1 ;;; -*- mode: lisp -*-
3 ;;; File: unittests-dataframe.lisp
4 ;;; Author: AJ Rossini <blindglobe@gmail.com>
5 ;;; Copyright: (c)2008--, AJ Rossini. Currently licensed under MIT
6 ;;; license. See file LICENSE.mit in top-level directory
7 ;;; for information.
8 ;;; Purpose: unittests for the dataframe package
9 ;;; Time-stamp: <2009-09-24 10:30:20 tony>
10 ;;; Creation: <2008-05-09 14:18:19 tony>
12 ;;; What is this talk of 'release'? Klingons do not make software
13 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
14 ;;; designers and quality assurance people in its wake.
16 (in-package :lisp-stat-unittests)
18 (deftestsuite lisp-stat-ut-dataframe (lisp-stat-ut)
19 ((my-df-1-good
20 (make-instance 'dataframe-array
21 :storage #2A((1 2 3 4 5)
22 (10 20 30 40 50))
23 :doc "This is an interesting legal dataframe-array"
24 :case-labels (list "x" "y")
25 :var-labels (list "a" "b" "c" "d" "e")))
26 (my-df-1-bad
27 (make-instance 'dataframe-array
28 :storage #2A((1 2 3 4 5)
29 (10 20 30 40 50))
30 :doc "This is an interesting illegal dataframe-array"
31 :case-labels (list "a" "b" "c" "d" "e")
32 :var-labels (list "x" "y")))))
34 ;;; Ensure helper-functions work
36 (addtest (lisp-stat-ut-dataframe) genseq
37 (ensure
38 (equal (cls-dataframe::gen-seq 4)
39 (list 1 2 3 4)))
40 (ensure
41 (equal (cls-dataframe::gen-seq 0)
42 nil))
43 (ensure
44 (equal (cls-dataframe::gen-seq 4 2)
45 (list 2 3 4))))
47 (addtest (lisp-stat-ut-dataframe) repeatseq
48 (ensure
49 (equal (cls-dataframe::repeat-seq 3 "d")
50 (list "d" "d" "d")))
51 (ensure
52 (equal (cls-dataframe::repeat-seq 3 'd)
53 (list 'd 'd 'd))))
56 (addtest (lisp-stat-ut-dataframe) make-labels
57 (ensure
58 (equal (cls-dataframe::make-labels "c" 3)
59 (list "c1" "c2" "c3")))
60 (ensure-error
61 (cls-dataframe::make-labels 'c 3)))
64 ;;; Dataframe tests
66 (addtest (lisp-stat-ut-dataframe) df-equalp
67 (ensure
68 (equalp (dataset (make-instance 'dataframe-array
69 :storage #2A(('a 'b)
70 ('c 'd))))
71 #2A(('a 'b)
72 ('c 'd)))))
74 (addtest (lisp-stat-ut-dataframe) df-consdata
75 (ensure
76 (consistent-dataframe-p my-df-1)))
78 (addtest (lisp-stat-ut-dataframe) df-consdata
79 (ensure-error
80 (slot-value my-df-1 'store)))
82 (addtest (lisp-stat-ut-dataframe) df-consdata
83 (ensure
84 (slot-value my-df-1 'cls-dataframe::store)))
86 (addtest (lisp-stat-ut-dataframe) df-consdata
87 (ensure
88 (dataset my-df-1)))
90 (addtest (lisp-stat-ut-dataframe) df-consdata
91 (ensure
92 (equalp
93 (slot-value my-df-1 'cls-dataframe::store)
94 (cls-dataframe::dataset my-df-1))))
96 (addtest (lisp-stat-ut-dataframe) df-consdata
97 (ensure
98 (eq (cls-dataframe::dataset my-df-1)
99 (slot-value my-df-1 'cls-dataframe::store))))
101 ;; NEVER REACH INTO CLASS INTERIORS, NO PROMISE
102 ;; GUARANTEE OF LATER CONSISTENCY...
104 (addtest (lisp-stat-ut-dataframe) df-consdata
105 (ensure
106 (cls-dataframe::doc-string my-df-1))
107 (ensure-error
108 (doc-string my-df-1)))
110 (addtest (lisp-stat-ut-dataframe) df-consdata
111 (ensure
112 (cls-dataframe::case-labels my-df-1))
113 (ensure-error
114 (case-labels my-df-1)))
116 (addtest (lisp-stat-ut-dataframe) df-consdata
117 (ensure
118 (cls-dataframe::var-labels my-df-1))
119 (ensure-error
120 (var-labels my-df-1)))
122 ;; need to ensure that for things like the following, that we protect
123 ;; this a bit more so that the results are not going to to be wrong.
124 ;; That would be a bit nasty if the dataframe-array becomes
125 ;; inconsistent.
127 (addtest (lisp-stat-ut-dataframe) badAccess9
128 (ensure
129 (setf (cls-dataframe::var-labels my-df-1)
130 (list "a" "b"))))
132 (addtest (lisp-stat-ut-dataframe) badAccess10
133 (ensure
134 (progn
135 ;; no error, but corrupts structure
136 (setf (cls-dataframe::var-labels my-df-1)
137 (list "a" "b" "c"))
138 ;; error happens here
139 (not (consistent-dataframe-p my-df-1))))) ;; Nil
141 (addtest (lisp-stat-ut-dataframe) badAccess12
142 (ensure
143 (setf (cls-dataframe::var-labels my-df-1)
144 (list "a" "b"))))
146 (addtest (lisp-stat-ut-dataframe) badAccess13
147 (ensure
148 (consistent-dataframe-p my-df-1))) ;; T
150 ;; This is now done by:
151 (addtest (lisp-stat-ut-dataframe) badAccess14
152 (ensure-error
153 (let ((old-varnames (varNames my-df-1)))
154 (setf (varNames my-df-1) (list "a" "b")) ;; should error
155 (setf (varNames my-df-1) old-varnames)
156 (error "don't reach this point in badaccess14"))))
159 ;; NEED TO CONFIRM THERE IS AN ERROR.
160 (addtest (lisp-stat-ut-dataframe) badAccess15
161 (ensure-error
162 (let ((origCaseNames (caselabels my-df-1)))
163 (setf (caselabels my-df-1) (list "a" "b" "c" 4 5))
164 (caselabels my-df-1)
165 (ignore-errors
166 (setf (caselabels my-df-1)
167 (list "a" "b" 4 5)))
168 (setf (caselabels my-df-1) origCaseNames))))
171 ;; (run-tests)
172 ;; (describe (run-tests))
176 (equalp (dataset
177 (make-instance 'dataframe-array
178 :storage #2A(('a 'b)
179 ('c 'd))))
180 #2A(('a 'b)
181 ('c 'd)) )
183 (equalp (dataset
184 (make-instance 'dataframe-array
185 :storage #2A((1 2)
186 (3 4))))
187 #2A((1 2)
188 (3 4)))
190 (equalp (dataset
191 (make-instance 'dataframe-array
192 :storage #2A((1d0 2d0)
193 (3d0 4d0))))
194 #2A((1d0 2d0)
195 (3d0 4d0)))