Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 add garden tests #27

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name = "Fortran-tooling"
version = "0.1.0"
license = "MIT"
author = "Connor Aird, Mashy Green, Duncan Leggat, Ilektra Christidi, Tuomas Koskela"
maintainer = "[email protected]"
copyright = "Copyright 2025, UCL ARC"

[fortran]
source-form = "free"

[profiles.gfortran.linux]
flags = "-ffree-line-length-none"

[build]
auto-executables = true
auto-tests = true
auto-examples = true

[install]
library = false

[dev-dependencies]
test-drive.git = "https://github.com/fortran-lang/test-drive"
test-drive.tag = "v0.5.0"
garden.git = "https://gitlab.com/connoraird/garden"
garden.tag = "8-dp-integer-assertions"

[[executable]]
name = "poisson"
source-dir = "src/poisson"
main = "main.f90"

[[executable]]
name = "mesh_generator"
source-dir = "src/mesh_generator"
main = "main.f90"

[[test]]
name = "test-drive-mesh-generator"
source-dir = "testing/test-drive"
main = "main.f90"

[[test]]
name = "garden-mesh-generator"
source-dir = "testing/garden"
main = "main.f90"
30 changes: 30 additions & 0 deletions testing/garden/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# garden

[Garden](https://gitlab.com/everythingfunctional/garden) is a unit testing framework for testing serial or parallel Fortran codes.
It has a sister project called [veggies](https://gitlab.com/everythingfunctional/veggies) which acts as the same testing framework
but for serial only codes. *"The hope is that at some point in the future all compilers will support parallel features implicitly, and any need for two separate packages will disappear."*

## Running the tests


## Features matrix

Compilers tested: *A list of compilers we have tried with these tests*

| Feature | Implemented natively | Implemented manually |
|---------|----------------------|----------------------|
| Can run individual tests | Yes or No (explanation) | Yes or No (explanation) |
| Mocking | Yes or No (explanation) | Yes or No (explanation) |
| Stubbing | Yes or No (explanation) | Yes or No (explanation) |
| Data driven tests | Yes or No (explanation) | Yes or No (explanation) |
| Coverage report | Yes or No (explanation) | Yes or No (explanation) |
| Skip tests | Yes or No (explanation) | Yes or No (explanation) |

## Pros

## Cons

## Building

## Resources
- Repository: https://gitlab.com/everythingfunctional/garden
21 changes: 21 additions & 0 deletions testing/garden/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
program garden_main
use garden, only : test_item_t, test_that, run_tests
use garden_mesh_generator, only : test_assert_eq_double_mat
implicit none

if (.not.run()) stop 1

contains
function run() result(passed)
logical :: passed

type(test_item_t) :: tests
type(test_item_t) :: individual_tests(1)

individual_tests(1) = test_assert_eq_double_mat()

tests = test_that(individual_tests)

passed = run_tests(tests)
end function run
end program garden_main
55 changes: 55 additions & 0 deletions testing/garden/test_mesh_generator.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module garden_mesh_generator
use, intrinsic :: iso_fortran_env
use mesh_generator, only : calculate_mesh_parameters
implicit none

contains
function test_assert_eq_double_mat() result(tests)
use garden, only: &
test_item_t, &
describe, &
it
implicit none
type(test_item_t) :: tests

tests = describe( &
"calculate_mesh_parameters", &
[ it( &
"passes with valid inputs", &
check_calculate_mesh_parameters_valid_inputs) &
])
end function

function check_calculate_mesh_parameters_valid_inputs() result(result_)
use garden, only: result_t, assert_equals
implicit none

type(result_t) :: result_

integer(kind=int64) :: box_size = 10
real(kind=real64) :: edge_size = 1.0
integer(kind=int64) :: actual_num_edges_per_boundary, actual_num_nodes, &
actual_num_boundary_nodes, actual_num_elements

integer(kind=int64) :: &
expected_num_edges_per_boundary = 10, &
expected_num_nodes = 121, &
expected_num_boundary_nodes = 40, &
expected_num_elements = 200, &
num_edges_per_boundary, &
num_nodes, &
num_boundary_nodes, &
num_elements

call calculate_mesh_parameters(box_size, edge_size, &
actual_num_edges_per_boundary, actual_num_nodes, &
actual_num_boundary_nodes, actual_num_elements)

result_ = &
assert_equals(actual_num_edges_per_boundary, expected_num_edges_per_boundary).and.&
assert_equals(actual_num_nodes, expected_num_nodes).and.&
assert_equals(actual_num_boundary_nodes, expected_num_boundary_nodes).and.&
assert_equals(actual_num_elements, expected_num_elements)

end function
end module garden_mesh_generator
2 changes: 1 addition & 1 deletion testing/test-drive/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ program tester
use testdrive, only : run_testsuite, new_testsuite, testsuite_type, &
& select_suite, run_selected, get_argument

use test_mesh_generator, only : collect_mesh_generator_testsuite
use test_drive_mesh_generator, only : collect_mesh_generator_testsuite

implicit none

Expand Down
6 changes: 3 additions & 3 deletions testing/test-drive/test_mesh_generator.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module test_mesh_generator
module test_drive_mesh_generator
use, intrinsic :: iso_fortran_env
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test

Expand Down Expand Up @@ -190,7 +190,7 @@ subroutine test_calculate_mesh_8_2_8_9(error)
expected_outputs%elements(:,6) = (/5,6,9/)
expected_outputs%elements(:,7) = (/4,8,7/)
expected_outputs%elements(:,8) = (/5,9,8/)
allocate(expected_outputs%nodes(3, inputs%num_nodes))
allocate(expected_outputs%nodes(2, inputs%num_nodes))
expected_outputs%nodes(:,1) = (/1.0,1.0/)
expected_outputs%nodes(:,2) = (/1.0,2.0/)
expected_outputs%nodes(:,3) = (/1.0,3.0/)
Expand Down Expand Up @@ -219,4 +219,4 @@ subroutine test_skip_example(error)
call skip_test(error, "This feature is not implemented yet")
return
end subroutine test_skip_example
end module test_mesh_generator
end module test_drive_mesh_generator