Skip to content

Commit

Permalink
Merge pull request #166 from NiskuT/improvement-27
Browse files Browse the repository at this point in the history
[improvement-27] Add test for shared elements
  • Loading branch information
NiskuT authored Jan 26, 2023
2 parents 3d7b214 + 6b73f81 commit 0a2ec24
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 3 deletions.
7 changes: 7 additions & 0 deletions test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
add_custom_test(map)
add_custom_test(rules)
add_custom_test(serialize)
add_custom_test(city)
add_custom_test(hexagon)
add_custom_test(controlpawn)
add_custom_test(barbarian)
add_custom_test(barbarianvillage)
add_custom_test(card)
add_custom_test(resource)
27 changes: 27 additions & 0 deletions test/shared/test_barbarian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( BarbarianTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::Barbarian barbarian;

shared::ElementEnum type = barbarian.getType();
BOOST_CHECK(type == shared::ElementEnum::barbarian);
BOOST_CHECK(barbarian.isAlive == true);
}

BOOST_AUTO_TEST_CASE( kill )
{
shared::Barbarian barbarian;
barbarian.kill();
BOOST_CHECK(barbarian.isAlive == false);
}

BOOST_AUTO_TEST_SUITE_END()
19 changes: 19 additions & 0 deletions test/shared/test_barbarianvillage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( BarbarianVillageTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::BarbarianVillage village;

shared::ElementEnum type = village.getType();
BOOST_CHECK(type == shared::ElementEnum::barbarianVillage);
}

BOOST_AUTO_TEST_SUITE_END()
34 changes: 34 additions & 0 deletions test/shared/test_card.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( CardTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::Card card(shared::CardsEnum::science);

shared::CardsEnum type = card.getType();
BOOST_CHECK(type == shared::CardsEnum::science);
BOOST_CHECK(card.getLevel() == 1);
}

BOOST_AUTO_TEST_CASE( boxAndDifficulty )
{
shared::Card card(shared::CardsEnum::science);

BOOST_CHECK(card.getNumberOfBox() == 0);
card.addBox(2);
BOOST_CHECK(card.getNumberOfBox() == 2);
card.removeBox(1);
BOOST_CHECK(card.getNumberOfBox() == 1);

card.setDificulty(3);
BOOST_CHECK(card.getDificulty() == 3);
}

BOOST_AUTO_TEST_SUITE_END()
36 changes: 36 additions & 0 deletions test/shared/test_city.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( CityTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::City city({20, 15});

BOOST_CHECK(city.getPosition()[0] == 20);
BOOST_CHECK(city.getPosition()[1] == 15);

shared::ElementEnum type = city.getType();
BOOST_CHECK(type == shared::ElementEnum::city);

BOOST_CHECK(city.isMature == false);
BOOST_CHECK(city.isCapital == false);
BOOST_CHECK(city.isStateCity == false);
}

BOOST_AUTO_TEST_CASE( setStateCity )
{
shared::City city({0, 0});
city.setStateCity(shared::CityStateEnum::mohenjoDaro);

BOOST_CHECK(city.stateCityType == shared::CityStateEnum::mohenjoDaro);
BOOST_CHECK(city.isStateCity == true);

}

BOOST_AUTO_TEST_SUITE_END()
30 changes: 30 additions & 0 deletions test/shared/test_controlpawn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( ControlPawnTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::ControlPawn pawn({20, 15});

BOOST_CHECK(pawn.getPosition()[0] == 20);
BOOST_CHECK(pawn.getPosition()[1] == 15);
BOOST_CHECK(pawn.isReinforced() == false);

shared::ElementEnum type = pawn.getType();
BOOST_CHECK(type == shared::ElementEnum::controlPawn);
}

BOOST_AUTO_TEST_CASE( setReinforced )
{
shared::ControlPawn pawn({0, 0});
pawn.setReinforced();
BOOST_CHECK(pawn.isReinforced() == true);
}

BOOST_AUTO_TEST_SUITE_END()
54 changes: 54 additions & 0 deletions test/shared/test_hexagon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( HexagonTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( constructorAndGetters )
{
shared::Hexagon hexagon;

BOOST_CHECK(hexagon.getFieldLevel() == shared::FieldLevel::Grassland);
}

BOOST_AUTO_TEST_CASE( setFieldType )
{
shared::Hexagon hexagon;

hexagon.setFieldType(shared::FieldLevel::WonderMessa);

BOOST_CHECK(hexagon.getFieldLevel() == shared::FieldLevel::WonderMessa);
}

BOOST_AUTO_TEST_CASE( manageElements )
{
shared::Hexagon hexagon;

BOOST_CHECK(hexagon.getElements().size() == 0);

std::shared_ptr<shared::Caravan> caravan1 = std::make_shared<shared::Caravan>();
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element1 = *caravan1;
hexagon.addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element1));

BOOST_CHECK(hexagon.getElements().size() == 1);

std::shared_ptr<shared::Caravan> caravan2 = std::make_shared<shared::Caravan>();
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element2 = *caravan2;
hexagon.addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element2));

BOOST_CHECK(hexagon.getElements().size() == 2);

hexagon.removeElement(hexagon.getElements()[0]);

BOOST_CHECK(hexagon.getElements().size() == 1);

hexagon.clearElement();

BOOST_CHECK(hexagon.getElements().size() == 0);
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 0 additions & 2 deletions test/shared/test_map.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <shared.hpp>
#include <ctime>
#include <iostream>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( MapTest )
Expand Down
23 changes: 23 additions & 0 deletions test/shared/test_resource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <shared.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( MapTest )

BOOST_AUTO_TEST_CASE(TestStaticAssert)
{
BOOST_CHECK(1);
}

BOOST_AUTO_TEST_CASE( all )
{
shared::Resource resource(shared::ResourceEnum::stone);

BOOST_CHECK(resource.getType() == shared::ResourceEnum::stone);
resource.isAlive = true;
resource.picked();
BOOST_CHECK(resource.isAlive == false);


}

BOOST_AUTO_TEST_SUITE_END()
1 change: 0 additions & 1 deletion test/shared/test_serialize.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <shared.hpp>
#include <iostream>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(SerializeTest)
Expand Down

0 comments on commit 0a2ec24

Please sign in to comment.