-
Notifications
You must be signed in to change notification settings - Fork 0
/
hffm_solution_test.h
67 lines (61 loc) · 1.5 KB
/
hffm_solution_test.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
58
59
60
61
62
63
64
65
66
#include <cxxtest/TestSuite.h>
extern "C" {
#include "hffm_solution.h"
#include "hffm_solution_private.h"
#include "hffm_mock_solution.h"
}
#include <iostream>
using namespace std;
class SolutionTestSuite : public CxxTest::TestSuite
{
hffm_solution_t *sol;
mock_solution_t *msol;
public:
void setUp()
{
msol = mock_solution_new();
sol = (hffm_solution_t *) msol;
}
void tearDown()
{
mock_solution_really_free(msol);
}
void test_free()
{
TS_ASSERT_EQUALS(msol->times_free_called, 0);
hffm_solution_free(sol);
TS_ASSERT_EQUALS(msol->times_free_called, 1);
}
void test_vary()
{
TS_ASSERT_EQUALS(msol->times_vary_called, 0);
hffm_solution_vary(sol, 1.0);
TS_ASSERT_EQUALS(msol->times_vary_called, 1);
TS_ASSERT_EQUALS(msol->last_vary_amt, 1.0);
hffm_solution_vary(sol, 0.25);
TS_ASSERT_EQUALS(msol->times_vary_called, 2);
TS_ASSERT_EQUALS(msol->last_vary_amt, 0.25);
}
void test_error()
{
msol->error = 1.0;
TS_ASSERT_EQUALS(hffm_solution_error(sol), 1.0);
msol->error = 10.0;
TS_ASSERT_EQUALS(hffm_solution_error(sol), 10.0);
}
void test_copy()
{
TS_ASSERT_EQUALS(msol->generation, 0);
hffm_solution_t *sol2 = hffm_solution_copy(sol);
mock_solution_t *msol2 = (mock_solution_t *) sol2;
TS_ASSERT_EQUALS(msol->generation, 0);
TS_ASSERT_EQUALS(msol2->generation, 1);
mock_solution_really_free(msol2);
}
void test_accepted()
{
TS_ASSERT_EQUALS(msol->times_accepted_called, 0);
hffm_solution_accepted(sol);
TS_ASSERT_EQUALS(msol->times_accepted_called, 1);
}
};