Sparse Virtual File System  0.4.0
A Sparse Virtual File System.
test.h
Go to the documentation of this file.
1 
32 #ifndef CPPSVF_TEST_H
33 #define CPPSVF_TEST_H
34 
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 
39 namespace SVFS {
40  namespace Test {
41 
42  extern const char test_data_bytes_512[];
43 
47  class ExceptionTest : public std::exception {
48  public:
49  explicit ExceptionTest(const std::string &in_msg) : msg(in_msg) {}
50 
51  [[nodiscard]] const std::string &message() const { return msg; }
52 
53  protected:
54  std::string msg;
55  };
56 
61  public:
62  explicit ExceptionTestConfiguration(const std::string &in_msg) : ExceptionTest(in_msg) {}
63  };
64 
68  class TestResult {
69  public:
80  TestResult(const std::string &m_function, const std::string &m_test,
81  int m_result, const std::string &m_errro_message, double m_exec_time,
84  m_error_message(m_errro_message),
87 
88  [[nodiscard]] const std::string &function() const { return m_function; }
89 
90  [[nodiscard]] const std::string &test() const { return m_test; }
91 
92  [[nodiscard]] int result() const { return m_result; }
93 
94  [[nodiscard]] const std::string &error_message() const { return m_error_message; }
95 
96  [[nodiscard]] double exec_time() const { return m_exec_time; }
97 
98  [[nodiscard]] size_t work_bytes() const { return m_work_bytes; }
99 
100  [[nodiscard]] bool has_error_message() const { return !m_error_message.empty(); }
101 
103  [[nodiscard]] double work_rate() const {
104  if (m_exec_time != 0.0) {
105  return m_work_bytes / m_exec_time;
106  }
107  return 0.0;
108  }
109 
111  [[nodiscard]] double ms_per_mb() const {
112  if (m_work_bytes != 0.0) {
113  return m_exec_time * 1000 * (1 << 20) / m_work_bytes;
114  }
115  return 0.0;
116  }
117 
118  private:
119  std::string m_function;
120  std::string m_test;
121  int m_result;
122  std::string m_error_message;
123  double m_exec_time;
124  size_t m_work_bytes;
125  };
126 
127 
128  typedef std::vector<TestResult> t_test_results;
129 
130 
131  void write_test_results(const t_test_results &results, std::ostream &os);
132 
133 
137  class TestCount {
138  public:
139  TestCount() : m_pass(0), m_fail(0) {}
140 
141  [[nodiscard]] size_t pass() const { return m_pass; }
142 
143  [[nodiscard]] size_t fail() const { return m_fail; }
144 
145  [[nodiscard]] size_t total() const { return m_pass + m_fail; }
146 
148  void add_result(int result) {
149  if (result) {
150  m_fail += 1;
151  } else {
152  m_pass += 1;
153  }
154  }
155 
158  m_pass += rhs.m_pass;
159  m_fail += rhs.m_fail;
160  return *this;
161  }
162 
163  private:
164  size_t m_pass;
165  size_t m_fail;
166  };
167 
168  } // namespace Test
169 } // namespace SVFS
170 
171 #endif //CPPSVF_TEST_H
Exception used where a test case is miss-configured.
Definition: test.h:60
ExceptionTestConfiguration(const std::string &in_msg)
Definition: test.h:62
Exception used in place of asserts so that checks are done in release version.
Definition: test.h:47
const std::string & message() const
Definition: test.h:51
std::string msg
Definition: test.h:54
ExceptionTest(const std::string &in_msg)
Definition: test.h:49
Count of tests taht pass and fail.
Definition: test.h:137
size_t pass() const
Definition: test.h:141
size_t fail() const
Definition: test.h:143
size_t total() const
Definition: test.h:145
TestCount operator+=(const TestCount &rhs)
Append a test result.
Definition: test.h:157
void add_result(int result)
Add a tests result.
Definition: test.h:148
Result of a test.
Definition: test.h:68
double exec_time() const
Definition: test.h:96
size_t work_bytes() const
Definition: test.h:98
TestResult(const std::string &m_function, const std::string &m_test, int m_result, const std::string &m_errro_message, double m_exec_time, size_t m_work_bytes)
Definition: test.h:80
std::string m_test
Definition: test.h:120
std::string m_function
Definition: test.h:119
const std::string & test() const
Definition: test.h:90
double ms_per_mb() const
Returns the cost in ms/Mb.
Definition: test.h:111
std::string m_error_message
Definition: test.h:122
const std::string & error_message() const
Definition: test.h:94
size_t m_work_bytes
Definition: test.h:124
int result() const
Definition: test.h:92
double work_rate() const
Returns the work rate in bytes/second.
Definition: test.h:103
bool has_error_message() const
Definition: test.h:100
double m_exec_time
Definition: test.h:123
std::vector< TestResult > t_test_results
Definition: test.h:128
const char test_data_bytes_512[]
Definition: test.cpp:51
void write_test_results(const t_test_results &results, std::ostream &os)
Definition: test.cpp:106
The namespace for all svfsc code.
Definition: svf.cpp:41