@@ -16,6 +16,7 @@ program tests
16
16
call fptest4()
17
17
call fptest5()
18
18
call fptest6()
19
+ call error_tests()
19
20
20
21
contains
21
22
! *******************************************************************************
@@ -257,22 +258,30 @@ subroutine fptest6()
257
258
258
259
implicit none
259
260
260
- integer , parameter :: nfunc = 5
261
+ integer , parameter :: nfunc = 12
261
262
character (len=* ), dimension (nfunc), parameter :: func = [ ' -1.0*x ' , &
262
263
' -sqrt(x) ' , &
263
264
' a*COS(b*x)+5 ' , &
264
265
' a*COS(b*x)+5.0 ' , &
265
- ' exp(x)-abs(x)+log(1.0)+log10(1.0)' ]
266
- integer , parameter :: nvar = 3
266
+ ' exp(x)-abs(x)+log(1.0)+log10(1.0)' ,&
267
+ ' sinh(x) ' , &
268
+ ' cosh(x) ' , &
269
+ ' tanh(x) ' , &
270
+ ' tan(x) ' , &
271
+ ' asin(y) ' , &
272
+ ' acos(y) ' , &
273
+ ' atan(y) ' ]
274
+ integer , parameter :: nvar = 4
267
275
character (len=* ), dimension (nvar), parameter :: var = [ ' x' , &
268
276
' a' , &
269
- ' b' ]
270
- real (wp), dimension (nvar), parameter :: val = [ 2.0_wp , 3.0_wp , 4.0_wp ]
277
+ ' b' , &
278
+ ' y' ]
279
+ real (wp), dimension (nvar), parameter :: val = [ 2.0_wp , 3.0_wp , 4.0_wp , 0.1_wp ]
271
280
272
281
type (fparser_array) :: parser
273
282
real (wp),dimension (nfunc) :: res
274
283
integer :: i ! ! counter
275
- real (wp) :: x,a,b
284
+ real (wp) :: x,a,b,y
276
285
277
286
write (* ,* ) ' '
278
287
write (* ,* ) ' Test 6'
@@ -292,16 +301,100 @@ subroutine fptest6()
292
301
x = val(1 )
293
302
a = val(2 )
294
303
b = val(3 )
295
- call compare(func(1 ), - 1.0_wp * x, res(1 ))
296
- call compare(func(2 ), - sqrt (x), res(2 ))
297
- call compare(func(3 ), a* cos (b* x)+ 5 , res(3 ))
298
- call compare(func(4 ), a* cos (b* x)+ 5.0 , res(4 ))
299
- call compare(func(5 ), exp (x)- abs (x)+ log (1.0 )+ log10 (1.0 ), res(5 ))
304
+ y = val(4 )
305
+ call compare(func(1 ), - 1.0_wp * x, res(1 ))
306
+ call compare(func(2 ), - sqrt (x), res(2 ))
307
+ call compare(func(3 ), a* cos (b* x)+ 5 , res(3 ))
308
+ call compare(func(4 ), a* cos (b* x)+ 5.0 , res(4 ))
309
+ call compare(func(5 ), exp (x)- abs (x)+ log (1.0 )+ log10 (1.0 ), res(5 ))
310
+ call compare(func(6 ), sinh (x), res(6 ))
311
+ call compare(func(7 ), cosh (x), res(7 ))
312
+ call compare(func(8 ), tanh (x), res(8 ))
313
+ call compare(func(9 ), tan (x), res(9 ))
314
+ call compare(func(10 ), asin (y), res(10 ))
315
+ call compare(func(11 ), acos (y), res(11 ))
316
+ call compare(func(12 ), atan (y), res(12 ))
300
317
end if
301
318
302
319
end subroutine fptest6
303
320
! *******************************************************************************
304
321
322
+ ! *******************************************************************************
323
+ ! >
324
+ ! Test some of the error cases.
325
+
326
+ subroutine error_tests ()
327
+
328
+ implicit none
329
+
330
+ integer , parameter :: nvar = 3
331
+ character (len=* ), dimension (nvar), parameter :: var = [ ' x' , &
332
+ ' a' , &
333
+ ' b' ]
334
+ real (wp), dimension (nvar), parameter :: val = [ 2.0_wp , 3.0_wp , 4.0_wp ]
335
+ type (fparser_array) :: parser
336
+
337
+ write (* ,* ) ' '
338
+ write (* ,* ) ' Test 7 - Test error conditions'
339
+ write (* ,* ) ' '
340
+
341
+ call parse_error(parser,' st(-x)' ,var,val)
342
+ call parse_error(parser,' x * 452d3234.2323' ,var,val)
343
+ call parse_error(parser,' x * (123' ,var,val)
344
+ call parse_error(parser,' x +-* y' ,var,val)
345
+ call parse_error(parser,' x + sin' ,var,val)
346
+ call parse_error(parser,' -(1) + (+x) + ()' ,var,val)
347
+ call parse_error(parser,' x +' ,var,val)
348
+
349
+ call eval_error(parser,' sqrt(-x)' ,var,val)
350
+ call eval_error(parser,' acos(10.0)' ,var,val)
351
+ call eval_error(parser,' asin(10.0)' ,var,val)
352
+ call eval_error(parser,' log(-x)' ,var,val)
353
+ call eval_error(parser,' log10(-x)' ,var,val)
354
+ call eval_error(parser,' 1/0' ,var,val)
355
+
356
+ end subroutine error_tests
357
+ ! *******************************************************************************
358
+
359
+ subroutine parse_error (parser ,str ,var ,val )
360
+ type (fparser_array),intent (inout ) :: parser
361
+ character (len=* ),intent (in ) :: str ! ! expression with a parsing error
362
+ real (wp),dimension (1 ) :: res
363
+ character (len=* ),dimension (:),intent (in ) :: var
364
+ real (wp),dimension (:),intent (in ) :: val
365
+ call parser% parse([str], var) ! parse and bytecompile function string
366
+ if (parser% error()) then
367
+ call parser% print_errors(output_unit)
368
+ write (* ,* ) ' PASSED : parsing error'
369
+ else
370
+ error stop ' FAILED : there should have been a parsing error'
371
+ end if
372
+ call parser% clear_errors()
373
+ call parser% destroy()
374
+ end subroutine parse_error
375
+
376
+ subroutine eval_error (parser ,str ,var ,val )
377
+ type (fparser_array),intent (inout ) :: parser
378
+ character (len=* ),intent (in ) :: str ! ! expression with a parsing error
379
+ real (wp),dimension (1 ) :: res
380
+ character (len=* ),dimension (:),intent (in ) :: var
381
+ real (wp),dimension (:),intent (in ) :: val
382
+ call parser% parse([str], var, .True. ) ! parse and bytecompile function string [case sensitive]
383
+ if (parser% error()) then
384
+ call parser% print_errors(output_unit)
385
+ error stop
386
+ end if
387
+ call parser% evaluate(val,res) ! interprete bytecode representation of function
388
+ if (parser% error()) then
389
+ call parser% print_errors(output_unit)
390
+ write (* ,* ) ' PASSED : evaluation errors detected'
391
+ else
392
+ error stop ' FAILED : there should have been evaluation errors'
393
+ end if
394
+ call parser% clear_errors()
395
+ call parser% destroy()
396
+ end subroutine eval_error
397
+
305
398
! *******************************************************************************
306
399
! >
307
400
! Compare the results from the parser to the actualy expression
0 commit comments