SASUnit Examples  Version 1.5.0
boxplot_test.sas
Go to the documentation of this file.
1 
24 /*-- standard case without reference -----------------------------------------*/
25 %initTestcase(i_object=boxplot.sas, i_desc=standard case without reference)
26 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report1.pdf)
27 %assertReport(i_actual=&g_work\report1.pdf, i_expected=,
28  i_desc=please compare chart with specification in source code)
29 
30 /*-- standard case with reference --------------------------------------------*/
31 %initTestcase(i_object=boxplot.sas, i_desc=standard case with reference)
32 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report2.pdf)
33 %assertReport(i_actual=&g_work\report2.pdf, i_expected=&g_refdata\boxplot1.pdf,
34  i_desc=please compare the two charts)
35 
36 /*-- standard case with reference, missing values for Y ----------------------*/
37 %initTestcase(i_object=boxplot.sas, i_desc=%str(standard case with reference, missing values for Y ))
38 data blood_pressure;
39  set testdata.blood_pressure;
40  output;
41  sbp=.;
42  output;
43 run;
44 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report3.pdf)
45 %assertReport(i_actual=&g_work\report3.pdf, i_expected=&g_refdata\boxplot1.pdf,
46  i_desc=%str(please compare the two charts, no changes produced by missing values in the y variable))
47 %assertLogMsg(i_logMsg=%str(NOTE: 240 observation\(s\) contained a MISSING value for the SBP \* Visit = Med request|NOTE: 240 Beobachtung\(en\) in fehlendem Wert enthalten für den Befehl SBP \* Visit = Med)
48  ,i_desc=regular expression used to support different languages
49  )
50 
51 /*-- different scaling for x and y axis --------------------------------------*/
52 %initTestcase(i_object=boxplot.sas, i_desc=different scaling for x and y axis)
53 data blood_pressure;
54  set testdata.blood_pressure;
55  visit=visit*100;
56  sbp=sbp*100;
57 run;
58 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report4.pdf)
59 %assertReport(i_actual=&g_work\report4.pdf, i_expected=,
60  i_desc=please compare chart with specification in source code)
61 
62 /*-- only two visits ---------------------------------------------------------*/
63 %initTestcase(i_object=boxplot.sas, i_desc=only two visits)
64 data blood_pressure;
65  set testdata.blood_pressure;
66  where visit in (1, 5);
67 run;
68 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report5.pdf)
69 %assertReport(i_actual=&g_work\report5.pdf, i_expected=,
70  i_desc=please compare chart with specification in source code)
71 
72 /*-- Error: only one visit ---------------------------------------------------*/
73 %initTestcase(i_object=boxplot.sas, i_desc=only one visit)
74 data blood_pressure;
75  set testdata.blood_pressure;
76  where visit in (3);
77 run;
78 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report6.pdf)
79 %assertLogMsg(i_logMsg=ERROR: boxplot: x variable must have at least two values)
80 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report6.pdf)), i_expected=0, i_desc=no report created)
81 %endTestcase(i_assertLog=0)
82 
83 /*-- 18 visits ---------------------------------------------------------------*/
84 %initTestcase(i_object=boxplot.sas, i_desc=18 visits)
85 data blood_pressure;
86  set
87  testdata.blood_pressure (in=in1)
88  testdata.blood_pressure (in=in2)
89  testdata.blood_pressure (in=in3)
90  ;
91  if in2 then visit=visit+6;
92  if in3 then visit=visit+12;
93 run;
94 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report7.pdf)
95 %assertReport(i_actual=&g_work\report7.pdf, i_expected=,
96  i_desc=please compare chart with specification in source code)
97 
98 /*-- Error: invalid input data set -------------------------------------------*/
99 %initTestcase(i_object=boxplot.sas, i_desc=invalid input data set)
100 %boxplot(data=XXXXX, x=visit, y=sbp, group=med, report=&g_work\report8.pdf)
101 %assertLogMsg(i_logMsg=ERROR: boxplot: Data set XXXXX does not exist)
102 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report8.pdf)), i_expected=0, i_desc=no report created)
103 %endTestcase(i_assertLog=0)
104 
105 /*-- Error: input data set missing -------------------------------------------*/
106 %initTestcase(i_object=boxplot.sas, i_desc=input data set missing)
107 %boxplot(data=, x=visit, y=sbp, group=med, report=&g_work\report9.pdf)
108 %assertLogMsg(i_logMsg=ERROR: boxplot: Data set does not exist)
109 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report9.pdf)), i_expected=0, i_desc=no report created)
110 %endTestcase(i_assertLog=0)
111 
112 /*-- Error: invalid x variable -----------------------------------------------*/
113 %initTestcase(i_object=boxplot.sas, i_desc=invalid x variable)
114 %boxplot(data=testdata.blood_pressure, x=visitXXX, y=sbp, group=med, report=&g_work\report10.pdf)
115 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable visitXXX does not exist in data set testdata.blood_pressure)
116 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report10.pdf)), i_expected=0, i_desc=no report created)
117 %endTestcase(i_assertLog=0)
118 
119 /*-- Error: x variable missing -----------------------------------------------*/
120 %initTestcase(i_object=boxplot.sas, i_desc=x variable missing)
121 %boxplot(data=testdata.blood_pressure, x=, y=sbp, group=med, report=&g_work\report11.pdf)
122 %assertLogMsg(i_logMsg=ERROR: boxplot: X variable not specified)
123 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report11.pdf)), i_expected=0, i_desc=no report created)
124 %endTestcase(i_assertLog=0)
125 
126 /*-- Error: x variable not numeric -------------------------------------------*/
127 %initTestcase(i_object=boxplot.sas, i_desc=x variable not numeric)
128 data blood_pressure;
129  set testdata.blood_pressure;
130  visitc = put (visit, 1.);
131 run;
132 %boxplot(data=blood_pressure, x=visitc, y=sbp, group=med, report=&g_work\report12.pdf)
133 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable visitc in data set blood_pressure must be numeric)
134 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report12.pdf)), i_expected=0, i_desc=no report created)
135 %endTestcase(i_assertLog=0)
136 
137 /*-- Error: x variable values not equidistant --------------------------------*/
138 %initTestcase(i_object=boxplot.sas, i_desc=x variable values not equidistant)
139 data blood_pressure;
140  set testdata.blood_pressure;
141  if visit=5 then visit=6;
142 run;
143 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report13.pdf)
144 %assertLogMsg(i_logMsg=ERROR: boxplot: Values of x variable are not equidistant)
145 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report13.pdf)), i_expected=0, i_desc=no report created)
146 %endTestcase(i_assertLog=0)
147 
148 /*-- Error: x variable has missing values ------------------------------------*/
149 %initTestcase(i_object=boxplot.sas, i_desc=x variable has missing values)
150 data blood_pressure;
151  set testdata.blood_pressure;
152  output;
153  visit=.;
154  output;
155 run;
156 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report14.pdf)
157 %assertLogMsg(i_logMsg=ERROR: boxplot: Missing values in x variable are not allowed)
158 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report14.pdf)), i_expected=0, i_desc=no report created)
159 %endTestcase(i_assertLog=0)
160 
161 /*-- Error: invalid y variable -----------------------------------------------*/
162 %initTestcase(i_object=boxplot.sas, i_desc=invalid y variable)
163 %boxplot(data=testdata.blood_pressure, x=visit, y=sbpXXX, group=med, report=&g_work\report15.pdf)
164 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable sbpXXX does not exist in data set testdata.blood_pressure)
165 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report15.pdf)), i_expected=0, i_desc=no report created)
166 %endTestcase(i_assertLog=0)
167 
168 /*-- Error: y variable not specified -----------------------------------------*/
169 %initTestcase(i_object=boxplot.sas, i_desc=y variable not specified)
170 %boxplot(data=testdata.blood_pressure, x=visit, y=, group=med, report=&g_work\report16.pdf)
171 %assertLogMsg(i_logMsg=ERROR: boxplot: Y variable not specified)
172 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report16.pdf)), i_expected=0, i_desc=no report created)
173 %endTestcase(i_assertLog=0)
174 
175 /*-- Error: y variable not numeric -------------------------------------------*/
176 %initTestcase(i_object=boxplot.sas, i_desc=y variable not numeric)
177 data blood_pressure;
178  set testdata.blood_pressure;
179  sbpc = put (sbp, best32.);
180 run;
181 %boxplot(data=blood_pressure, x=visit, y=sbpc, group=med, report=&g_work\report17.pdf)
182 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable sbpc in data set blood_pressure must be numeric)
183 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report17.pdf)), i_expected=0, i_desc=no report created)
184 %endTestcase(i_assertLog=0)
185 
186 /*-- Error: invalid group variable -------------------------------------------*/
187 %initTestcase(i_object=boxplot.sas, i_desc=invalid group variable)
188 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=medXXX, report=&g_work\report18.pdf)
189 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable medXXX does not exist in data set testdata.blood_pressure)
190 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report18.pdf)), i_expected=0, i_desc=no report created)
191 %endTestcase(i_assertLog=0)
192 
193 /*-- Error: group variable not specified -------------------------------------*/
194 %initTestcase(i_object=boxplot.sas, i_desc=group variable not specified)
195 %boxplot(data=testdata.blood_pressure, x=visit, y=sbp, group=, report=&g_work\report19.pdf)
196 %assertLogMsg(i_logMsg=ERROR: boxplot: Group variable not specified)
197 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report19.pdf)), i_expected=0, i_desc=no report created)
198 %endTestcase(i_assertLog=0)
199 
200 /*-- Error: group variable has only one value --------------------------------*/
201 %initTestcase(i_object=boxplot.sas, i_desc=group variable has only one value)
202 data blood_pressure;
203  set testdata.blood_pressure;
204  if med=1;
205 run;
206 %boxplot(data=blood_pressure, x=visit, y=sbp, group=med, report=&g_work\report20.pdf)
207 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable med must have exactly two values)
208 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report20.pdf)), i_expected=0, i_desc=no report created)
209 %endTestcase(i_assertLog=0)
210 
211 /*-- Error: group variable has more than two values -------------------------*/
212 %initTestcase(i_object=boxplot.sas, i_desc=group variable has more than two values)
213 data blood_pressure2;
214  set testdata.blood_pressure;
215  if med=1 then do;
216  output;
217  med=2;
218  output;
219  end;
220  else output;
221 run;
222 %boxplot(data=blood_pressure2, x=visit, y=sbp, group=med, report=&g_work\report21.pdf)
223 %assertLogMsg(i_logMsg=ERROR: boxplot: Variable med must have exactly two values)
224 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report21.pdf)), i_expected=0, i_desc=no report created)
225 %endTestcase(i_assertLog=0)
226 
227 /*-- Error: group variable has missing values --------------------------------*/
228 %initTestcase(i_object=boxplot.sas, i_desc=group variable has missing values)
229 data blood_pressure3;
230  set testdata.blood_pressure;
231  if med=0 then do;
232  med=.;
233  output;
234  end;
235 run;
236 %boxplot(data=blood_pressure3, x=visit, y=sbp, group=med, report=&g_work\report22.pdf)
237 %assertLogMsg(i_logMsg=ERROR: boxplot: Missing values in group variable are not allowed)
238 %assertEquals(i_actual=%sysfunc(fileexist(&g_work\report22.pdf)), i_expected=0, i_desc=no report created)
239 %endTestcase(i_assertLog=0)
240