MONC
test_q_indices.F90
Go to the documentation of this file.
1 ! Tests the collections_mod utility functions
3  use fruit, only : assert_equals, add_fail, assert_false, assert_true
6  implicit none
7 
8 contains
9 
10  ! Tests get_q_index - ensures that a new entry is added only if that entry does not
11  ! exist already
12  subroutine test_get_q_index
13  character(7), parameter :: name='First'
14  integer :: numActive,index
15  index = get_q_index(name)
16  numactive = get_number_active_q_indices()
17 
18  call assert_equals(1, numactive, "First element")
19  ! add the same element for second time
20  index = get_q_index(name)
21  numactive = get_number_active_q_indices()
22  call assert_equals(1, numactive, "Repeated element")
23  end subroutine test_get_q_index
24 
25  ! Tests set_q_index - ensures that a new index is set a given index and name
26  subroutine test_q_indices_set
27  type(q_metadata_type) :: descriptor
28  character(7), parameter :: name='Set'
29  integer :: numActive,new_numActive,index
30  index = get_q_index(name)
31  numactive = get_number_active_q_indices()
32 
33  ! add the same element for second time
34  call set_q_index(index,"New")
35  new_numactive = get_number_active_q_indices()
36  call assert_equals(new_numactive, numactive, "Overwritten element")
37 
38  ! we expect to have overwritten the previous descriptor
39  descriptor = get_indices_descriptor(index)
40  call assert_equals("New",descriptor%name,"Check name of set element")
41  end subroutine test_q_indices_set
42 
43  ! Tests limits - if an element is introduced after the n_maxqs limit,
44  ! it is not taken into account as an active index
45  subroutine test_q_indices_limits
46  integer :: numActive,new_numActive,index
47  !number of elements active before
48  numactive = get_number_active_q_indices()
49  !set new value out of range
50  call set_q_index(101,"Limit")
51  !number of elements active after
52  new_numactive = get_number_active_q_indices()
53  !check the number of active elements has not changed
54  call assert_equals(new_numactive, numactive, "Out of range element")
55 
56  end subroutine test_q_indices_limits
57 
58 
59 
60 
61 end module test_q_indices_mod
62 
63 
64 
65 
66 ! Driver for the q_indices_mod unit tests
68  use fruit, only : init_fruit, run_test_case, fruit_summary
70 
71  implicit none
72 
73  call init_fruit
74  call run_test_case(test_get_q_index, "Elements addition")
75  call run_test_case(test_q_indices_set, "Elements set")
76  call run_test_case(test_q_indices_limits, "Elements limits")
77  call fruit_summary
78 end program test_q_indices_driver
integer function, public get_max_number_q_indices()
Gets the maximum number of Q indicies.
Definition: q_indices.F90:81
subroutine test_q_indices_limits
type(q_metadata_type) function, public get_indices_descriptor(i)
Retrieves the indicies descriptor at a specific location.
Definition: q_indices.F90:100
This manages the Q variables and specifically the mapping between names and the index that they are s...
Definition: q_indices.F90:2
integer function, public get_number_active_q_indices()
Gets the number of active Q indicies (i.e. those allocated to specific uses)
Definition: q_indices.F90:87
program test_q_indices_driver
subroutine test_get_q_index
subroutine test_q_indices_set
subroutine, public set_q_index(index, name)
Sets a Q index to be active at a specific index and sets the name.
Definition: q_indices.F90:71
integer function, public get_q_index(name, assigning_component)
Add in a new entry into the register if the name does not already exist or return the index of the pr...
Definition: q_indices.F90:112