From be079625eb1a810636880fecaafe195821f0e1e0 Mon Sep 17 00:00:00 2001 From: przemek83 <4788832+przemek83@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:16:20 +0200 Subject: [PATCH] Remove some unsignedness from ints in tests code. --- test/BulletTest.cpp | 22 +++++++++++----------- test/MapTest.cpp | 16 ++++++++-------- test/MapUtilsTest.cpp | 2 +- test/TankTest.cpp | 18 +++++++++--------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/BulletTest.cpp b/test/BulletTest.cpp index 688608d..91f8819 100644 --- a/test/BulletTest.cpp +++ b/test/BulletTest.cpp @@ -5,8 +5,8 @@ #include #include -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; @@ -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); } } @@ -107,7 +107,7 @@ TEST_CASE("Bullet moving", "[bullet]") SECTION("bullet moving inside valid area") { using TestData = std::pair; - 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}}, @@ -143,8 +143,8 @@ TEST_CASE("Bullet moving", "[bullet]") TEST_CASE("Bullet moving to invalid area", "[bullet]") { using TestData = std::pair; - 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}}, diff --git a/test/MapTest.cpp b/test/MapTest.cpp index b6137c8..42c645d 100644 --- a/test/MapTest.cpp +++ b/test/MapTest.cpp @@ -24,7 +24,7 @@ namespace { -const unsigned int tileCount{5}; +const int tileCount{5}; std::string getTestMap() { @@ -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]") @@ -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}); @@ -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); diff --git a/test/MapUtilsTest.cpp b/test/MapUtilsTest.cpp index 29bb491..6989522 100644 --- a/test/MapUtilsTest.cpp +++ b/test/MapUtilsTest.cpp @@ -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 movePoints{ diff --git a/test/TankTest.cpp b/test/TankTest.cpp index 23e8c83..c384457 100644 --- a/test/TankTest.cpp +++ b/test/TankTest.cpp @@ -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, @@ -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; const auto [pointToTest, expectedIsWithin] = GENERATE_REF( TestData{Point{99, 99}, false}, TestData{Point{99, 100}, false}, @@ -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); } @@ -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, @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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); }