/
tests.h
57 lines (49 loc) · 1.08 KB
/
tests.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include <string>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <functional>
#include <unordered_map>
#include "engine.h"
#define TEST(name) tests[name] = []()
using namespace eia_v0_5;
using std::cout;
using std::endl;
using std::string;
using std::function;
using std::unordered_map;
class Tests
{
Engine * E;
unordered_map<string, function<bool()>> tests;
public:
explicit Tests(Engine * E) : E(E) { register_tests(); }
bool run()
{
int fails = 0;
for (auto test : tests)
{
cout << "Test \"" << test.first << "\" - ";
const bool success = test.second();
if (success)
{
cout << "passed" << endl;
}
else
{
cout << "failed!" << endl;
++fails;
}
}
cout << "Fails: " << fails << endl << endl;
if (fails > 0)
{
system("pause");
return false;
}
return true;
}
private:
void register_tests();
};