-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet_test.cpp
93 lines (80 loc) · 2.77 KB
/
bullet_test.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <boost/test/unit_test.hpp>
#include "bullet.h"
#include "helper.h"
BOOST_AUTO_TEST_CASE(bullet_construction)
{
const double damage{10.0};
const double x{1.2};
const double y{3.4};
const double speed_x{0.8};
const double speed_y{0.6};
const int world_size{100};
const bullet b(damage, x, y, speed_x, speed_y);
BOOST_CHECK_EQUAL(b.get_damage(), damage);
BOOST_CHECK_EQUAL(b.get_x(), x);
BOOST_CHECK_EQUAL(b.get_y(), y);
BOOST_CHECK_EQUAL(b.get_speed_x(), speed_x);
BOOST_CHECK_EQUAL(b.get_speed_y(), speed_y);
}
BOOST_AUTO_TEST_CASE(bullet_set_and_get_must_be_symmetrical)
{
const double damage{10.0};
const double x{1.2};
const double y{3.4};
const double speed_x{0.8};
const double speed_y{0.6};
const int world_size{100};
bullet b(damage, x, y, speed_x, speed_y);
const double new_x{12.34};
const double new_y{56.78};
b.set_position(new_x, new_y);
BOOST_CHECK_EQUAL(b.get_x(), new_x);
BOOST_CHECK_EQUAL(b.get_y(), new_y);
}
BOOST_AUTO_TEST_CASE(remove_bullets_without_speed)
{
using position = std::pair<double, double>;
const double damage{10.0};
const position pos1{-10.0, 10.0}; //Left
const position pos2{ 10.0, -10.0}; //Top
const position pos3{110.0, 10.0}; //Right
const position pos4{ 10.0, 110.0}; //Bottom
const double speed_x{0.8};
const double speed_y{0.6};
const int world_size{100};
const bullet a(damage, pos1.first, pos1.second, speed_x, speed_y);
const bullet b(damage, pos2.first, pos2.second, speed_x, speed_y);
const bullet c(damage, pos3.first, pos3.second, speed_x, speed_y);
const bullet d(damage, pos4.first, pos4.second, speed_x, speed_y);
std::vector<bullet> bullets = { a, b, c, d };
//BULLETS WITHOUT SPEED SHOULD BE REMOVED
}
BOOST_AUTO_TEST_CASE(keep_with_speed_bullets)
{
using position = std::pair<double, double>;
const double damage{10.0};
const position pos{10.0, 10.0};
const double speed_x{0.8};
const double speed_y{0.6};
const int world_size{100};
const bullet b(damage, pos.first, pos.second, speed_x, speed_y);
std::vector<bullet> bullets = { b };
//BULLETS WITH SPEED SHOULD NOT BE REMOVED
}
BOOST_AUTO_TEST_CASE(check_move)
{
using position = std::pair<double, double>;
const double damage{10.0};
const position pos{10.0, 10.0};
const double speed_x{0.8};
const double speed_y{0.6};
const int world_size{100};
bullet b(damage, pos.first, pos.second, speed_x, speed_y);
const position pos_before = { b.get_x(), b.get_y() };
b.move(world_size);
const position pos_after = { b.get_x(), b.get_y() };
BOOST_CHECK_NE(pos_before.first, pos_after.first);
BOOST_CHECK_NE(pos_before.second, pos_after.second);
BOOST_CHECK_CLOSE(pos_after.first, pos_before.first + speed_x, 0.0001);
BOOST_CHECK_CLOSE(pos_after.second, pos_before.second + speed_y, 0.0001);
}