From cf2f711d0ed25ef273f7820bdf4b4938d4421c3d Mon Sep 17 00:00:00 2001 From: "Nakib H. Protik" Date: Fri, 23 Aug 2024 15:28:51 +0200 Subject: [PATCH] Added unit tests for the grid-representation change of vector_allreps. --- src/vector.f90 | 4 ++- test/test_vector_allreps.f90 | 64 +++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/vector.f90 b/src/vector.f90 index aa2b0c4..1cea5dc 100644 --- a/src/vector.f90 +++ b/src/vector.f90 @@ -102,7 +102,9 @@ pure function vector_allreps_sub(v1, v2, grid, primitive_vecs) result(v3) end function vector_allreps_sub pure function vector_allreps_change_grid(vin, grid) result(vout) - !! Change grid + !! Change grid. + !! Beware, this is only well-defined is the vector is representable + !! in both original and the new grids. type(vector_allreps), intent(in) :: vin integer(i64), intent(in) :: grid(3) diff --git a/test/test_vector_allreps.f90 b/test/test_vector_allreps.f90 index 004c9ce..96c6bce 100644 --- a/test/test_vector_allreps.f90 +++ b/test/test_vector_allreps.f90 @@ -4,18 +4,18 @@ program test_vector_allreps use testify_m, only : testify use vector_allreps_module, only : & vector_allreps, vector_allreps_add, vector_allreps_sub, & - vector_allreps_print + vector_allreps_print, vector_allreps_change_grid implicit none integer :: itest - integer, parameter :: num_tests = 17 + integer, parameter :: num_tests = 25 !17 type(testify) :: test_array(num_tests), tests_all - integer(i64) :: imuxed, grid(3) + integer(i64) :: imuxed, grid(3), another_grid(3) real(r64) :: primitive_vecs(3, 3) !integer(i64), parameter :: N = 3 - type(vector_allreps) :: v0, v1, v2, v3 + type(vector_allreps) :: v0, v1, v2, v3, v0p, v1p, v2p print*, '<>' @@ -137,7 +137,61 @@ program test_vector_allreps call test_array(itest)%assert(& v3%cart, & [-3.0, 2.0, 3.0]/8.0_r64) - + + !Test grid change + another_grid = [12, 12, 12] !3x first grid + + ! zero vector, everything should be unchanged + v0p = vector_allreps_change_grid(v0, another_grid) + + itest = itest + 1 + test_array(itest) = testify("grid change null vector, muxed index") + call test_array(itest)%assert(v0p%muxed_index, 1_i64) + + itest = itest + 1 + test_array(itest) = testify("grid change null vector, integer rep") + call test_array(itest)%assert(& + v0p%int, & + [0, 0, 0]*1_i64) + + itest = itest + 1 + test_array(itest) = testify("grid change null vector, fractional rep") + call test_array(itest)%assert(& + v0p%frac, & + [0.0, 0.0, 0.0]*1.0_r64) + + itest = itest + 1 + test_array(itest) = testify("grid change null vector, Cartesian rep") + call test_array(itest)%assert(& + v0p%cart, & + [0.0, 0.0, 0.0]*1.0_r64) + + ! test the last vector of original grid + v1 = vector_allreps(product(grid), grid, primitive_vecs) + v1p = vector_allreps_change_grid(v1, another_grid) + + itest = itest + 1 + test_array(itest) = testify("grid change last vector, muxed index") + call test_array(itest)%assert(v1p%muxed_index, 1414_i64) + + itest = itest + 1 + test_array(itest) = testify("grid change last vector, integer rep") + call test_array(itest)%assert(& + v1p%int, & + [9, 9, 9]*1_i64) + + itest = itest + 1 + test_array(itest) = testify("grid change last vector, fractional rep") + call test_array(itest)%assert(& + v1p%frac, & + v1%frac) + + itest = itest + 1 + test_array(itest) = testify("grid change last vector, Cartesian rep") + call test_array(itest)%assert(& + v1p%cart, & + v1%cart) + tests_all = testify(test_array) call tests_all%report