startmacro
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Test File Calculator Macro
! @author Jay P hallam
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!q
switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

if interAct then
  !
  ! This will test the switch to enable results and expressions to be re-computed
  ! in the process method of fcalculator
  !
  pipe on
    panel/controls=gc/setup
    gcontrol label macro "MACRO"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    gcontrol text idtext "Instructions" "Amplitude should be value of MULTIPLIER minus 1" 24 7 /title
    gcontrol lval multiplier "Multiplier" 2 1 10 1

    waveform,OUT=_wave,FORM=SF,ELEM=5e9,SHAPE=CONST,AMP=1
    fcalc/mon _out _wave gc.multiplier.value-1 *
    plot _out y1=-1 y2=10

  pipe off
endif

call test_fcalc_invalid_expression

waveform temp_fcalc_m3  sf elem=10 shape=const amp=-3
waveform temp_fcalc_m4  sf elem=10 shape=const amp=-4
waveform temp_fcalc_0   sf elem=10 shape=const amp=0
waveform temp_fcalc_1   sf elem=10 shape=const amp=1
waveform temp_fcalc_2   sf elem=10 shape=const amp=2
waveform temp_fcalc_3   sf elem=10 shape=const amp=3
waveform temp_fcalc_4   sf elem=10 shape=const amp=4
waveform temp_fcalc_5   sf elem=10 shape=const amp=5
waveform temp_fcalc_8   sf elem=10 shape=const amp=8
waveform temp_fcalc_9   sf elem=10 shape=const amp=9
waveform temp_fcalc_10  sf elem=10 shape=const amp=10
waveform temp_fcalc_123 sf elem=10 shape=const amp=1.23

fcalc temp_fcalc_add temp_fcalc_1 temp_fcalc_1 +
call checkResult "File ADD............." temp_fcalc_add temp_fcalc_2

fcalc temp_fcalc_sub temp_fcalc_3 temp_fcalc_2 -
call checkResult "File SUBTRACT........" temp_fcalc_sub temp_fcalc_1

fcalc temp_fcalc_mult temp_fcalc_2 temp_fcalc_4 *
call checkResult "File MULTIPLY........" temp_fcalc_mult temp_fcalc_8

fcalc temp_fcalc_div temp_fcalc_10 temp_fcalc_5 /
call checkResult "File DIVIDE.........." temp_fcalc_div temp_fcalc_2

fcalc temp_fcalc_pow temp_fcalc_3 temp_fcalc_2 **
call checkResult "File POWER..........." temp_fcalc_pow temp_fcalc_9

fcalc temp_fcalc_sqrt temp_fcalc_9 "SQRT"
call checkResult "File SQRT............" temp_fcalc_sqrt temp_fcalc_3

fcalc temp_fcalc_fix temp_fcalc_123 "FIX"
!!!jph -- result is supposed to be same as input file
call checkResult "File FIX............" temp_fcalc_fix temp_fcalc_1

fcalc temp_fcalc_round temp_fcalc_123 "ROUND"
!!!jph -- result is supposed to be same as input file
call checkResult "File ROUND.........." temp_fcalc_round temp_fcalc_1

fcalc temp_fcalc_max temp_fcalc_1 temp_fcalc_9 "MAXIMUM"
call checkResult "File MAXIMUM........" temp_fcalc_max temp_fcalc_9

fcalc temp_fcalc_min temp_fcalc_1 temp_fcalc_9 "MINIMUM"
call checkResult "File MINIMUM........" temp_fcalc_min temp_fcalc_1

fcalc temp_fcalc_modulot  temp_fcalc_9 temp_fcalc_m4 "MODULOT"
call checkResult "File MODULOT........" temp_fcalc_modulot temp_fcalc_1

fcalc temp_fcalc_moduloe  temp_fcalc_8 temp_fcalc_m3 "MODULOE"
call checkResult "File MODULOE........" temp_fcalc_moduloe temp_fcalc_2

fcalc temp_fcalc_modulof temp_fcalc_9 temp_fcalc_m4 "MODULOF"
call checkResult "File MODULOF........" temp_fcalc_modulof temp_fcalc_m3

fcalc temp_fcalc_sin temp_fcalc_0 "SIN"
call checkResult "File SIN............" temp_fcalc_sin temp_fcalc_0

fcalc temp_fcalc_cos temp_fcalc_0 "COS"
call checkResult "File COS............" temp_fcalc_cos temp_fcalc_1

fcalc temp_fcalc_tan temp_fcalc_0 "TAN"
call checkResult "File TAN............" temp_fcalc_tan temp_fcalc_0

fcalc temp_fcalc_asin temp_fcalc_0 "ASIN"
call checkResult "File ASIN..........." temp_fcalc_asin temp_fcalc_0

fcalc temp_fcalc_acos temp_fcalc_1 "ACOS"
call checkResult "File ACOS..........." temp_fcalc_acos temp_fcalc_0

fcalc temp_fcalc_atan temp_fcalc_0 "ATAN"
call checkResult "File ATAN..........." temp_fcalc_atan temp_fcalc_0

if /NOERASE LE 0 then
  files/e temp_fcalc*
endif

if baseline then
  %test_fcalc_piped  ! since 3.7.1: test macro for testing fcalc when pipe on and df.getSize=0.0 (NXM-2954)
  %test_fcalc ! enabled since 3.5.1: Test all Operators with file inputs under a variety of conditions (full coverage)
  %test_fcalc_mix_input_types ! since 3.5.1: Test Operators with a mix of files and constants for inputs bug 2852
endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "MULTIPLIER" then

  endif
return

!--------------------------------------------------------------
!  Check the results against what is expected
!  If failure occurs, print the test name with the names
!  of the file containing the expected
!  and actual values obtained from the test.
!
!  (INPUT) testname        - name of the test being run
!  (INPUT) actualValue     - name of file containing actual results from the test
!  (INPUT) expectedValue   - name of file containing expected result values
!
procedure checkResult s:testname s:actualValue s:expectedValue

  ASSERT/TEXT=testname actualValue FEQ expectedValue

return

!******************************************************************************!
procedure test_fcalc_invalid_expression
!  This set of tests added by JC4 to check exception handling when FCALCULATOR
!  is passed a set of invalid parameters (see DR 504091-1 and DR 504090-1).
!
  ASSERT/TEXT="FCALC: TOO MANY OPERATORS (TEST 1 of 4)"/EXCEPT &
        FCALCULATOR FOO APENNY 2 + +
  ASSERT/TEXT="FCALC: TOO MANY OPERATORS (TEST 2 of 4)"/EXCEPT &
        FCALCULATOR FOO APENNY APENNY + +
  ASSERT/TEXT="FCALC: TOO MANY OPERATORS (TEST 3 of 4)"/EXCEPT &
        FCALCULATOR FOO 2 APENNY + 1 APENNY * / 8 - +
  ASSERT/TEXT="FCALC: TOO MANY OPERATORS (TEST 4 of 4)"/EXCEPT &
        FCALCULATOR FOO APENNY +

  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 1 of 6)"/EXCEPT &
        FCALCULATOR FOO APENNY 2 2 +
  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 2 of 6)"/EXCEPT &
        FCALCULATOR FOO APENNY APENNY APENNY +
  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 3 of 6)"/EXCEPT &
        FCALCULATOR FOO +
  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 4 of 6)"/EXCEPT &
        FCALCULATOR FOO APENNY 2 + 1 APENNY * / APENNY 9 -
  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 5 of 6)"/EXCEPT &
        FCALCULATOR FOO APENNY APENNY
  ASSERT/TEXT="FCALC: TOO FEW OPERATORS (TEST 6 of 6)"/EXCEPT &
        FCALCULATOR FOO APENNY +

  ASSERT/TEXT="FCALC: NO FILES READ IN (TEST 1 of 1)"/EXCEPT &
        FCALCULATOR FOO 2 2 +

return
