Skip to content

Commit

Permalink
Tests for drawing status.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 3, 2024
1 parent 48e0cd6 commit 46c2f1d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/FakeDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ class FakeDisplay : public Display
int y_;
};

struct DrawnText
{
int x_;
int y_;
std::string text_;
};

bool init() override { return true; };

void drawText([[maybe_unused]] int x, [[maybe_unused]] int y,
[[maybe_unused]] const std::string& text) const override {};

void drawTextWithBackground(
[[maybe_unused]] int x, [[maybe_unused]] int y,
[[maybe_unused]] const std::string& text) const override {};
[[maybe_unused]] const std::string& text) const override
{
drawnTexts_.push_back({x, y, text});
};

void drawBackground(
[[maybe_unused]] ResourceType resourceType) const override {};
Expand Down Expand Up @@ -70,9 +80,15 @@ class FakeDisplay : public Display

void resetChangedAreas() { changedAreas_.clear(); }

std::vector<DrawnText> getDrawnTexts() const { return drawnTexts_; }

void resetDrawnTexts() { drawnTexts_.clear(); }

private:
int resourceWidth_ {0};
int resourceHeight_ {0};
int resourceWidth_{0};
int resourceHeight_{0};

mutable std::vector<ChangedArea> changedAreas_;

mutable std::vector<DrawnText> drawnTexts_;
};
28 changes: 28 additions & 0 deletions test/StatusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

#include <src/Status.h>

#include "FakeDisplay.h"

TEST_CASE("Status usage", "[Status]")
{
FakeDisplay display;
Status status{{100, 100}};
SECTION("Check resource type")
{
Expand All @@ -15,4 +18,29 @@ TEST_CASE("Status usage", "[Status]")
Point center{status.getCenter()};
REQUIRE(center == Point{200, 300});
}

SECTION("Check texts when drawing empty stats")
{
status.draw(display);
std::vector<FakeDisplay::DrawnText> drawnTexts{display.getDrawnTexts()};
REQUIRE(drawnTexts.size() == 4);
REQUIRE(drawnTexts[0].text_ == "Lives: 0");
REQUIRE(drawnTexts[1].text_ == "Shield: 0");
REQUIRE(drawnTexts[2].text_ == "Speed: 0");
REQUIRE(drawnTexts[3].text_ == "Attack: 0");
}

SECTION("Check Positions when drawing empty stats")
{
status.draw(display);
std::vector<FakeDisplay::DrawnText> drawnTexts{display.getDrawnTexts()};
REQUIRE(drawnTexts[0].x_ == 200);
REQUIRE(drawnTexts[0].y_ == 120);
REQUIRE(drawnTexts[1].x_ == 200);
REQUIRE(drawnTexts[1].y_ == 240);
REQUIRE(drawnTexts[2].x_ == 200);
REQUIRE(drawnTexts[2].y_ == 360);
REQUIRE(drawnTexts[3].x_ == 200);
REQUIRE(drawnTexts[3].y_ == 480);
}
}

0 comments on commit 46c2f1d

Please sign in to comment.