Skip to content

Commit

Permalink
Add tests for remaining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidnumerics-joe committed Nov 27, 2023
1 parent 48fd57b commit c6695ab
Show file tree
Hide file tree
Showing 40 changed files with 1,509 additions and 28 deletions.
9 changes: 4 additions & 5 deletions src/FEQParse.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ MODULE FEQParse

INTEGER, PARAMETER, PRIVATE :: Error_Message_Length = 256
INTEGER, PARAMETER, PRIVATE :: Max_Equation_Length = 1024
INTEGER, PARAMETER, PRIVATE :: Max_Function_Length = 6
!INTEGER, PARAMETER, PRIVATE :: Max_Function_Length = 6
INTEGER, PARAMETER, PRIVATE :: Max_Variable_Length = 12
INTEGER, PARAMETER, PRIVATE :: Stack_Length = 128

Expand Down Expand Up @@ -279,15 +279,15 @@ SUBROUTINE Tokenize( parser, tokenized, errorMsg )
parser % inFix % top_index = parser % inFix % top_index + 1
parser % inFix % tokens( parser % inFix % top_index ) % tokenString = ''

j = FindLastFunctionIndex( parser % inFixFormula(i:i+Max_Function_Length-1) )
j = FindLastFunctionIndex( parser % inFixFormula(i:i+feqparse_function_maxlength-1) )

parser % inFix % tokens( parser % inFix % top_index ) % tokenString = parser % inFixFormula(i:i+j)
parser % inFix % tokens( parser % inFix % top_index ) % tokenType = Function_Token
i = i+j+1

! Check to see if the next string
IF( parser % inFixFormula(i:i) /= "(" )THEN
errorMsg = "Missing opening parentheses after token : "//&
errorMsg = "Missing opening parentheses after token : "//&
TRIM( parser % inFix % tokens( parser % inFix % top_index ) % tokenString )

RETURN
Expand Down Expand Up @@ -325,7 +325,6 @@ SUBROUTINE Tokenize( parser, tokenized, errorMsg )

END SUBROUTINE Tokenize


SUBROUTINE ConvertToPostFix( parser )
CLASS( EquationParser ), INTENT(inout) :: parser
! Local
Expand Down Expand Up @@ -424,7 +423,7 @@ FUNCTION Evaluate_sfp32( parser, x ) RESULT( f )
IF( .NOT.( ALLOCATED( parser % postfix % tokens ) ) )THEN

f = 0.0_real32

ELSE

DO k = 1, parser % postfix % top_index
Expand Down
3 changes: 1 addition & 2 deletions src/FEQParse_Functions.F90
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ END FUNCTION IsFunction

FUNCTION FindLastFunctionIndex( eqChar ) RESULT( j )
CHARACTER(*) :: eqChar
INTEGER :: i, j
INTEGER :: i, j

DO i = 1, LEN(eqChar)

IF( eqChar(i:i) == "(" )THEN
j = i-2
EXIT
Expand Down
38 changes: 37 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,51 @@ add_fortran_test_executable (
"sin_r1fp64.f90"
"tan_r1fp64.f90"
"tanh_r1fp64.f90"
"sech_r1fp64.f90"
"abs_r1fp64.f90"
"sqrt_r1fp64.f90"
"acos_r1fp64.f90"
"asin_r1fp64.f90"
"atan_r1fp64.f90"
"log_r1fp64.f90"
"log10_r1fp64.f90"
"random_r1fp64.f90"
"cos_r1fp32.f90"
"sin_r1fp32.f90"
"tan_r1fp32.f90"
"tanh_r1fp32.f90"
"sech_r1fp32.f90"
"abs_r1fp32.f90"
"sqrt_r1fp32.f90"
"acos_r1fp32.f90"
"asin_r1fp32.f90"
"atan_r1fp32.f90"
"log_r1fp32.f90"
"log10_r1fp32.f90"
"random_r1fp32.f90"
"cos_sfp64.f90"
"sin_sfp64.f90"
"tan_sfp64.f90"
"tanh_sfp64.f90"
"sech_sfp64.f90"
"abs_sfp64.f90"
"sqrt_sfp64.f90"
"acos_sfp64.f90"
"asin_sfp64.f90"
"atan_sfp64.f90"
"log_sfp64.f90"
"log10_sfp64.f90"
"random_sfp64.f90"
"cos_sfp32.f90"
"sin_sfp32.f90"
"tan_sfp32.f90"
"tanh_sfp32.f90")
"tanh_sfp32.f90"
"sech_sfp32.f90"
"abs_sfp32.f90"
"sqrt_sfp32.f90"
"acos_sfp32.f90"
"asin_sfp32.f90"
"atan_sfp32.f90"
"log_sfp32.f90"
"log10_sfp32.f90"
"random_sfp32.f90")
41 changes: 41 additions & 0 deletions test/abs_r1fp32.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

INTEGER FUNCTION abs_r1fp32() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real32) :: x(1:N,1:3)
REAL(real32) :: feval(1:N)
REAL(real32) :: fexact(1:N)
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \abs( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real32
do i = 1,N
x(i,1) = -1.0_real32 + (2.0_real32)/REAL(N,real32)*REAL(i-1,real32)
fexact(i) = abs(x(i,1))
enddo

! Evaluate the equation
feval = f % evaluate( x )
IF( MAXVAL(ABS(feval-fexact)) <= epsilon(1.0_real32) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION abs_r1fp32
41 changes: 41 additions & 0 deletions test/abs_r1fp64.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

INTEGER FUNCTION abs_r1fp64() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real64) :: x(1:N,1:3)
REAL(real64) :: feval(1:N)
REAL(real64) :: fexact(1:N)
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \abs( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real64
do i = 1,N
x(i,1) = -1.0_real64 + (2.0_real64)/REAL(N,real64)*REAL(i-1,real64)
fexact(i) = abs(x(i,1))
enddo

! Evaluate the equation
feval = f % evaluate( x )
IF( MAXVAL(ABS(feval-fexact)) <= epsilon(1.0) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION abs_r1fp64
38 changes: 38 additions & 0 deletions test/abs_sfp32.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

INTEGER FUNCTION abs_sfp32() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real32) :: x(1:3)
REAL(real32) :: feval
REAL(real32) :: fexact
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \abs( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real32
fexact = abs(x(1))

! Evaluate the equation
feval = f % evaluate( x )
IF( (ABS(feval-fexact)) <= epsilon(1.0_real32) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION abs_sfp32
38 changes: 38 additions & 0 deletions test/abs_sfp64.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

INTEGER FUNCTION abs_sfp64() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real64) :: x(1:3)
REAL(real64) :: feval
REAL(real64) :: fexact
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \abs( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real64
fexact = abs(x(1))

! Evaluate the equation
feval = f % evaluate( x )
IF( (ABS(feval-fexact)) <= epsilon(1.0_real64) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION abs_sfp64
41 changes: 41 additions & 0 deletions test/acos_r1fp32.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

INTEGER FUNCTION acos_r1fp32() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real32) :: x(1:N,1:3)
REAL(real32) :: feval(1:N)
REAL(real32) :: fexact(1:N)
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \acos( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real32
do i = 1,N
x(i,1) = -1.0_real32 + (2.0_real32)/REAL(N,real32)*REAL(i-1,real32)
fexact(i) = acos(x(i,1))
enddo

! Evaluate the equation
feval = f % evaluate( x )
IF( MAXVAL(ABS(feval-fexact)) <= epsilon(1.0_real32) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION acos_r1fp32
41 changes: 41 additions & 0 deletions test/acos_r1fp64.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

INTEGER FUNCTION acos_r1fp64() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real64) :: x(1:N,1:3)
REAL(real64) :: feval(1:N)
REAL(real64) :: fexact(1:N)
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \acos( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real64
do i = 1,N
x(i,1) = -1.0_real64 + (2.0_real64)/REAL(N,real64)*REAL(i-1,real64)
fexact(i) = acos(x(i,1))
enddo

! Evaluate the equation
feval = f % evaluate( x )
IF( MAXVAL(ABS(feval-fexact)) <= epsilon(1.0) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION acos_r1fp64
38 changes: 38 additions & 0 deletions test/acos_sfp32.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

INTEGER FUNCTION acos_sfp32() RESULT(r)
USE FEQParse
use iso_fortran_env
IMPLICIT NONE
integer, parameter :: N=1000
TYPE(EquationParser) :: f
CHARACTER(LEN=1), DIMENSION(1:3) :: independentVars
CHARACTER(LEN=30) :: eqChar
REAL(real32) :: x(1:3)
REAL(real32) :: feval
REAL(real32) :: fexact
integer :: i

! Specify the independent variables
independentVars = (/ 'x', 'y', 'z' /)

! Specify an equation string that we want to evaluate
eqChar = 'f = \acos( x )'

! Create the EquationParser object
f = EquationParser(eqChar, independentVars)

x = 0.0_real32
fexact = acos(x(1))

! Evaluate the equation
feval = f % evaluate( x )
IF( (ABS(feval-fexact)) <= epsilon(1.0_real32) )THEN
r = 0
ELSE
r = 1
ENDIF

! Clean up memory
CALL f % Destruct()

END FUNCTION acos_sfp32
Loading

0 comments on commit c6695ab

Please sign in to comment.