ValidType_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "ValidType.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 #include <string>
43 #include <sstream>
44 #include <cmath>
45 
46 using namespace gnsstk;
48 {
49 public:
50  ValidType_T(){ eps = 1E-15;}// Default Constructor, set the precision value
51  ~ValidType_T() {} // Default Desructor
52 
53  int methodTest(void)
54  {
55  TUDEF( "ValidType", "isValid");
56  std::string failMesg;
57 
58  ValidType<float> vfloat0;
59 
60  //Is the invalid Valid object set as valid?
61  TUASSERT(!vfloat0.is_valid());
62 
63  //Is the invalid Valid object's value 0?
64  TUASSERTFE(0.0f, vfloat0.get_value());
65 
67 
68  //Does the get_value method return the correct value?
69  TUASSERTFE(5.0f, vfloat.get_value());
70 
71  //Is the valid Valid object set as valid?
73 
74  vfloat.set_valid(false);
75 
76  //Was the valid Valid object correctly set to invalid?
78 
79  TURETURN();
80  }
81 
82  int operatorTest(void)
83  {
84  TUDEF( "ValidType", " == Operator");
85  std::string failMesg;
86 
87  ValidType<float> CompareU1; // uninitalized
88  ValidType<float> CompareU2; // uninitalized
89  ValidType<float> Compare1 (6.);
90  ValidType<float> Compare2 (6.);
91  ValidType<float> Compare3 (8.);
92  ValidType<int> Compare4 (6);
94 
95  //Are two equvalent objects equal?
96  TUASSERT(CompareU1 == CompareU2);
97  TUASSERT(!(CompareU1 != CompareU2));
98  TUASSERT(Compare1 == Compare2);
99  TUASSERT(!(Compare1 != Compare2));
100 
101  //Are two non-equvalent objects equal?
102  TUASSERT(!(CompareU1 == Compare3));
103  TUASSERT(CompareU1 != Compare3);
104  TUASSERT(!(Compare1 == Compare3));
105  TUASSERT(Compare1 != Compare3);
106 
107  vfloat = 7.;
108 
109  TUCSM(" = Operator");
110  //Did the = operator store the value correctly?
111  TUASSERT(vfloat.get_value() == 7.);
112 
113  //Did the = operator set the object as valid?
115 
116  TUCSM(" += Operator");
117 
118  vfloat += 3.;
119  //Did the += operator store the value correctly?
120  TUASSERT(vfloat.get_value() == 10.);
121 
122  //Did the += operator change the object's valid bool?
124 
125  TUCSM(" -= Operator");
126 
127  vfloat -= 5.;
128 
129  //Did the -= operator store the value correctly?
130  TUASSERT(vfloat.get_value() == 5.);
131 
132  //Did the -= operator change the object's valid bool?
134 
135  TUCSM(" << Operator");
136 
137  vfloat = 11;
138 
139  std::stringstream streamOutput;
140  std::string stringOutput;
141  std::string stringCompare;
142 
143  streamOutput << vfloat;
144  stringOutput = streamOutput.str();
145 
146  stringCompare = "11";
147 
148  //Did the << operator ouput valid object correctly?
149  TUASSERT(stringCompare == stringOutput);
150 
151  streamOutput.str(""); // Resetting stream
152  vfloat.set_valid(false);
153 
154  streamOutput << vfloat;
155  stringOutput = streamOutput.str();
156 
157  stringCompare = "Unknown";
158 
159  // Did the << operator output invalid object correctly?
160  TUASSERT(stringCompare == stringOutput);
161 
162  TURETURN();
163  }
164 
165 private:
166  double eps;
167 };
168 
169 int main() //Main function to initialize and run all tests above
170 {
171  int errorTotal = 0;
172  ValidType_T testClass;
173 
174  errorTotal += testClass.methodTest();
175  errorTotal += testClass.operatorTest();
176 
177  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal << std::endl;
178 
179  return errorTotal; //Return the total number of errors
180 }
TUCSM
#define TUCSM(METHOD)
Definition: TestUtil.hpp:59
gnsstk::ValidType< float >
ValidType_T::operatorTest
int operatorTest(void)
Definition: ValidType_T.cpp:82
ValidType.hpp
ValidType_T::methodTest
int methodTest(void)
Definition: ValidType_T.cpp:53
gnsstk::ValidType::get_value
T get_value() const
Definition: ValidType.hpp:97
gnsstk::vfloat
ValidType< float > vfloat
Definition: ValidType.hpp:107
ValidType_T::eps
double eps
Definition: ValidType_T.cpp:166
ValidType_T::~ValidType_T
~ValidType_T()
Definition: ValidType_T.cpp:51
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
ValidType_T::ValidType_T
ValidType_T()
Definition: ValidType_T.cpp:50
gnsstk::ValidType::is_valid
bool is_valid() const
Definition: ValidType.hpp:96
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
main
int main()
Definition: ValidType_T.cpp:169
TUASSERTFE
#define TUASSERTFE(EXP, GOT)
Definition: TestUtil.hpp:103
gnsstk::ValidType::set_valid
void set_valid(const bool &v) noexcept
Definition: ValidType.hpp:99
ValidType_T
Definition: ValidType_T.cpp:47


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42