B.3.7 Integer Class Unit Test Program

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

module Unit_Test_Module
  use Caesar_Integer_Class
  implicit none

contains

  subroutine testint (I)
    type(integer) :: I
    type(logical) :: vs
    write (6,100) 'I = ', I
    vs = Valid_State(I)
    write (6,101) 'Valid_State(I)         ==> ', vs
    100 format (/, a, i14)
    101 format (2x, a, l1)
    return
  end subroutine testint
  
  subroutine testint3 (I3)
    type(integer), pointer, dimension(:,:,:) :: I3
    type(logical) :: vs
    write (6,100) 'I3(1,1,1) = ', I3(1,1,1)
    vs = Valid_State(I3)
    write (6,101) 'Valid_State(I3)        ==> ', vs
    100 format (/, a, i14)
    101 format (2x, a, l1)
    return
  end subroutine testint3
  
end module Unit_Test_Module

program Unit_Test
  use Unit_Test_Module
  use Caesar_Integer_Class
  implicit none

  type(integer) :: I
  type(integer,3) :: I3

  ! Initializations.

  call Initialize (I)
  call Initialize (I3, 3, 4, 5)

  ! Integer tests.

  I = 0
  call testint (I)
  I = HUGE(I)
  call testint (I)
  I = -HUGE(I)
  call testint (I)

  I3(1,1,1) = 0
  call testint3 (I3)
  I3(1,1,1) = HUGE(I3)
  call testint3 (I3)
  I3(1,1,1) = -HUGE(I3)
  call testint3 (I3)

  ! Note that the compiler figures out the error unless it is given in 
  ! two steps, as follows. Also, note that adding 1 to HUGE wraps to
  ! a low negative number, as does subtracting 2 from -HUGE. 

  I = HUGE(I)
  I = I+1
  call testint (I)
  I = -HUGE(I)
  I = I-2
  call testint (I)

  I3(1,1,1) = HUGE(I3)
  I3(1,1,1) = I3(1,1,1)+1
  call testint3 (I3)
  I3(1,1,1) = -HUGE(I3)
  I3(1,1,1) = I3(1,1,1)-2
  call testint3 (I3)

  ! The bottom line is that there are really no invalid integers. The
  ! Valid_State_Integer routine is primarily added for completeness.

  ! Integer scalar function tests.

  I = 123456789
  write (6,*) 'MaxVal(I) = ', MaxVal(I)
  write (6,*) 'MinVal(I) = ', MinVal(I)
  write (6,*) 'SUM(I)    = ', SUM(I)

  ! Finalizations.

  call Finalize (I)
  call Finalize (I3)

end



Michael L. Hall