-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
77 lines (62 loc) · 2.37 KB
/
test.cpp
File metadata and controls
77 lines (62 loc) · 2.37 KB
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
#include <iostream>
#include <cassert>
#include "src/GenerateDungeon/Character.h"
#include <SDL.h>
// Stubs for global/static variables needed by Character.cpp and Tile.cpp
SDL_Renderer* gRenderer = nullptr;
LTexture gTileTexture;
SDL_Rect gTileClips[TOTAL_TILE_SPRITES];
// We need a dummy for LTexture methods used in Character.cpp and Tile.cpp
void LTexture::render( int x, int y, SDL_Rect* clip, bool filter, double angle, SDL_Point* center, SDL_RendererFlip flip ) {}
LTexture::LTexture() : mTexture(nullptr), mWidth(0), mHeight(0) {}
LTexture::~LTexture() {}
void test_partial_healing() {
// x, y, maxHP, STR, VIT, state, dir, type, name
Character c(0, 0, 100, 10, 10, ALIVE, DOWN, PLAYER, "TestHero");
// nowHP starts at 100. reduce it.
// receiveDamage(55) -> 55 - (10/2) = 50 damage. nowHP = 50.
c.receiveDamage(55);
assert(c.getNowHP() == 50);
c.healed(30);
assert(c.getNowHP() == 80);
std::cout << "test_partial_healing passed!" << std::endl;
}
void test_full_healing() {
Character c(0, 0, 100, 10, 10, ALIVE, DOWN, PLAYER, "TestHero");
c.receiveDamage(55); // nowHP = 50
c.healed(50);
assert(c.getNowHP() == 100);
std::cout << "test_full_healing passed!" << std::endl;
}
void test_overflow_healing() {
Character c(0, 0, 100, 10, 10, ALIVE, DOWN, PLAYER, "TestHero");
c.receiveDamage(55); // nowHP = 50
c.healed(100);
// Introduce an artificial bug in the test assertion to confirm it can fail
// assert(c.getNowHP() == 150); // This should fail
assert(c.getNowHP() == 100);
std::cout << "test_overflow_healing passed!" << std::endl;
}
void test_healing_at_max_hp() {
Character c(0, 0, 100, 10, 10, ALIVE, DOWN, PLAYER, "TestHero");
assert(c.getNowHP() == 100);
c.healed(10);
assert(c.getNowHP() == 100);
std::cout << "test_healing_at_max_hp passed!" << std::endl;
}
void test_healing_with_zero() {
Character c(0, 0, 100, 10, 10, ALIVE, DOWN, PLAYER, "TestHero");
c.receiveDamage(55); // nowHP = 50
c.healed(0);
assert(c.getNowHP() == 50);
std::cout << "test_healing_with_zero passed!" << std::endl;
}
int main(int argc, char* argv[]) {
test_partial_healing();
test_full_healing();
test_overflow_healing();
test_healing_at_max_hp();
test_healing_with_zero();
std::cout << "All tests passed using real Character class!" << std::endl;
return 0;
}