!----------------------------------------------------------------------
!     Copyright (c) 2016 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  tee_module テストプログラム (積分・平均計算)
!
!履歴  2016/09/20  竹広真一
!
program tee_mpi_module_integral_test

  use dc_message, only : MessageNotify
  use dc_test, only : AssertEqual
  use tee_mpi_module
  use mpi
  implicit none

 !---- 空間解像度設定 ----
  integer, parameter :: im=32, jm=32, km=32       ! 格子点の設定(X,Y)
  integer, parameter :: lm=10, mm=10, nm=21       ! 切断波数の設定(X,Y)

 !---- 変数 ----
  real(8), allocatable :: zvx_Data(:,:,:)         ! 格子データ
  real(8), allocatable :: vx_Data(:,:)            ! 格子データ
  real(8), allocatable :: zx_Data(:,:)            ! 格子データ
  real(8), allocatable :: zv_Data(:,:)            ! 格子データ
  real(8), allocatable :: x_Data(:)               ! 格子データ
  real(8), allocatable :: v_Data(:)               ! 格子データ
  real(8), allocatable :: z_Data(:)               ! 格子データ

  real(8), allocatable :: vx_Ans(:,:)             ! 格子データ
  real(8), allocatable :: zv_Ans(:,:)             ! 格子データ
  real(8), allocatable :: zx_Ans(:,:)             ! 格子データ

  real(8), allocatable :: x_Ans(:)                ! 格子データ
  real(8), allocatable :: v_Ans(:)                ! 格子データ
  real(8), allocatable :: z_Ans(:)                ! 格子データ

  real(8)              :: Ans

  integer            :: np, ip, ierr
  
 !---- 座標変数など ----
  real(8), parameter :: xmin = -1.0d0, xmax=1.0d0
  real(8), parameter :: ymin = -1.0d0, ymax=1.0d0
  real(8), parameter :: zmin = -1.0d0, zmax=1.0d0

  real(8), parameter :: pi=3.1415926535897932385D0

  ! 判定誤差設定
  integer, parameter :: check_digits = 11
  integer, parameter :: ignore = -12

  call MessageNotify('M','tee_mpi_module_integral_test', &
       'tee_mpi_module integral and average functions tests')

 !---------------- MPI スタート ---------------------
  call MPI_INIT(IERR)
  call MPI_COMM_RANK(MPI_COMM_WORLD,IP,IERR)
  call MPI_COMM_SIZE(MPI_COMM_WORLD,NP,IERR)
   
 !---------------- 座標値の設定 ---------------------
  call tee_mpi_initial(im,jm,km,lm,mm,nm,xmin,xmax,ymin,ymax,zmin,zmax) 

  allocate(zvx_Data(0:km,jc(ip),0:im-1))         ! 格子データ
  allocate(vx_Data(jc(ip),0:im-1))               ! 格子データ
  allocate(zx_Data(0:km,0:im-1))                 ! 格子データ
  allocate(zv_Data(0:km,jc(ip)))                 ! 格子データ
  allocate(x_Data(0:im-1))                       ! 格子データ
  allocate(v_Data(jc(ip)))                       ! 格子データ
  allocate(z_Data(0:km))                         ! 格子データ

  allocate(vx_Ans(jc(ip),0:im-1))                ! 格子データ
  allocate(zv_Ans(0:km,jc(ip)))                  ! 格子データ
  allocate(zx_Ans(0:km,0:im-1))                  ! 格子データ

  allocate(x_Ans(0:im-1))                        ! 格子データ
  allocate(v_Ans(jc(ip)))                        ! 格子データ
  allocate(z_Ans(0:km))                          ! 格子データ

 !------------------- 3 次元関数チェック ----------------------
  zvx_Data = sin(pi*zvx_X) * cos(pi*zvx_Y) * cos(pi*zvx_Z)

  Ans = 0.0D0
  call AssertEqual(&
    message='IntZYX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',      &
    answer = Ans,                                                 &
    check = IntZYX_zvx(zvx_Data),                                 &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='AvrZYX_vx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',       &
    answer = Ans,                                                 &
    check = AvrZYX_zvx(zvx_Data),                                 &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  vx_Ans = 0.0D0
  call AssertEqual(&
    message='vx_IntZ_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = vx_Ans,                                              &
    check = vx_IntZ_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='vx_AvrZ_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = vx_Ans,                                              &
    check = vx_AvrZ_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zv_Ans = 0.0D0
  call AssertEqual(&
    message='zv_IntX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = zv_Ans,                                              &
    check = zv_IntX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zv_AvrX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = zv_Ans,                                              &
    check = zv_AvrX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zx_Ans = 0.0D0
  call AssertEqual(&
    message='zx_IntY_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = zx_Ans,                                              &
    check = zx_IntY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zx_AvrY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = zx_Ans,                                              &
    check = zx_AvrY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 0.0D0
  call AssertEqual(&
    message='z_IntYX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = z_Ans,                                               &
    check = z_IntYX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='z_AvrYX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = z_Ans,                                               &
    check = z_AvrYX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 0.0D0
  call AssertEqual(&
    message='v_IntZX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = v_Ans,                                               &
    check = v_IntZX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='y_AvrZX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = v_Ans,                                               &
    check = v_AvrZX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 0.0D0
  call AssertEqual(&
    message='x_IntZY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = x_Ans,                                               &
    check = x_IntZY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='x_AvrZY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = x_Ans,                                               &
    check = x_AvrZY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zvx_Data = (1 - sin(pi*zvx_X)) * cos(pi*zvx_Y)**2 * sin(pi*zvx_Z)**2

  Ans = 2.0D0
  call AssertEqual(&
    message='IntZYX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',      &
    answer = Ans,                                                 &
    check = IntZYX_zvx(zvx_Data),                                 &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.25D0
  call AssertEqual(&
    message='AvrZYX_vx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',       &
    answer = Ans,                                                 &
    check = AvrZYX_zvx(zvx_Data),                                 &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  vx_Ans = (1 - sin(pi*vx_X)) * cos(pi*vx_Y)**2 
  call AssertEqual(&
    message='vx_IntZ_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = vx_Ans,                                              &
    check = vx_IntZ_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  vx_Ans = (1 - sin(pi*vx_X)) * cos(pi*vx_Y)**2/2.0D0
  call AssertEqual(&
    message='vx_AvrZ_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = vx_Ans,                                              &
    check = vx_AvrZ_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zv_Ans = 2*cos(pi*zv_Y)**2 * sin(pi*zv_Z)**2
  call AssertEqual(&
    message='zv_IntX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = zv_Ans,                                              &
    check = zv_IntX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  zv_Ans = cos(pi*zv_Y)**2 * sin(pi*zv_Z)**2
  call AssertEqual(&
    message='zv_AvrX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = zv_Ans,                                              &
    check = zv_AvrX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zx_Ans = (1 - sin(pi*zx_X)) *  sin(pi*zx_Z)**2
  call AssertEqual(&
    message='zx_IntY_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = zx_Ans,                                              &
    check = zx_IntY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  zx_Ans = (1 - sin(pi*zx_X)) *  sin(pi*zx_Z)**2/2.0D0
  call AssertEqual(&
    message='zx_AvrY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = zx_Ans,                                              &
    check = zx_AvrY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 2*sin(pi*z_Z)**2
  call AssertEqual(&
    message='z_IntYX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = z_Ans,                                               &
    check = z_IntYX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  z_Ans = sin(pi*z_Z)**2/2.0D0
  call AssertEqual(&
    message='z_AvrYX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = z_Ans,                                               &
    check = z_AvrYX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 2*cos(pi*v_Y)**2
  call AssertEqual(&
    message='v_IntZX_zvx with sin(pi*X)p*cos(pi*Y)*cos(pi*Z)',    &
    answer = v_Ans,                                               &
    check = v_IntZX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  v_Ans = cos(pi*v_Y)**2/2.0D0
  call AssertEqual(&
    message='v_AvrZX_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = v_Ans,                                               &
    check = v_AvrZX_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 1 - sin(pi*x_X)
  call AssertEqual(&
    message='x_IntZY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = x_Ans,                                               &
    check = x_IntZY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  x_Ans = (1 - sin(pi*x_X))/4.0D0
  call AssertEqual(&
    message='x_AvrZY_zvx with sin(pi*X)*cos(pi*Y)*cos(pi*Z)',     &
    answer = x_Ans,                                               &
    check = x_AvrZY_zvx(zvx_Data),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

 !------------------- 2 次元関数チェック ----------------------
  ! YX データ

  vx_Data = sin(pi*vx_X) * cos(pi*vx_Y)

  Ans = 0.0D0
  call AssertEqual(&
    message='IntYX_vx with sin(pi*X)*cos(pi*Y)',                  &
    answer = Ans,                                                 &
    check = IntYX_vx(vx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='AvrYX_vx with sin(pi*X)*cos(pi*Y)',                  &
    answer = Ans,                                                 &
    check = AvrYX_vx(vx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 0.0D0
  call AssertEqual(&
    message='v_IntX_vx with sin(pi*X)*cos(pi*Y)',                 &
    answer = v_Ans,                                               &
    check = v_IntX_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='v_AvrX_vx with sin(pi*X)*cos(pi*Y)',                 &
    answer = v_Ans,                                               &
    check = v_AvrX_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 0.0D0
  call AssertEqual(&
    message='x_IntY_vx with sin(pi*X)*cos(pi*Y)',                 &
    answer = x_Ans,                                               &
    check = x_IntY_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='x_AvrY_vx with sin(pi*X)*cos(pi*Y)',                 &
    answer = x_Ans,                                               &
    check = x_AvrY_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  vx_Data = (1 - sin(pi*vx_X)) * cos(pi*vx_Y)**2

  Ans = 2.0D0
  call AssertEqual(&
    message='IntYX_vx with (1-sin(pi*X)) * cos(pi*Y)**2',         &
    answer = Ans,                                                 &
    check = IntYX_vx(vx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrYX_vx with (1-sin(pi*X)) * cos(pi*Y)**2',         &
    answer = Ans,                                                 &
    check = AvrYX_vx(vx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 2*cos(pi*v_Y)**2
  call AssertEqual(&
    message='v_IntX_vx with (1-sin(pi*X)) * cos(pi*Y)**2',        &
    answer = v_Ans,                                               &
    check = v_IntX_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  v_Ans = cos(pi*v_Y)**2
  call AssertEqual(&
    message='v_AvrX_vx with (1-sin(pi*X)) * cos(pi*Y)**2',        &
    answer = v_Ans,                                               &
    check = v_AvrX_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 1 - sin(pi*x_X)
  call AssertEqual(&
    message='x_IntY_vx with (1-sin(pi*X)) * cos(pi*Y)**2',        &
    answer = x_Ans,                                               &
    check = x_IntY_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  x_Ans = 0.5*(1 - sin(pi*x_X))
  call AssertEqual(&
    message='x_AvrY_vx with (1-sin(pi*X)) * cos(pi*Y)**2',        &
    answer = x_Ans,                                               &
    check = x_AvrY_vx(vx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  ! ZY データ
  zv_Data = sin(pi*zv_Z) * cos(pi*zv_Y)

  Ans = 0.0D0
  call AssertEqual(&
    message='IntZY_zv with sin(pi*Z)*cos(pi*Y)',                  &
    answer = Ans,                                                 &
    check = IntZY_zv(zv_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='AvrZY_zv with sin(pi*Z)*cos(pi*Y)',                  &
    answer = Ans,                                                 &
    check = AvrZY_zv(zv_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 0.0D0
  call AssertEqual(&
    message='v_IntX_zv with sin(pi*Z)*cos(pi*Y)',                 &
    answer = v_Ans,                                               &
    check = v_IntZ_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='v_AvrZ_zv with sin(pi*Z)*cos(pi*Y)',                 &
    answer = v_Ans,                                               &
    check = v_AvrZ_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 0.0D0
  call AssertEqual(&
    message='z_IntY_zv with sin(pi*Z)*cos(pi*Y)',                 &
    answer = z_Ans,                                               &
    check = z_IntY_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='z_AvrY_zv with sin(pi*Z)*cos(pi*Y)',                 &
    answer = z_Ans,                                               &
    check = z_AvrY_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zv_Data = (1 - sin(pi*zv_Z)) * cos(pi*zv_Y)**2

  Ans = 2.0D0
  call AssertEqual(&
    message='IntZY_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',         &
    answer = Ans,                                                 &
    check = IntZY_zv(zv_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrZY_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',         &
    answer = Ans,                                                 &
    check = AvrZY_zv(zv_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Ans = 2*cos(pi*v_Y)**2
  call AssertEqual(&
    message='v_IntZ_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',        &
    answer = v_Ans,                                               &
    check = v_IntZ_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  v_Ans = cos(pi*v_Y)**2
  call AssertEqual(&
    message='v_AvrZ_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',        &
    answer = v_Ans,                                               &
    check = v_AvrZ_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 1 - sin(pi*z_Z)
  call AssertEqual(&
    message='z_IntY_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',        &
    answer = z_Ans,                                               &
    check = z_IntY_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  z_Ans = 0.5*(1 - sin(pi*z_Z))
  call AssertEqual(&
    message='z_AvrY_zv with (1-sin(pi*Z)) * cos(pi*Y)**2',        &
    answer = z_Ans,                                               &
    check = z_AvrY_zv(zv_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  ! ZX データ
  zx_Data = sin(pi*zx_Z) * cos(pi*zx_X)

  Ans = 0.0D0
  call AssertEqual(&
    message='IntZX_zx with sin(pi*Z)*cos(pi*X)',                  &
    answer = Ans,                                                 &
    check = IntZX_zx(zx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='AvrZX_zx with sin(pi*Z)*cos(pi*X)',                  &
    answer = Ans,                                                 &
    check = AvrZX_zx(zx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 0.0D0
  call AssertEqual(&
    message='x_IntZ_zx with sin(pi*Z)*cos(pi*X)',                 &
    answer = x_Ans,                                               &
    check = x_IntZ_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='x_AvrZ_zx with sin(pi*Z)*cos(pi*X)',                 &
    answer = x_Ans,                                               &
    check = x_AvrZ_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 0.0D0
  call AssertEqual(&
    message='z_IntX_zx with sin(pi*Z)*cos(pi*X)',                 &
    answer = z_Ans,                                               &
    check = z_IntX_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='z_AvrX_zx with sin(pi*Z)*cos(pi*X)',                 &
    answer = z_Ans,                                               &
    check = z_AvrX_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zx_Data = (1 - sin(pi*zx_Z)) * cos(pi*zx_X)**2

  Ans = 2.0D0
  call AssertEqual(&
    message='IntZX_zx with (1-sin(pi*Z)) * cos(pi*X)**2',         &
    answer = Ans,                                                 &
    check = IntZX_zx(zx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrZX_zx with (1-sin(pi*Z)) * cos(pi*X)**2',         &
    answer = Ans,                                                 &
    check = AvrZX_zx(zx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  x_Ans = 2*cos(pi*x_X)**2
  call AssertEqual(&
    message='x_IntZ_zx with (1-sin(pi*Z)) * cos(pi*X)**2',        &
    answer = x_Ans,                                               &
    check = x_IntZ_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  x_Ans = cos(pi*x_X)**2
  call AssertEqual(&
    message='x_AvrZ_zx with (1-sin(pi*Z)) * cos(pi*X)**2',        &
    answer = x_Ans,                                               &
    check = x_AvrZ_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Ans = 1 - sin(pi*z_Z)
  call AssertEqual(&
    message='z_IntX_zx with (1-sin(pi*Z)) * cos(pi*X)**2',        &
    answer = z_Ans,                                               &
    check = z_IntX_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  z_Ans = 0.5*(1 - sin(pi*z_Z))
  call AssertEqual(&
    message='z_AvrX_zx with (1-sin(pi*Z)) * cos(pi*X)**2',        &
    answer = z_Ans,                                               &
    check = z_AvrX_zx(zx_Data),                                   &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

 !------------------- 1 次元関数チェック ----------------------
  x_Data = 1 - sin(2*pi*x_X)

  Ans = 2.0D0
  call AssertEqual(&
    message='IntX_x with 1-sin(2*pi*X)',                          &
    answer = Ans,                                                 &
    check = IntX_x(x_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 1.0D0
  call AssertEqual(&
    message='AvrX_x with 1-sin(2*pi*X)',                          &
    answer = Ans,                                                 &
    check = AvrX_x(x_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Data = cos(pi*v_Y)**2

  Ans = 1.0D0
  call AssertEqual(&
    message='IntY_v with cos(pi*X)**2',                           &
    answer = Ans,                                                 &
    check = IntY_v(v_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrY_v with cos(pi*X)**2',                           &
    answer = Ans,                                                 &
    check = AvrY_v(v_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Data = sin(pi*z_Z)**2

  Ans = 1.0D0
  call AssertEqual(&
    message='IntZ_z with sin(pi*Z)**2',                           &
    answer = Ans,                                                 &
    check = IntZ_z(z_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

 !------------------- 1 次元関数チェック ----------------------
  x_Data = 1 - sin(2*pi*x_X)

  Ans = 2.0D0
  call AssertEqual(&
    message='IntX_x with 1-sin(2*pi*X)',                          &
    answer = Ans,                                                 &
    check = IntX_x(x_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 1.0D0
  call AssertEqual(&
    message='AvrX_x with 1-sin(2*pi*X)',                          &
    answer = Ans,                                                 &
    check = AvrX_x(x_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  v_Data = cos(pi*v_Y)**2

  Ans = 1.0D0
  call AssertEqual(&
    message='IntY_v with cos(pi*X)**2',                           &
    answer = Ans,                                                 &
    check = IntY_v(v_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrY_v with cos(pi*X)**2',                           &
    answer = Ans,                                                 &
    check = AvrY_v(v_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  z_Data = sin(pi*z_Z)**2

  Ans = 1.0D0
  call AssertEqual(&
    message='IntZ_z with sin(pi*Z)**2',                           &
    answer = Ans,                                                 &
    check = IntZ_z(z_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  Ans = 0.5D0
  call AssertEqual(&
    message='AvrZ_z with sin(pi*Z)**2',                           &
    answer = Ans,                                                 &
    check = AvrZ_z(z_Data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  
  call MPI_FINALIZE(IERR)
  
  call MessageNotify('M','tee_mpi_module_integral_test', &
       'tee_mpi_module integral and average functions tests succeeded')

end program tee_mpi_module_integral_test
