1/*==============================================================================
2|
3| NAME
4|
5| ppUnitTest.hpp
6|
7| DESCRIPTION
8|
9| Header file for unit test routines.
10|
11| User manual and technical documentation are described in detail in my web page at
12| http://seanerikoconnor.freeservers.com/Mathematics/AbstractAlgebra/PrimitivePolynomials/overview.html
13|
14| LEGAL
15|
16| Primpoly Version 16.3 - A Program for Computing Primitive Polynomials.
17| Copyright (C) 1999-2024 by Sean Erik O'Connor. All Rights Reserved.
18|
19| This program is free software: you can redistribute it and/or modify
20| it under the terms of the GNU General Public License as published by
21| the Free Software Foundation, either version 3 of the License, or
22| (at your option) any later version.
23|
24| This program is distributed in the hope that it will be useful,
25| but WITHOUT ANY WARRANTY; without even the implied warranty of
26| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27| GNU General Public License for more details.
28|
29| You should have received a copy of the GNU General Public License
30| along with this program. If not, see http://www.gnu.org/licenses/.
31|
32| The author's address is seanerikoconnor!AT!gmail!DOT!com
33| with the !DOT! replaced by . and the !AT! replaced by @
34|
35==============================================================================*/
36
37// Wrap this header file to prevent duplication if it is included
38// accidentally more than once.
39#ifndef __PP_UNITTEST_H__
40#define __PP_UNITTEST_H__
41
42
43/*=============================================================================
44|
45| NAME
46|
47| unitTest
48|
49| DESCRIPTION
50|
51| In the spirit of EXTREME programming, test each class and its member
52| functions. Run the tests every time we run this application.
53| Place the test results into the current directory in the file
54| unitTest.txt. If we can't write the file, log an error message
55| to the console and skip the tests. If we can't even do that, throw
56| an exception.
57|
58+============================================================================*/
59
60class UnitTest
61{
62 public:
63 // Default constructor with a reasonable default file name.
64 UnitTest( const char * fileName = "unitTest.log" ) ;
65
66 ~UnitTest() ;
67
68 // We have only one unit test object; prevent any copy constructors or
69 // assignment operators from being defined.
70 UnitTest( const UnitTest & u ) = delete ;
71 UnitTest & operator=( const UnitTest & unitTest ) = delete ;
72
73 // Run all unit tests.
74 bool run() ;
75
76 protected:
77 // Unit tests for different functional areas.
78 bool unitTestSystemFunctions() ;
79 bool unitTestBigIntBase10() ;
80 bool unitTestBigIntDefaultBase() ;
81 bool unitTestModPArithmetic() ;
82 bool unitTestFactoring() ;
83 bool unitTestPolynomials() ;
84 bool unitTestPolynomialOrder() ;
85 bool unitTestParser() ;
86
87 protected:
88 // File to log the unit test results. Can be standard output (console) if we can't open the file.
89 const char * unit_test_log_file_name_ ;
90 ofstream fout_ ;
91} ;
92
93
94/*=============================================================================
95|
96| NAME
97|
98| UnitTestError
99|
100| DESCRIPTION
101|
102| Exception classes for the the UnitTest class
103| derived from the STL exception class runtime_error.
104|
105+============================================================================*/
106
107class UnitTestError : public runtime_error
108{
109 public:
110 // Throw with error message, file name and line number.
111 UnitTestError( const string & description, const string & file, const int & line )
112 : runtime_error( description + " in file " + file + " at line " + to_string(line) )
113 {
114 } ;
115
116 // Throw with an error message.
117 UnitTestError( const string & description )
118 : runtime_error( description )
119 {
120 } ;
121
122 // Default throw with no error message.
123 UnitTestError()
124 : runtime_error( "UnitTest exception: " )
125 {
126 } ;
127} ;
128#endif // __PP_UNITTEST_H__ -- End of wrapper for header file.