source: ccr/trunk/p/C0CUNIT.m@ 954

Last change on this file since 954 was 508, checked in by George Lilly, 16 years ago

formatting for Version 1

File size: 7.1 KB
RevLine 
[508]1C0CUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08
2 ;;1.0;C0C;;May 19, 2009;
[391]3 ;Copyright 2008 George Lilly. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "This is a unit testing library",!
21 W !
22 Q
23 ;
[508]24ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array
[391]25 ; ZARY IS PASSED BY REFERENCE
26 ; BAT is a string identifying the test battery
27 ; TST is a test which will evaluate to true or false
28 ; I '$G(ZARY) D
29 ; . S ZARY(0)=0 ; initially there are no elements
30 ; W "GOT HERE LOADING "_TST,!
31 N CNT ; count of array elements
32 S CNT=ZARY(0) ; contains array count
33 S CNT=CNT+1 ; increment count
34 S ZARY(CNT)=TST ; put the test in the array
35 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY
36 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY
37 . S II=$P(ZARY(BAT),"^",2)
38 . S $P(ZARY(BAT),"^",2)=II+1
39 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY
40 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY
41 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX
42 . ; S TN=$NA(ZARY("TESTS"))
43 . ; D PUSH^C0CXPATH(TN,BAT)
44 S ZARY(0)=CNT ; update the array counter
45 Q
46 ;
[508]47ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
[391]48 ; ZARY IS PASSED BY NAME
49 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
50 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
51 K @ZARY
52 S @ZARY@(0)=0 ; initialize array count
53 N LINE,LABEL,BODY
54 N INTEST S INTEST=0 ; switch for in the test case section
55 N SECTION S SECTION="[anonymous]" ; test case section
56 ;
57 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
58 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
59 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
60 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
61 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
62 . I INTEST D ; within the testing section
63 . . I LINE?." "1";;><".E D ; section name found
64 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
65 . . I LINE?." "1";;>>".E D ; test case found
66 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
67 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
68 Q
69 ;
[508]70ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
[391]71 N ZI,ZX,ZR,ZP
72 S DEBUG=0
73 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS
74 ; . W "DOING ALL",!
75 ; . N J,NT
76 ; . S NT=$NA(ZARY("TESTS"))
77 ; . W NT,@NT@(0),!
78 ; . F J=1:1:@NT@(0) D ;
79 ; . . W @NT@(J),!
80 ; . . D ZTEST^C0CUNIT(@ZARY,@NT@(J))
81 I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST
82 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
83 N FIRST,LAST
84 S FIRST=$P(ZARY(WHICH),"^",1)
85 S LAST=$P(ZARY(WHICH),"^",2)
86 F ZI=FIRST:1:LAST D
87 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
88 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
89 . . ; W ZP,!
90 . . S ZX=ZP
91 . . W "RUNNING: "_ZP
92 . . X ZX
93 . . W "..SUCCESS: ",WHICH,!
94 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST
95 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
96 . . S ZX="S ZR="_ZP
97 . . W "TRYING: "_ZP
98 . . X ZX
99 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
100 . . I '$D(TPASSED) D ; NOT INITIALIZED YET
101 . . . S TPASSED=0 S TFAILED=0
102 . . I ZR S TPASSED=TPASSED+1
103 . . I 'ZR S TFAILED=TFAILED+1
104 Q
105 ;
[508]106TEST ; RUN ALL THE TEST CASES
[391]107 N ZTMP
108 D ZLOAD(.ZTMP)
109 D ZTEST(.ZTMP,"ALL")
110 W "PASSED: ",TPASSED,!
111 W "FAILED: ",TFAILED,!
112 W !
113 W "THE TESTS!",!
114 ; I DEBUG ZWR ZTMP
115 Q
116 ;
[508]117GTSTS(GTZARY,RTN) ; return an array of test names
[391]118 N I,J S I="" S I=$O(GTZARY("TESTS",I))
119 F J=0:0 Q:I="" D
120 . D PUSH^C0CXPATH(RTN,I)
121 . S I=$O(GTZARY("TESTS",I))
122 Q
123 ;
[508]124TESTALL(RNM) ; RUN ALL THE TESTS
[391]125 N ZI,J,TZTMP,TSTS,TOTP,TOTF
126 S TOTP=0 S TOTF=0
127 D ZLOAD^C0CUNIT("TZTMP",RNM)
128 D GTSTS(.TZTMP,"TSTS")
129 F ZI=1:1:TSTS(0) D ;
130 . S TPASSED=0 S TFAILED=0
131 . D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI))
132 . S TOTP=TOTP+TPASSED
133 . S TOTF=TOTF+TFAILED
134 . S $P(TSTS(ZI),"^",2)=TPASSED
135 . S $P(TSTS(ZI),"^",3)=TFAILED
136 F ZI=1:1:TSTS(0) D ;
137 . W "TEST=> ",$P(TSTS(ZI),"^",1)
138 . W " PASSED=>",$P(TSTS(ZI),"^",2)
139 . W " FAILED=>",$P(TSTS(ZI),"^",3),!
140 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
141 Q
142 ;
[508]143TLIST(ZARY) ; LIST ALL THE TESTS
[391]144 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
145 ; ZARY IS PASSED BY REFERENCE
146 N I,J,K S I="" S I=$O(ZARY("TESTS",I))
147 S K=1
148 F J=0:0 Q:I="" D
149 . ; W "I IS NOW=",I,!
150 . W I," "
151 . S I=$O(ZARY("TESTS",I))
152 . S K=K+1 I K=6 D
153 . . W !
154 . . S K=1
155 Q
156 ;
[508]157MEDS
[398]158 N DEBUG S DEBUG=0
159 N DFN S DFN=5685
160 K ^TMP($J)
161 W "Loading CCR Template into T using LOAD^GPLCCR0($NA(^TMP($J,""CCR"")))",!!
162 N T S T=$NA(^TMP($J,"CCR")) D LOAD^GPLCCR0(T)
163 N XPATH S XPATH="//ContinuityOfCareRecord/Body/Medications"
164 W "XPATH is: "_XPATH,!
165 W "Getting Med Template into INXML using",!
166 W "QUERY^GPLXPATH(T,XPATH,""INXML"")",!!
167 D QUERY^GPLXPATH(T,XPATH,"INXML")
[416]168 W "Executing EXTRACT^C0CMED(INXML,DFN,OUTXML)",!
[398]169 W "OUTXML will be ^TMP($J,""OUT"")",!
170 N OUTXML S OUTXML=$NA(^TMP($J,"OUT"))
[416]171 D EXTRACT^C0CMED6("INXML",DFN,OUTXML)
[398]172 D FILEOUT^C0CRNF(OUTXML,"TESTMEDS.xml")
173 Q
[508]174PAT
[415]175 D ANALYZE^ARJTXRD("C0CDPT",.OUT) ; Analyze a routine in the directory
[400]176 N X,Y
177 ; Select Patient
178 S DIC=2,DIC(0)="AEMQ" D ^DIC
179 ;
180 W "You have selected patient "_Y,!!
181 N I S I=89 F S I=$O(OUT(I)) Q:I="ALINE" D
182 . W "OUT("_I_",0)"_" is "_$P(OUT(I,0)," ")_" "
183 . W "valued at "
[415]184 . W @("$$"_$P(OUT(I,0),"(DFN)")_"^"_"C0CDPT"_"("_$P(Y,"^")_")")
[400]185 . W !
186 Q
Note: See TracBrowser for help on using the repository browser.