unit_testing.h
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 H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef UNITTESTING_H
10#define UNITTESTING_H
11
12// System includes
13
14#include <cmath>
15#include <cstdlib>
16#include <fstream>
17#include <iomanip>
18#include <iostream>
19#include <string>
20#include <sstream>
21#include <time.h>
22
23// OpenNN includes
24
25#include "../opennn/opennn.h"
26
27using namespace OpenNN;
28
30{
31
32public:
33
34 explicit UnitTesting();
35
36 virtual ~UnitTesting();
37
38 // Get methods
39
40 Index get_tests_count() const;
41 Index get_tests_passed_count() const;
42 Index get_tests_failed_count() const;
43
44 Index get_random_tests_number() const;
45
46 const bool& get_display() const;
47
48 // Set methods
49
50 void set_tests_count(const Index&);
51 void set_tests_passed_count(const Index&);
52 void set_tests_failed_count(const Index&);
53
54 void set_random_tests_number(const Index&);
55
56 void set_message(const string&);
57
58 void set_display(const bool&);
59
60 // Unit testing methods
61
62 void assert_true(const bool&, const string&);
63 void assert_false(const bool&, const string&);
64
65 // Test case methods
66
68
69 virtual void run_test_case() = 0;
70
71 void print_results();
72
73protected:
74
76
78
80
82
84
86
88
90
92
93 bool display = true;
94
95 const int n = omp_get_max_threads();
96 NonBlockingThreadPool* non_blocking_thread_pool = new NonBlockingThreadPool(n);
97 ThreadPoolDevice* thread_pool_device = new ThreadPoolDevice(non_blocking_thread_pool, n);
98
99};
100
101#endif
102
103// OpenNN: Open Neural Networks Library.
104// Copyright (C) 2005-2021 Artificial Intelligence Techniques, SL.
105//
106// This library is free software; you can redistribute it and/or
107// modify it under the terms of the GNU Lesser General Public
108// License as published by the Free Software Foundation; either
109// version 2.1 of the License, or any later version.
110//
111// This library is distributed in the hope that it will be useful,
112// but WITHOUT ANY WARRANTY; without even the implied warranty of
113// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
114// Lesser General Public License for more details.
115
116// You should have received a copy of the GNU Lesser General Public
117// License along with this library; if not, write to the Free Software
118// 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.