OTest2
A C++ testing framework
testmarkfloat.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <testmarkfloat.h>
20 
21 #include <assert.h>
22 #include <cmath>
23 #include <iomanip>
24 #include <iostream>
25 #include <limits>
26 
27 #include <testmarkhash.h>
28 #include <testmarkin.h>
29 #include <testmarkout.h>
30 
31 namespace OTest2 {
32 
33 namespace {
34 
35 const char SERIALIZE_TYPE_MARK[] = "ot2:float";
36 
37 } /* -- namespace */
38 
40  long double value_) :
41  value(value_) {
42 
43 }
44 
46  const CtorMark*) :
47  value(0.0L) {
48 
49 }
50 
52 
53 }
54 
55 const char* TestMarkFloat::typeMark() {
56  return SERIALIZE_TYPE_MARK;
57 }
58 
59 TestMarkHashCode TestMarkFloat::doGetHashCode() const noexcept {
60  return TestMarkHash::hashBasicType(SERIALIZE_TYPE_MARK, value);
61 }
62 
63 bool TestMarkFloat::doIsEqual(
64  const TestMark& other_,
65  long double precision_) const {
66  return std::abs(value - static_cast<const TestMarkFloat*>(&other_)->value)
67  <= precision_;
68 }
69 
70 bool TestMarkFloat::doIsEqualValue(
71  const TestMark& other_,
72  long double precision_) const {
73  return doIsEqual(other_, precision_);
74 }
75 
76 void TestMarkFloat::doDiffArray(
77  int level_,
78  std::vector<LinearizedRecord>& array_) const
79 {
80  /* -- there are no children */
81 }
82 
83 void TestMarkFloat::doLinearizedMark(
84  int level_,
85  const std::string& label_,
86  std::vector<LinearizedRecord>& array_) const {
87  array_.push_back({level_, this, label_});
88 }
89 
90 void TestMarkFloat::doPrintOpen(
91  std::ostream& os_,
92  const std::string& prefix_) const {
93  os_ << prefix_
94  << std::setprecision(
95  std::numeric_limits<long double>::digits10 + 1)
96  << value << '\n';
97 }
98 
99 void TestMarkFloat::doPrintClose(
100  std::ostream& os_,
101  const std::string& prefix_) const {
102  /* -- nothing to do */
103 }
104 
105 void TestMarkFloat::doSerializeMark(
106  TestMarkOut& serializer_) const {
107  serializer_.writeTypeMark(SERIALIZE_TYPE_MARK);
108  serializer_.writeFloat(value);
109 }
110 
111 void TestMarkFloat::doDeserializeMark(
112  TestMarkFactory& factory_,
113  TestMarkIn& deserializer_) {
114  value = deserializer_.readFloat();
115 }
116 
117 } /* namespace OTest2 */
testmarkhash.h
OTest2::TestMarkFloat::~TestMarkFloat
virtual ~TestMarkFloat()
Dtor.
Definition: testmarkfloat.cpp:51
OTest2::TestMarkHashCode
std::uint64_t TestMarkHashCode
Definition: testmarkhashcode.h:28
OTest2::TestMarkHash::hashBasicType
static TestMarkHashCode hashBasicType(const char *type_name_, Type_ value_)
Definition: testmarkhash.h:122
OTest2::TestMarkFloat::typeMark
static const char * typeMark()
Get serialization typemark.
Definition: testmarkfloat.cpp:55
OTest2
Definition: assertbean.h:25
testmarkin.h
testmarkout.h
OTest2::TestMarkFloat::TestMarkFloat
TestMarkFloat(long double value_)
Ctor.
Definition: testmarkfloat.cpp:39
testmarkfloat.h
value
std::string value
Definition: runnerfiltertags.cpp:503