!----------------------------------------------------------------------
! Copyright(c) 2009-2011 SPMODEL Development Group. All rights reserved.
!----------------------------------------------------------------------
!
!表題  INDEXX :" 小さい順番号付け テストプログラム
!
!履歴  2009/02/06  竹広真一
!      2011/03/06  佐々木洋平
!
program indexx_test

  use dc_message, only : MessageNotify
  use dc_types, only: DP
  use dc_test, only : AssertEqual
  use spml_utils, only: indexx
  implicit none

  integer, parameter         :: narray = 5
  real(DP), dimension(narray) :: array
  integer, dimension(narray) :: indary
  integer, dimension(narray) :: indary_sol

  array = (/-1.0D0, 1.0D0, -3.0D0, 2.0D0, 0.0D0/)
  indary = indexx(array)

  call MessageNotify('M','indexx_test','test of index sorting')

  indary_sol = (/3,1,5,2,4/)
  call AssertEqual(                            &
    message = 'Index check, increasing order', &
    answer  =  indary_sol,                     &
    check   =  indary )

  indary_sol = (/4,2,5,1,3/)
  call AssertEqual(                            &
    message = 'Index check, decreasing order', &
    answer  =  indary_sol,                     &
    check   =  indary(narray:1:-1) )

  call MessageNotify('M','indexx_test','test of index sorting succeeded!')

end program indexx_test
