-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.h
37 lines (32 loc) · 1.26 KB
/
test_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include "vector.h"
#include <cstdio>
inline void equal_or_error(const std::string &file, int line,
int expected, int output) {
if (expected != output) {
fprintf(stderr, "Test failed at %s, line %d.\n", file.c_str(), line);
fprintf(stderr, "Expected %d, got %d.\n", expected, output);
exit(1);
}
}
template <typename T>
void equal_or_error(const std::string &file, int line,
T expected, T output, T tolerance = 1e-3f) {
if (fabs(expected - output) > tolerance) {
fprintf(stderr, "Test failed at %s, line %d.\n", file.c_str(), line);
std::cerr << "Expected " << expected << ", got " << output << std::endl;
exit(1);
}
}
template <typename T>
void equal_or_error(const std::string &file, int line,
const TVector3<T> &expected,
const TVector3<T> &output, T tolerance = 1e-3f) {
if (fabs(expected[0] - output[0]) > tolerance ||
fabs(expected[1] - output[1]) > tolerance ||
fabs(expected[2] - output[2]) > tolerance) {
fprintf(stderr, "Test failed at %s, line %d.\n", file.c_str(), line);
std::cerr << "Expected " << expected << ", got " << output << std::endl;
exit(1);
}
}