E.2.9 Statistics Class Unit Test Program

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

program Unit_Test

  use Caesar_Data_Structures_Module
  use Caesar_Statistics_Class
  use Caesar_Numbers_Module, only: one
  implicit none

  type(Statistics_type) :: Variable_Stats
  type(Communication_type) :: Comm

  ! Initialize communications.

  call Initialize (Comm)
  call Output (Comm)
  if (this_is_IO_PE) write (6,*)

  ! Testing statements.

  ! Odd Numbers.

  call Initialize (Variable_Stats, 'Odd Numbers')

  call Add_Value (Variable_Stats, 1.0d0)
  call Add_Value (Variable_Stats, 3.0d0)
  call Add_Value (Variable_Stats, 5.0d0)
  call Add_Value (Variable_Stats, 7.0d0)
  call Add_Value (Variable_Stats, 9.0d0)

  call Output (Variable_Stats, Global=.false., Verbose=.true.)
  if (this_is_IO_PE) write (6,*)
  call Output (Variable_Stats, Global=.true.,  Verbose=.true.)
  if (this_is_IO_PE) write (6,*)

  VERIFY(Valid_State(Variable_Stats),0)

  call Finalize (Variable_Stats)

  ! Powers of 2.

  call Initialize (Variable_Stats, 'Powers of 2')

  call Add_Value (Variable_Stats, 1.0d0)
  call Add_Value (Variable_Stats, 2.0d0)
  call Add_Value (Variable_Stats, 4.0d0)
  call Add_Value (Variable_Stats, 8.0d0)
  call Add_Value (Variable_Stats, 16.0d0)
  call Add_Value (Variable_Stats, 32.0d0)
  call Add_Value (Variable_Stats, 64.0d0)

  call Output (Variable_Stats, Global=.false., Verbose=.true.)
  if (this_is_IO_PE) write (6,*)
  call Output (Variable_Stats, Global=.true.,  Verbose=.true.)
  if (this_is_IO_PE) write (6,*)

  VERIFY(Valid_State(Variable_Stats),0)

  call Finalize (Variable_Stats)

  ! Reciprocals.

  call Initialize (Variable_Stats, 'Reciprocals')

  call Add_Value (Variable_Stats, one/1.0d0)
  call Add_Value (Variable_Stats, one/2.0d0)
  call Add_Value (Variable_Stats, one/3.0d0)
  call Add_Value (Variable_Stats, one/4.0d0)
  call Add_Value (Variable_Stats, one/5.0d0)
  call Add_Value (Variable_Stats, one/6.0d0)
  call Add_Value (Variable_Stats, one/7.0d0)
  call Add_Value (Variable_Stats, one/8.0d0)
  call Add_Value (Variable_Stats, one/9.0d0)
  call Add_Value (Variable_Stats, one/55.0d0)

  call Output (Variable_Stats, Global=.false., Verbose=.true.)
  if (this_is_IO_PE) write (6,*)
  call Output (Variable_Stats, Global=.true.,  Verbose=.true.)
  if (this_is_IO_PE) write (6,*)

  VERIFY(Valid_State(Variable_Stats),0)

  call Finalize (Variable_Stats)

  ! Negatives.

  call Initialize (Variable_Stats, 'Negatives')

  call Add_Value (Variable_Stats, 1.0d0)
  call Add_Value (Variable_Stats, -1.0d0)
  call Add_Value (Variable_Stats, 2.0d0)
  call Add_Value (Variable_Stats, -2.0d0)
  call Add_Value (Variable_Stats, 3.0d0)
  call Add_Value (Variable_Stats, -3.0d0)

  call Output (Variable_Stats, Global=.false., Verbose=.true.)
  if (this_is_IO_PE) write (6,*)
  call Output (Variable_Stats, Global=.true.,  Verbose=.true.)
  if (this_is_IO_PE) write (6,*)

  VERIFY(Valid_State(Variable_Stats),0)

  call Finalize (Variable_Stats)

  ! Parallel test.

  call Initialize (Variable_Stats, 'Parallel Test')

  call Add_Value (Variable_Stats, changetype(real, this_PE))

  call Output (Variable_Stats, Global=.false., Verbose=.true.)
  if (this_is_IO_PE) write (6,*)
  call Output (Variable_Stats, Global=.true.,  Verbose=.true.)

  VERIFY(Valid_State(Variable_Stats),0)

  call Finalize (Variable_Stats)

  ! Finalize communications.

  call Finalize (Comm)

end



Michael L. Hall