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

8 tests #10

Merged
merged 12 commits into from
Dec 31, 2023
12 changes: 10 additions & 2 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source-form = "free"
auto-executables = true
auto-tests = true
auto-examples = true
module-naming = true
module-naming = false

[install]
library = true
Expand All @@ -25,4 +25,12 @@ main = "example_in_f.f90"

[[example]]
name = "example_in_c"
main = "example_in_c.c"
main = "example_in_c.c"

[dev-dependencies]

[[test]]
name = "tester"
main = "tester.f90"
[test.dependencies]
test-drive = {git="https://github.com/fortran-lang/test-drive", tag="v0.4.0"}
149 changes: 141 additions & 8 deletions pywrapper/pycodata/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,147 @@
import unittest
from ..constants import *

class TestLib(unittest.TestCase):
r"""Test pyiawps library."""
def test_value(self):
value = ALPHA_PARTICLE_MASS
reference = 6.6446573357e-27
self.assertEqual(value, reference)

class TestYear(unittest.TestCase):
r"""Test year."""
def test_year(self):
value = YEAR
reference = 2018
self.assertEqual(value, reference)
expected = 2018
self.assertEqual(value, expected)


class TestConstants(unittest.TestCase):
r"""Test constant values."""
def test_ALPHA_PARTICLE_ELECTRON_MASS_RATIO(self):
value = ALPHA_PARTICLE_ELECTRON_MASS_RATIO
expected = 7294.29954142
self.assertEqual(value, expected)

def test_ALPHA_PARTICLE_MASS(self):
value = ALPHA_PARTICLE_MASS
expected = 6.6446573357e-27
self.assertEqual(value, expected)

def test_ATOMIC_MASS_CONSTANT(self):
value = ATOMIC_MASS_CONSTANT
expected = 1.66053906660e-27
self.assertEqual(value, expected)

def test_AVOGADRO_CONSTANT(self):
value = AVOGADRO_CONSTANT
expected = 6.02214076e23
self.assertEqual(value, expected)

def test_BOLTZMANN_CONSTANT(self):
value = BOLTZMANN_CONSTANT
expected = 1.380649e-23
self.assertEqual(value, expected)

def test_ELECTRON_VOLT(self):
value = ELECTRON_VOLT
expected = 1.602176634e-19
self.assertEqual(value, expected)

def test_ELEMENTARY_CHARGE(self):
value = ELEMENTARY_CHARGE
expected = 1.602176634e-19
self.assertEqual(value, expected)

def test_FARADAY_CONSTANT(self):
value = FARADAY_CONSTANT
expected = 96485.33212
self.assertEqual(value, expected)

def test_MOLAR_MASS_CONSTANT(self):
value = MOLAR_MASS_CONSTANT
expected = 0.99999999965e-3
self.assertEqual(value, expected)

def test_MOLAR_VOLUME_NTP(self):
value = MOLAR_VOLUME_OF_IDEAL_GAS__273_15_K__101_325_KPA
expected = 22.41396954e-3
self.assertEqual(value, expected)

def test_PLANCK_CONSTANT(self):
value = PLANCK_CONSTANT
expected = 6.62607015e-34
self.assertEqual(value, expected)

def test_SPEED_OF_LIGHT(self):
value = SPEED_OF_LIGHT_IN_VACUUM
expected = 299792458.0
self.assertEqual(value, expected)

def test_STANDARD_ACCELERATION_OF_GRAVITY(self):
value = STANDARD_ACCELERATION_OF_GRAVITY
expected = 9.80665
self.assertEqual(value, expected)


class TestUncertainties(unittest.TestCase):
r"""Test constant uncertainties."""
def test_U_ALPHA_PARTICLE_ELECTRON_MASS_RATIO(self):
value = U_ALPHA_PARTICLE_ELECTRON_MASS_RATIO
expected = 0.00000024
self.assertEqual(value, expected)

def test_U_ALPHA_PARTICLE_MASS(self):
value = U_ALPHA_PARTICLE_MASS
expected = 0.0000000020e-27
self.assertEqual(value, expected)

def test_U_ATOMIC_MASS_CONSTANT(self):
value = U_ATOMIC_MASS_CONSTANT
expected = 0.00000000050e-27
self.assertEqual(value, expected)

def test_U_AVOGADRO_CONSTANT(self):
value = U_AVOGADRO_CONSTANT
expected = 0.0
self.assertEqual(value, expected)

def test_U_BOLTZMANN_CONSTANT(self):
value = U_BOLTZMANN_CONSTANT
expected = 0.0
self.assertEqual(value, expected)

def test_U_ELECTRON_VOLT(self):
value = U_ELECTRON_VOLT
expected = 0.0
self.assertEqual(value, expected)

def test_U_ELEMENTARY_CHARGE(self):
value = U_ELEMENTARY_CHARGE
expected = 0.0
self.assertEqual(value, expected)

def test_U_FARADAY_CONSTANT(self):
value = U_FARADAY_CONSTANT
expected = 0.0
self.assertEqual(value, expected)

def test_U_MOLAR_MASS_CONSTANT(self):
value = U_MOLAR_MASS_CONSTANT
expected = 0.00000000030e-3
self.assertEqual(value, expected)

def test_U_MOLAR_VOLUME_NTP(self):
value = U_MOLAR_VOLUME_OF_IDEAL_GAS__273_15_K__101_325_KPA
expected = 0.0
self.assertEqual(value, expected)

def test_U_PLANCK_CONSTANT(self):
value = U_PLANCK_CONSTANT
expected = 0.0
self.assertEqual(value, expected)

def test_U_SPEED_OF_LIGHT(self):
value = U_SPEED_OF_LIGHT_IN_VACUUM
expected = 0.0
self.assertEqual(value, expected)

def test_U_STANDARD_ACCELERATION_OF_GRAVITY(self):
value = U_STANDARD_ACCELERATION_OF_GRAVITY
expected = 0.0
self.assertEqual(value, expected)

22 changes: 0 additions & 22 deletions test/test.f90

This file was deleted.

28 changes: 28 additions & 0 deletions test/tester.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
program tester
use iso_fortran_env
use testdrive, only : run_testsuite, new_testsuite, testsuite_type
use testsuite_constants, only : collect_suite_constants
use testsuite_uncertainties, only : collect_suite_uncertainties
use testsuite_year, only : collect_suite_year
implicit none
type(testsuite_type), allocatable :: testsuites(:)
character(len=*), parameter :: fmt = '("#", *(1x, a))'
integer :: stat, is

stat = 0

testsuites = [new_testsuite("Year", collect_suite_year),&
new_testsuite("Constants", collect_suite_constants),&
new_testsuite("Uncertainties", collect_suite_uncertainties)]

do is = 1, size(testsuites)
write(error_unit, fmt) "Testing:", testsuites(is)%name
call run_testsuite(testsuites(is)%collect, error_unit, stat)
end do

if (stat > 0) then
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
error stop
end if

end program
150 changes: 150 additions & 0 deletions test/testsuite_constants.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
module testsuite_constants
!! Test some constants values
use iso_fortran_env
use testdrive, only : new_unittest, unittest_type, error_type, check
use codata
implicit none
private

public :: collect_suite_constants

contains

subroutine collect_suite_constants(testsuite)
!! Collection of tests
type(unittest_type), allocatable, intent(out) :: testsuite(:)

testsuite = [&
new_unittest("ALPHA_PARTICLE_ELECTRON_MASS_RATIO", test_ALPHA_PARTICLE_ELECTRON_MASS_RATIO),&
new_unittest("ALPHA_PARTICLE_MASS", test_ALPHA_PARTICLE_MASS),&
new_unittest("ATOMIC_MASS_CONSTANT", test_ATOMIC_MASS_CONSTANT),&
new_unittest("AVOGADRO_CONSTANT", test_AVOGADRO_CONSTANT),&
new_unittest("BOLTZMANN_CONSTANT", test_BOLTZMANN_CONSTANT),&
new_unittest("ELECTRON_VOLT", test_ELECTRON_VOLT),&
new_unittest("ELEMENTARY_CHARGE", test_ELEMENTARY_CHARGE),&
new_unittest("FARADAY_CONSTANT", test_FARADAY_CONSTANT),&
new_unittest("MOLAR_MASS_CONSTANT", test_MOLAR_MASS_CONSTANT),&
new_unittest("MOLAR_VOLUME_OF_IDEAL_GAS__273_15K__101_325_KPA", test_MOLAR_VOLUME_NTP),&
new_unittest("PLANCK_CONSTANT", test_PLANCK_CONSTANT),&
new_unittest("SPEED_OF_LIGHT_IN_VACUUM", test_SPEED_OF_LIGHT),&
new_unittest("STANDARD_ACCELERATION_OF_GRAVITY", test_STANDARD_ACCELERATION_OF_GRAVITY)]
end subroutine

subroutine test_ALPHA_PARTICLE_ELECTRON_MASS_RATIO(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 7294.29954142d0
value = ALPHA_PARTICLE_ELECTRON_MASS_RATIO
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_ALPHA_PARTICLE_MASS(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 6.6446573357d-27
value = ALPHA_PARTICLE_MASS
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_ATOMIC_MASS_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 1.66053906660d-27
value = ATOMIC_MASS_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_AVOGADRO_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 6.02214076d23
value = AVOGADRO_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_BOLTZMANN_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 1.380649d-23
value = BOLTZMANN_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_ELECTRON_VOLT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 1.602176634d-19
value = ELECTRON_VOLT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_ELEMENTARY_CHARGE(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 1.602176634d-19
value = ELEMENTARY_CHARGE
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_FARADAY_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 96485.33212d0
value = FARADAY_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_MOLAR_MASS_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 0.99999999965d-3
value = MOLAR_MASS_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_MOLAR_VOLUME_NTP(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 22.41396954d-3
value = MOLAR_VOLUME_OF_IDEAL_GAS__273_15_K__101_325_KPA
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_PLANCK_CONSTANT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected, fac
expected = 6.62607015d-34
value = PLANCK_CONSTANT
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_SPEED_OF_LIGHT(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected
expected = 299792458.0d0
value = SPEED_OF_LIGHT_IN_VACUUM
call check(error, value, expected)
if (allocated(error)) return
end subroutine

subroutine test_STANDARD_ACCELERATION_OF_GRAVITY(error)
type(error_type), allocatable, intent(out) :: error
real(real64) :: value, expected
expected = 9.80665d0
value = STANDARD_ACCELERATION_OF_GRAVITY
call check(error, value, expected)
if (allocated(error)) return
end subroutine

end module
Loading