Skip to content

Commit

Permalink
Remove some unsignedness from ints in tests code.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 13, 2024
1 parent 7447ed0 commit be07962
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
22 changes: 11 additions & 11 deletions test/BulletTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <src/Config.h>
#include <src/Direction.h>

const unsigned int bulletPower{4};
const unsigned int bulletSpeed{10};
const int bulletPower{4};
const int bulletSpeed{10};
const Point point{5, 5};
const bool enemyOrigin = false;
const bool playerOrigin = true;
Expand Down Expand Up @@ -61,29 +61,29 @@ TEST_CASE("Bullet coordinates", "[bullet]")
SECTION("getX is working")
{
const Point currentPoint{bullet.getLocation()};
const unsigned int currentX{bullet.getX()};
const int currentX{bullet.getX()};
REQUIRE(currentX == currentPoint.x_);
}
SECTION("getY is working")
{
const Point currentPoint{bullet.getLocation()};
const unsigned int currentY{bullet.getY()};
const int currentY{bullet.getY()};
REQUIRE(currentY == currentPoint.y_);
}

SECTION("setX is working")
{
const unsigned int newX{15};
const int newX{15};
bullet.setX(newX);
const unsigned int currentX{bullet.getX()};
const int currentX{bullet.getX()};
REQUIRE(currentX == newX);
}

SECTION("setY is working")
{
const unsigned int newY{27};
const int newY{27};
bullet.setY(newY);
const unsigned int currentY{bullet.getY()};
const int currentY{bullet.getY()};
REQUIRE(currentY == newY);
}
}
Expand All @@ -107,7 +107,7 @@ TEST_CASE("Bullet moving", "[bullet]")
SECTION("bullet moving inside valid area")
{
using TestData = std::pair<Direction, Point>;
const unsigned int middle{Config::getInstance().getBoardWidth() / 2};
const int middle{Config::getInstance().getBoardWidth() / 2};
auto [direction, expectedPoint] = GENERATE_REF(
TestData{Direction::UP, Point{middle, middle - bulletSpeed}},
TestData{Direction::DOWN, Point{middle, middle + bulletSpeed}},
Expand Down Expand Up @@ -143,8 +143,8 @@ TEST_CASE("Bullet moving", "[bullet]")
TEST_CASE("Bullet moving to invalid area", "[bullet]")
{
using TestData = std::pair<Direction, Point>;
const unsigned int nearEndOfMap{Config::getInstance().getBoardWidth() -
bulletSpeed / 2};
const int nearEndOfMap{Config::getInstance().getBoardWidth() -
bulletSpeed / 2};
auto [direction, pointGenerated] =
GENERATE_REF(TestData{Direction::UP, point},
TestData{Direction::DOWN, Point{point.x_, nearEndOfMap}},
Expand Down
16 changes: 8 additions & 8 deletions test/MapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace
{
const unsigned int tileCount{5};
const int tileCount{5};

std::string getTestMap()
{
Expand All @@ -36,13 +36,13 @@ std::string getTestMap()
"50401\n"};
}

Point tileToPoint(unsigned int tileX, unsigned int tileY)
Point tileToPoint(int tileX, int tileY)
{
static const unsigned int tileSize{Config::getInstance().getTileSize()};
static const int tileSize{Config::getInstance().getTileSize()};
return {tileX * tileSize, tileY * tileSize};
}

const unsigned int testHitStrength{10};
const int testHitStrength{10};
} // namespace

TEST_CASE("Map loading", "[map]")
Expand All @@ -59,7 +59,7 @@ TEST_CASE("Map loading", "[map]")
SECTION("check tanks location")
{
const auto tanks{map.loadMap(stream)};
const unsigned int tileSize{Config::getInstance().getTileSize()};
const int tileSize{Config::getInstance().getTileSize()};
auto tankIter{tanks.begin()};
REQUIRE(tankIter->getLocation() == Point{0, 0});
REQUIRE((++tankIter)->getLocation() == Point{0, 2 * tileSize});
Expand Down Expand Up @@ -256,13 +256,13 @@ std::string getTestMapForShifting()
}
} // namespace

const unsigned int tileCountForShifting{3};
const int tileCountForShifting{3};

TEST_CASE("shift", "[map]")
{
std::stringstream stream(getTestMapForShifting());
static const unsigned int tileSize{Config::getInstance().getTileSize()};
static const unsigned int twoTiles{tileSize * 2};
static const int tileSize{Config::getInstance().getTileSize()};
static const int twoTiles{tileSize * 2};

Map map(tileCountForShifting);
map.loadMap(stream);
Expand Down
2 changes: 1 addition & 1 deletion test/MapUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
TEST_CASE("Move points", "[MapUtils]")
{
const Point leftUpperCorner{100, 100};
const unsigned int tileSize{30};
const int tileSize{30};
SECTION("number of point returned")
{
const std::vector<Point> movePoints{
Expand Down
18 changes: 9 additions & 9 deletions test/TankTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TEST_CASE("location related", "[tank]")

SECTION("get center")
{
const unsigned int halfOfTile{Config::getInstance().getTileSize() / 2};
const int halfOfTile{Config::getInstance().getTileSize() / 2};
const Tank tank(TankType::ENEMY_TIER_1, point);
REQUIRE(tank.getCenter() == Point{
100 + halfOfTile,
Expand All @@ -103,7 +103,7 @@ TEST_CASE("location related", "[tank]")

SECTION("is within")
{
const unsigned int tileSize{Config::getInstance().getTileSize()};
const int tileSize{Config::getInstance().getTileSize()};
using TestData = std::pair<Point, bool>;
const auto [pointToTest, expectedIsWithin] = GENERATE_REF(
TestData{Point{99, 99}, false}, TestData{Point{99, 100}, false},
Expand Down Expand Up @@ -250,7 +250,7 @@ TEST_CASE("respawn", "[tank]")
SECTION("check speed after respawn")
{
Tank tank(TankType::PLAYER_TIER_1, point);
const unsigned int speed{tank.getStats().speed_};
const int speed{tank.getStats().speed_};
tank.hit(3);
REQUIRE(tank.getStats().speed_ == speed);
}
Expand All @@ -264,7 +264,7 @@ TEST_CASE("firing", "[tank]")
const Point point{100, 100};
SECTION("center of created bullet")
{
const unsigned int tileSize{Config::getInstance().getTileSize()};
const int tileSize{Config::getInstance().getTileSize()};
Tank tank(TankType::PLAYER_TIER_1, point);
const Bullet bullet = tank.fire(TimePoint::max());
const Point expectedBulletCenter{point.x_ + tileSize / 2,
Expand Down Expand Up @@ -320,7 +320,7 @@ TEST_CASE("power-ups", "[tank]")
SECTION("life-up")
{
Tank tank(TankType::PLAYER_TIER_4, point);
const unsigned int initialLives{tank.getStats().lives_};
const int initialLives{tank.getStats().lives_};
tank.applyPowerUp(ResourceType::LIFE_UP);
REQUIRE(tank.getStats().lives_ == initialLives + 1);
}
Expand All @@ -343,7 +343,7 @@ TEST_CASE("power-ups", "[tank]")
{
Tank tank(TankType::PLAYER_TIER_1, point);
tank.applyPowerUp(ResourceType::LIFE_UP);
const unsigned int initialLives{tank.getStats().lives_};
const int initialLives{tank.getStats().lives_};
tank.applyPowerUp(ResourceType::TIER_UP);
REQUIRE(tank.getStats().lives_ == initialLives);
}
Expand All @@ -353,7 +353,7 @@ TEST_CASE("power-ups", "[tank]")
Tank tank(TankType::PLAYER_TIER_2, point);
tank.applyPowerUp(ResourceType::SPEED_UP);
tank.applyPowerUp(ResourceType::SPEED_UP);
const unsigned int initialSpeed{tank.getStats().speed_};
const int initialSpeed{tank.getStats().speed_};
tank.applyPowerUp(ResourceType::TIER_UP);
REQUIRE(tank.getStats().speed_ == initialSpeed);
}
Expand All @@ -362,7 +362,7 @@ TEST_CASE("power-ups", "[tank]")
{
Tank tank(TankType::PLAYER_TIER_2, point);
tank.applyPowerUp(ResourceType::SPEED_UP);
const unsigned int initialSpeed{tank.getStats().speed_};
const int initialSpeed{tank.getStats().speed_};
tank.applyPowerUp(ResourceType::TIER_UP);
tank.applyPowerUp(ResourceType::TIER_UP);
REQUIRE(tank.getStats().speed_ > initialSpeed);
Expand All @@ -371,7 +371,7 @@ TEST_CASE("power-ups", "[tank]")
SECTION("speed-up")
{
Tank tank(TankType::PLAYER_TIER_1, point);
const unsigned int initialSpeed{tank.getStats().speed_};
const int initialSpeed{tank.getStats().speed_};
tank.applyPowerUp(ResourceType::SPEED_UP);
REQUIRE(tank.getStats().speed_ > initialSpeed);
}
Expand Down

0 comments on commit be07962

Please sign in to comment.