Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gha3mi committed Jan 18, 2024
1 parent 00fc461 commit 952167e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
16 changes: 13 additions & 3 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ license = "LICENSE"
macros = []

[dependencies]
kinds = {git="https://github.com/gha3mi/kinds.git"}
fortime = {git="https://github.com/gha3mi/fortime.git"}
kinds = {git="https://github.com/gha3mi/kinds.git"}
forunittest = {git="https://github.com/gha3mi/forunittest.git"}

[build]
auto-executables = false
Expand All @@ -25,4 +25,14 @@ library = true
[fortran]
implicit-typing = false
implicit-external = false
source-form = "free"
source-form = "free"

[[test]]
name = "test1"
source-dir = "test"
main = "test1.f90"

[[test]]
name = "test2"
source-dir = "test"
main = "test2.f90"
38 changes: 38 additions & 0 deletions test/test1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
program test_dot1

use kinds
use fordot
use forunittest

implicit none

real(rk), allocatable :: u(:), v(:)
real(rk) :: a_ref, a
integer :: m
type(unit_test) :: ut

! a = u(m).v(m)
m = 300

allocate(u(m),v(m))
call random_number(u)
call random_number(v)
u = u*100.0_rk
v = v*100.0_rk

a_ref = dot_product(u,v)

a = dot_product(u,v)
call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot1.1')

a = dot_product(u,v, option='m1')
call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot1.2')

a = dot_product(u,v, option='m2')
call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot1.3')

a = dot_product(u,v, option='m3')
call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot1.4')

end program test_dot1

47 changes: 47 additions & 0 deletions test/test2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
program test_dot2

use kinds
use fordot
use forunittest

implicit none

real(rk), allocatable :: u(:), v(:)
real(rk) :: a_ref, a
integer :: m, im
type(unit_test) :: ut

#if defined(USE_COARRAY)
im = this_image()
#else
im = 1
#endif

! a = u(m).v(n)
m = 500

allocate(u(m),v(m))
call random_number(u)
call random_number(v)
u = u*100.0_rk
v = v*100.0_rk

a_ref = dot_product(u,v)

a = dot_product(u,v,'coarray')
if (im==1) call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot2.1')

a = dot_product(u,v, 'coarray', 'm1')
if (im==1) call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot2.2')

a = dot_product(u,v, 'coarray', 'm2')
if (im==1) call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot2.3')

a = dot_product(u,v, 'coarray', 'm3')
if (im==1) call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot2.4')

a = dot_product(u,v, 'coarray', 'm4')
if (im==1) call ut%check(a, a_ref, tol=1e-5_rk, msg='test_dot2.5')

end program test_dot2

0 comments on commit 952167e

Please sign in to comment.