@@ -6,7 +6,10 @@ module inference_engine_test_m
66 ! External dependencies
77 use assert_m, only : assert
88 use kind_parameters_m, only : rkind
9- use sourcery_m, only : string_t, test_t, test_result_t, file_t
9+ use sourcery_m, only : test_t, test_result_t, test_description_t, test_description_substring, string_t, file_t
10+ #ifdef __GFORTRAN__
11+ use sourcery_m, only : test_function_i
12+ #endif
1013
1114 ! Internal dependencies
1215 use inference_engine_m, only : inference_engine_t, tensor_t, difference_t
@@ -31,25 +34,33 @@ pure function subject() result(specimen)
3134
3235 function results () result(test_results)
3336 type (test_result_t), allocatable :: test_results(:)
34-
35- character (len=* ), parameter :: longest_description = &
36- " converting a network with 2 hidden layers to and from JSON format"
37-
37+ type (test_description_t), allocatable :: test_descriptions(:)
38+
39+ #ifndef __GFORTRAN__
40+ test_descriptions = [ &
41+ test_description_t(" performing elemental inference with 1 hidden layer" , elemental_infer_with_1_hidden_layer_xor_net), &
42+ test_description_t(" performing elemental inference with 2 hidden layers" , elemental_infer_with_2_hidden_layer_xor_net), &
43+ test_description_t(" converting a network with 2 hidden layers to and from JSON format" , multi_hidden_layer_net_to_from_json) &
44+ ]
45+ #else
46+ procedure (test_function_i), pointer :: elemental_infer_1_ptr, elemental_infer_2_ptr, multi_hidden_ptr
47+ elemental_infer_1_ptr = > elemental_infer_with_1_hidden_layer_xor_net
48+ elemental_infer_2_ptr = > elemental_infer_with_2_hidden_layer_xor_net
49+ multi_hidden_ptr = > multi_hidden_layer_net_to_from_json
50+
51+ test_descriptions = [ &
52+ test_description_t(" performing elemental inference with 1 hidden layer" , elemental_infer_1_ptr), &
53+ test_description_t(" performing elemental inference with 2 hidden layers" , elemental_infer_2_ptr), &
54+ test_description_t(" converting a network with 2 hidden layers to and from JSON format" , multi_hidden_ptr) &
55+ ]
56+ #endif
3857 associate( &
39- descriptions = > &
40- [ character (len= len (longest_description)) :: &
41- " performing elemental inference with 1 hidden layer" , &
42- " performing elemental inference with 2 hidden layers" , &
43- " converting a network with 2 hidden layers to and from JSON format" &
44- ], &
45- outcomes = > &
46- [ elemental_infer_with_1_hidden_layer_xor_net(), elemental_infer_with_2_hidden_layer_xor_net(), &
47- multi_hidden_layer_net_to_from_json() &
48- ] &
58+ substring_in_subject = > index (subject(), test_description_substring) /= 0 , &
59+ substring_in_description = > test_descriptions% contains_text(string_t(test_description_substring)) &
4960 )
50- call assert(size (descriptions) == size (outcomes), " inference_engine_test(results): size(descriptions) == size(outcomes)" )
51- test_results = test_result_t(descriptions, outcomes)
61+ test_descriptions = pack (test_descriptions, substring_in_subject .or. substring_in_description)
5262 end associate
63+ test_results = test_descriptions% run()
5364 end function
5465
5566 function single_hidden_layer_xor_network () result(inference_engine)
@@ -98,7 +109,7 @@ function distinct_parameters() result(inference_engine)
98109 end function
99110
100111 function multi_hidden_layer_net_to_from_json () result(test_passes)
101- logical , allocatable :: test_passes
112+ logical test_passes
102113 type (inference_engine_t) inference_engine, from_json
103114 type (file_t) json_file
104115 type (difference_t) difference
@@ -112,7 +123,7 @@ function multi_hidden_layer_net_to_from_json() result(test_passes)
112123 end function
113124
114125 function elemental_infer_with_1_hidden_layer_xor_net () result(test_passes)
115- logical , allocatable :: test_passes(:)
126+ logical test_passes
116127 type (inference_engine_t) inference_engine
117128
118129 inference_engine = single_hidden_layer_xor_network()
@@ -125,15 +136,15 @@ function elemental_infer_with_1_hidden_layer_xor_net() result(test_passes)
125136 associate(array_of_inputs = > [tensor_t([true,true]), tensor_t([true,false]), tensor_t([false,true]), tensor_t([false,false])])
126137 truth_table = inference_engine% infer(array_of_inputs)
127138 end associate
128- test_passes = [ &
139+ test_passes = all ( &
129140 abs (truth_table(1 )% values() - false) < tolerance .and. abs (truth_table(2 )% values() - true) < tolerance .and. &
130141 abs (truth_table(3 )% values() - true) < tolerance .and. abs (truth_table(4 )% values() - false) < tolerance &
131- ]
142+ )
132143 end block
133144 end function
134145
135146 function elemental_infer_with_2_hidden_layer_xor_net () result(test_passes)
136- logical , allocatable :: test_passes(:)
147+ logical test_passes
137148 type (inference_engine_t) inference_engine
138149
139150 inference_engine = multi_layer_xor_network()
@@ -146,10 +157,10 @@ function elemental_infer_with_2_hidden_layer_xor_net() result(test_passes)
146157 associate(array_of_inputs = > [tensor_t([true,true]), tensor_t([true,false]), tensor_t([false,true]), tensor_t([false,false])])
147158 truth_table = inference_engine% infer(array_of_inputs)
148159 end associate
149- test_passes = [ &
160+ test_passes = all ( &
150161 abs (truth_table(1 )% values() - false) < tolerance .and. abs (truth_table(2 )% values() - true) < tolerance .and. &
151162 abs (truth_table(3 )% values() - true) < tolerance .and. abs (truth_table(4 )% values() - false) < tolerance &
152- ]
163+ )
153164 end block
154165 end function
155166
0 commit comments