## B.4.11 Logical Class Unit Test Program

This lightly commented program performs a unit test on the Logical Class.

```program Unit_Test
use Caesar_Logical_Class
implicit none

type(logical) :: L
type(logical,3) :: L3

! Initialize logicals.

call Initialize (L)
call Initialize (L3, 3, 4, 5)

! Logical Valid_State tests.

L = .false.
write (6,*) 'Valid_State L =', Valid_State(L)
L = .true.
write (6,*) 'Valid_State L =', Valid_State(L)
L3 = .false.
write (6,*) 'Valid_State L3 =', Valid_State(L3)
L3 = .true.
write (6,*) 'Valid_State L3 =', Valid_State(L3)

! Logical scalar function tests.

L = .false.
write (6,*) 'COUNT(L) =', COUNT(L)
write (6,*) 'ALL(L) =', ALL(L)
write (6,*) 'ANY(L) =', ANY(L)
L = .true.
write (6,*) 'COUNT(L) =', COUNT(L)
write (6,*) 'ALL(L) =', ALL(L)
write (6,*) 'ANY(L) =', ANY(L)

! Logical interval tests.

write (6,*) 'Following intervals should use brackets, '
write (6,*) 'but they are not available in F90.'
write (6,*) 'Is 1 in (1,99)?:', 1 .InInterval. (/1, 99/)
write (6,*) 'Is 5 in (3,7)?:', 5 .InInterval. (/3, 7/)
write (6,*) 'Is (6,3,4) in (3,7)?:', &
(/6, 3, 4/) .InInterval. (/3, 7/)
write (6,*) 'Is (6,3,4,8) in (3,7)?:', &
(/6, 3, 4, 8/) .InInterval. (/3, 7/)
write (6,*) 'Is 1.0 in (1.0,99.0)?:', 1.d0 .InInterval. (/1.d0, 99.d0/)
write (6,*) 'Is 3.14159 in (2.3,10.4)?:', &
3.14159d0 .InInterval. (/2.3d0, 10.4d0/)
write (6,*) 'Is (3.14159,4.2,5.8) in (2.3,10.4)?:', &
(/3.14159d0, 4.2d0, 5.8d0/) .InInterval. (/2.3d0, 10.4d0/)
write (6,*) 'Is (3.14159,4.2,5.8,14.0) in (2.3,10.4)?:', &
(/3.14159d0, 4.2d0, 5.8d0, 14.d0/) .InInterval. (/2.3d0, 10.4d0/)

write (6,*) 'Is 1 not in (1,99)?:', 1 .NotInInterval. (/1, 99/)
write (6,*) 'Is 1 not in (3,7)?:', 1 .NotInInterval. (/3, 7/)
write (6,*) 'Is (6,3,4) not in (3,7)?:', &
(/6, 3, 4/) .NotInInterval. (/3, 7/)
write (6,*) 'Is (16,-3,14,8) not in (3,7)?:', &
(/16, -3, 14, 8/) .NotInInterval. (/3, 7/)
write (6,*) 'Is 1.0 not in (1.0,99.0)?:', 1.d0 .NotInInterval. (/1.d0, 99.d0/)
write (6,*) 'Is 3.14159 not in (2.3,10.4)?:', &
3.14159d0 .NotInInterval. (/2.3d0, 10.4d0/)
write (6,*) 'Is (3.14159,4.2,5.8) not in (2.3,10.4)?:', &
(/3.14159d0, 4.2d0, 5.8d0/) .NotInInterval. (/2.3d0, 10.4d0/)
write (6,*) 'Is (-3.14159,14.2,-5.8,14.0) not in (2.3,10.4)?:', &
(/-3.14159d0, 14.2d0, -5.8d0, 14.d0/) &
.NotInInterval. (/2.3d0, 10.4d0/)

! Finalize logicals.

call Finalize (L)
call Finalize (L3)

end
```

Michael L. Hall