unit_testing.cpp
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// U N I T T E S T I N G C L A S S
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#include"unit_testing.h"
10
11UnitTesting::UnitTesting()
12{
13 tests_count = 0;
16
18}
19
20
22
24{
25}
26
27
29
31{
32 return tests_count;
33}
34
35
37
39{
40 return tests_passed_count;
41}
42
43
45
47{
48 return tests_failed_count;
49}
50
51
53
55{
57}
58
59
61
62const bool& UnitTesting::get_display() const
63{
64 return display;
65}
66
67
70
71void UnitTesting::set_tests_count(const Index& new_tests_count)
72{
73 tests_count = new_tests_count;
74}
75
76
79
80void UnitTesting::set_tests_passed_count(const Index& new_tests_passed_count)
81{
82 tests_passed_count = new_tests_passed_count;
83}
84
85
88
89void UnitTesting::set_tests_failed_count(const Index& new_tests_failed_count)
90{
91 tests_failed_count = new_tests_failed_count;
92}
93
94
97
98void UnitTesting::set_random_tests_number(const Index& new_random_tests_number)
99{
100 random_tests_number = new_random_tests_number;
101}
102
103
106
107void UnitTesting::set_display(const bool& new_display)
108{
109 display = new_display;
110}
111
112
121
122void UnitTesting::assert_true(const bool& condition, const string& error_message)
123{
124 tests_count++;
125
126 if(condition)
127 {
129 }
130 else
131 {
132 cout << "void assert_true(bool, const string&) method failed\n";
133 cout << error_message;
135 }
136}
137
138
147
148void UnitTesting::assert_false(const bool& condition, const string& error_message)
149{
150 tests_count++;
151
152 if(!condition)
153 {
155 }
156 else
157 {
158 cout << "void assert_false(bool, const string&) method failed\n";
159 cout << error_message;
161 }
162}
163
164
173
175{
177
178 cout << "Tests run: " << tests_count << endl;
179 cout << "Tests passed: " << tests_passed_count << endl;
180 cout << "Tests failed: " << tests_failed_count << endl;
181
182 if(tests_failed_count == 0)
183 {
184 cout << "Test case OK." << endl;
185 }
186 else
187 {
188 cout << "Test case NOT OK: " << tests_failed_count << " tests failed." << endl;
189 }
190}
191
192
193// OpenNN: Open Neural Networks Library.
194// Copyright (C) 2005-2021 Artificial Intelligence Techniques, SL.
195//
196// This library is free software; you can redistribute it and/or
197// modify it under the terms of the GNU Lesser General Public
198// License as published by the Free Software Foundation; either
199// version 2.1 of the License, or any later version.
200//
201// This library is distributed in the hope that it will be useful,
202// but WITHOUT ANY WARRANTY; without even the implied warranty of
203// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
204// Lesser General Public License for more details.
205
206// You should have received a copy of the GNU Lesser General Public
207// License along with this library; if not, write to the Free Software
208// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Index get_tests_failed_count() const
Returns the number of tests which have failed the test case.
const bool & get_display() const
Returns the display messages to the screen value of this object.
Index tests_failed_count
Number of tests which have failed the test case.
Definition: unit_testing.h:85
Index tests_count
Number of performed tests.
Definition: unit_testing.h:77
virtual void run_test_case()=0
This method runs all the methods contained in the test case.
virtual ~UnitTesting()
Destructor.
void assert_false(const bool &, const string &)
bool display
True if messages from this class are to be displayed, false otherwise.
Definition: unit_testing.h:93
void set_tests_failed_count(const Index &)
Index tests_passed_count
Number of tests which have passed the test case.
Definition: unit_testing.h:81
void set_tests_count(const Index &)
void set_tests_passed_count(const Index &)
Index random_tests_number
Number of iterations in random tests loops.
Definition: unit_testing.h:89
Index get_tests_count() const
Returns the number of tests which have been performed by the test case.
void assert_true(const bool &, const string &)
Index get_random_tests_number() const
Returns the number of iterations for loops of random tests.
void print_results()
void set_display(const bool &)
void set_random_tests_number(const Index &)
Index get_tests_passed_count() const
Returns the number of tests which have passed the test case.