Skip to content

Commit

Permalink
Merge pull request #4 from gha3mi/dev
Browse files Browse the repository at this point in the history
Utilize ForUnitTest for unit testing.
  • Loading branch information
gha3mi authored Apr 28, 2024
2 parents 03e8409 + bb0f64e commit 83888c9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Added `CHANGELOG.md` file.
- Added `CONTRIBUTING.md` file.
- Updated `README.md` file.
- Add NURBS surface to PPM conversion examples.
- Add NURBS surface to PPM conversion examples.
- Utilize ForUnitTest for testing.
3 changes: 3 additions & 0 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ forimage = {git="https://github.com/gha3mi/forimage.git"}
forcolormap = {git="https://github.com/vmagnin/forcolormap.git"}
fortime = {git="https://github.com/gha3mi/fortime.git"}

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

[[example]]
name = "demo_curve"
source-dir = "example"
Expand Down
14 changes: 8 additions & 6 deletions test/test_curve.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
program test_curve

use forcad, only: rk, nurbs_curve
use forunittest, only: unit_test

implicit none
type(nurbs_curve) :: nurbs, bsp
real(rk), allocatable :: Xc(:,:), Wc(:)
real(rk), allocatable :: Xg(:,:), Xgb(:,:)
real(rk) :: knot(6)
type(unit_test) :: ut

allocate(Xc(3, 3))
Xc(1,:) = [0.0_rk, 0.0_rk, 0.0_rk]
Expand All @@ -33,26 +35,26 @@ program test_curve
call nurbs%create()
call bsp%create()

print*,'test 01: ', norm2(Xg - nurbs%get_Xg())
print*,'test 02: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 01")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 02")

call nurbs%elevate_degree(2)
call bsp%elevate_degree(2)

call nurbs%create()
call bsp%create()

print*,'test 03: ', norm2(Xg - nurbs%get_Xg())
print*,'test 04: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 03")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 04")

call nurbs%remove_knots([0.25_rk, 0.75_rk], [2,1])
call bsp%remove_knots([0.25_rk, 0.75_rk], [2,1])

call nurbs%create()
call bsp%create()

print*,'test 05: ', norm2(Xg - nurbs%get_Xg())
print*,'test 06: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 05")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 06")

call nurbs%finalize()
call bsp%finalize()
Expand Down
17 changes: 9 additions & 8 deletions test/test_surface.f90
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
program test_surface

use forcad
use forcad, only: rk, nurbs_surface
use forunittest, only: unit_test

implicit none

type(nurbs_surface) :: nurbs, bsp
real(rk) :: knot1(6), knot2(6)
real(rk), allocatable :: Xc(:,:), Wc(:)
real(rk), allocatable :: Xg(:,:), Xgb(:,:)
type(unit_test) :: ut

Xc = generate_Xc(3, 3, 1.0_rk)

Expand Down Expand Up @@ -36,8 +37,8 @@ program test_surface
call nurbs%create()
call bsp%create()

print*,'test 07: ', norm2(Xg - nurbs%get_Xg())
print*,'test 08: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 07")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 08")

call nurbs%elevate_degree(1, 2)
call nurbs%elevate_degree(2, 2)
Expand All @@ -48,8 +49,8 @@ program test_surface
call nurbs%create()
call bsp%create()

print*,'test 09: ', norm2(Xg - nurbs%get_Xg())
print*,'test 10: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 09")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 10")

call nurbs%remove_knots(1, [0.25_rk, 0.75_rk], [2,1])
call nurbs%remove_knots(2, [0.25_rk, 0.75_rk], [2,1])
Expand All @@ -60,8 +61,8 @@ program test_surface
call nurbs%create()
call bsp%create()

print*,'test 11: ', norm2(Xg - nurbs%get_Xg())
print*,'test 12: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 11")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 12")

call nurbs%finalize()
call bsp%finalize()
Expand Down
14 changes: 8 additions & 6 deletions test/test_volume.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
program test_volume

use forcad, only: rk, nurbs_volume
use forunittest, only: unit_test

implicit none
type(nurbs_volume) :: nurbs, bsp
real(rk), allocatable :: Xc(:,:), Wc(:)
real(rk), allocatable :: Xg(:,:), Xgb(:,:)
real(rk) :: knot1(4), knot2(4), knot3(4)
type(unit_test) :: ut

Xc = generate_Xc(5.0_rk)

Expand Down Expand Up @@ -37,8 +39,8 @@ program test_volume
call nurbs%create()
call bsp%create()

print*,'test 13: ', norm2(Xg - nurbs%get_Xg())
print*,'test 14: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 13")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 14")

call nurbs%elevate_degree(1, 2)
call nurbs%elevate_degree(2, 2)
Expand All @@ -51,8 +53,8 @@ program test_volume
call nurbs%create()
call bsp%create()

print*,'test 15: ', norm2(Xg - nurbs%get_Xg())
print*,'test 16: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 15")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 16")

call nurbs%remove_knots(1, [0.25_rk, 0.75_rk], [1,1])
call nurbs%remove_knots(2, [0.25_rk, 0.75_rk], [1,1])
Expand All @@ -65,8 +67,8 @@ program test_volume
call nurbs%create()
call bsp%create()

print*,'test 17: ', norm2(Xg - nurbs%get_Xg())
print*,'test 18: ', norm2(Xgb - bsp%get_Xg())
call ut%check(res=nurbs%get_Xg(), expected=Xg, tol=1e-5_rk, msg="test 17")
call ut%check(res=bsp%get_Xg(), expected=Xgb, tol=1e-5_rk, msg="test 18")

call nurbs%finalize()
call bsp%finalize()
Expand Down

0 comments on commit 83888c9

Please sign in to comment.