TEST commands are used to test model constants and variables against numbers or other model variables (and can also be used to test the current date see *DATE* below). The TEST command returns 1 (TRUE) if the specified relationship is true, and 0 (FALSE) if not. The TEST command is intended primarily for use with IFTHENELSE and BRANCH commands.
The command portion of TEST should take the form
varname relation value
where varname is a model Constant or variable, relation is one of <, <=, =, >=, > or <> and value is either a number or another model variable. For example
TEST>FRACTION < 1
TEST>PERCENT TO ADVERTIZING>PERCENT TO KICKBACK
The second of these compares two model variables and is, because the > is used in the command syntax and the comparison, a little hard to read. Vensim looks for the first > and treats everything after that (and before the next &) as the command.
If you specify a model variable that is not a constant, Vensim will execute the equation for that variable in the model. Vensim will not, however, test dependency. Thus if you want to compute values, the values computed should depend only on model constants.
Consider the following common example:
sector : S1,S2,S3,S4 ~~|
ALLOCATION FRACTION[sector]=.25 ~~|
TOTAL ALLOCATION FRACTION = SUM(ALLOCATION FRACTION[sector!])~~|
Now in the Venapp you might want to test that the entered fractions do indeed add up to 1.
:SCREEN ENTRY
MODVAR,"ALLOCATION FRACTION[S1]",10,10,20,0,,[0|1]
MODVAR,"ALLOCATION FRACTION[S2]",10,20,20,0,,[0|1]
MODVAR,"ALLOCATION FRACTION[S3]",10,30,20,0,,[0|1]
MODVAR,"ALLOCATION FRACTION[S4]",10,40,20,0,,[0|1]
BUTTON,"Simulate Model",10,50,0,0,L,,IFTHENELSE&TEST>\
TOTAL ALLOCATION FRACTION=1&BRANCH>OK&\
SPECIAL>STOP|Fractions must add to 1.
BRANCH,"OK",0,0,0,0,,,MENU>RUN,NEXTSCREEN
If the fractions add to one, Vensim will make a simulation and shift to NEXTSCREEN. If the numbers do not add to one, the user will see a stop sign.
If you do attempt to compute a value that depends on something other than Constants you will likely get nonsense back. If you are careful, you can cause Vensim to execute equations in a specific order (through a series of Test commands) and get correct model results (Only the initial portion of INTEG will be evaluated.)
*DATE*
You can use *DATE* instead of a variable name to test the current date. This is useful if you want to limit the time part or all of a Venapp is available. Use
*DATE* > YYYY.MM.DD
or
*DATE* < YYYY.MM.DD
The date needs to be specified in the manner above MM/DD/YYYY and variations will not work). Consider the following:
:SCREEN TESTDATE
COMMAND,"",,,,,,,"IFTHENELSE&TEST>*DATE* > 2005.03.07&BRANCH>EXP&BRANCH>OK",
BRANCH,"OK",,,,,,,,SCREEN1
BRANCH,"EXP",,,,,,,"SPECIAL>MESSAGE|3|No|Too Late&MENU>EXIT",
If this appears as the first screen it will close the Venapp with the message "Too Late" after March 7, 2005 but simply open it before that date.
NOTE the use of *DATE* is easily circumvented by changing the date on the computer the user is working with.