You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/4-pfunit-syntax.md
+105-4Lines changed: 105 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ end module test_dot_product_intrinsic
113
113
114
114
## Handling state within tests
115
115
116
-
If the code we wished to test required some state to be setup prior to running the test, such as allocating arrays, we could repeat this step within each test, like so:
116
+
If multiple tests rely of the existence of some state such as the allocation of an array. We could repeat this step within each test, like so:
117
117
118
118
```fortran
119
119
module test_dot_product_intrinsic
@@ -382,8 +382,109 @@ The key features of this the type **dot_product_test_parameters** are
382
382
- It is decorated with the directive **@TestParameter**.
383
383
- It extends the type **AbstractTestParameter** provided by the pFUnit library.
384
384
- All inputs (**a** and **b**) and expected outputs (**expected_dot_product**) of **dot_product** are define as type-bound variables.
385
-
- There is an extra type-bound variable - **description** - which is used alongside the type-bound procedure **toString => dot_product_test_parameters_toString**.
386
-
- pFUnit requires that a type which extends **AbstractTestParameter** defines a type-bound procedure called **toString**. This procedure is then used to provide a description of the specific parameter set within the name of each test.
387
-
- For simplicity, we have added the variable **description** which we can be defined and return from **dot_product_test_parameters_toString** (we will cover this shortly).
385
+
- The type-bound variable **description** and procedure **toString** allow conversion of a single test parameter instance to a character array for logging (see below).
386
+
387
+
#### toString
388
+
389
+
pFUnit requires that a type which extends **AbstractTestParameter** must define a type-bound procedure called **toString**:
390
+
391
+
```fortran
392
+
!> Trims and returns the description of the parameter set. The string returned
393
+
!> by this function will be included by pFUnit in the name of this test
394
+
function toString(this) result(string)
395
+
class (dot_product_test_parameters), intent(in) :: this
396
+
character(:), allocatable :: string
397
+
398
+
string = trim(this%description)
399
+
end function toString
400
+
```
401
+
402
+
For simplicity, we utilise the variable **description** to define this string in its entirity.
403
+
404
+
:::::::::: callout
405
+
406
+
#### Default type constructor
407
+
408
+
All derived types in Fortran are given a default constructor of the same name which can be invoked
409
+
like a function. For example, we can create an instance of our type **dot_product_test_parameters**
0 commit comments