Skip to content
Snippets Groups Projects
Commit 58ac6175 authored by Aidan Meara's avatar Aidan Meara
Browse files

card unit test

parent b8118bab
No related branches found
No related tags found
2 merge requests!17finalize common,!16Draft: Resolve "write_common_tests"
......@@ -2,3 +2,4 @@ cmake-build-debug/
sockpp/cmake-build-debug/
*.DS_Store
.idea/
build-tests/
......@@ -8,4 +8,5 @@ add_executable(Wizard-tests ${TEST_SOURCE_FILES})
target_compile_definitions(Wizard-tests PRIVATE WIZARD_SERVER=1 RAPIDJSON_HAS_STDSTRING=1)
target_link_libraries(Wizard-tests gtest gtest_main Wizard-lib)
\ No newline at end of file
target_link_libraries(Wizard-tests gtest gtest_main Wizard-lib)
......@@ -8,37 +8,37 @@
#include "../src/common/serialization/json_utils.h"
// A card can be played on another card if and only if the new card has the
// same value or the same value plus one than the previous card or the previous card
// has value 7 and the new card has value 1.
TEST(CardTest, PlayCardsOn1) {
card c_1(1);
card c_2(2);
card c_3(3);
card c_4(4);
card c_5(5);
card c_6(6);
card c_7(7);
EXPECT_TRUE(c_1.can_be_played_on((&c_1)));
EXPECT_TRUE(c_2.can_be_played_on((&c_1)));
EXPECT_TRUE(c_1.can_be_played_on((&c_7)));
EXPECT_FALSE(c_3.can_be_played_on((&c_1)));
EXPECT_FALSE(c_4.can_be_played_on((&c_1)));
EXPECT_FALSE(c_5.can_be_played_on((&c_1)));
EXPECT_FALSE(c_6.can_be_played_on((&c_1)));
EXPECT_FALSE(c_7.can_be_played_on((&c_1)));
EXPECT_FALSE(c_2.can_be_played_on((&c_7)));
EXPECT_FALSE(c_3.can_be_played_on((&c_7)));
EXPECT_FALSE(c_4.can_be_played_on((&c_7)));
EXPECT_FALSE(c_5.can_be_played_on((&c_7)));
EXPECT_FALSE(c_6.can_be_played_on((&c_7)));
// check proper initialization and getters
TEST(CardTest, MakeCardGetMembers) {
card c_1(0,0);
card c_2(14,0);
card c_3(1,2);
card c_4(4,3);
card c_5(5,4);
card c_6(6,3);
card c_7(7,2);
EXPECT_EQ(c_1.get_color(), 0);
EXPECT_EQ(c_2.get_color(), 0);
EXPECT_EQ(c_3.get_color(), 2);
EXPECT_EQ(c_4.get_color(), 3);
EXPECT_EQ(c_5.get_color(), 4);
EXPECT_EQ(c_6.get_color(), 3);
EXPECT_EQ(c_7.get_color(), 2);
EXPECT_EQ(c_1.get_value(), 0);
EXPECT_EQ(c_2.get_value(), 14);
EXPECT_EQ(c_3.get_value(), 1);
EXPECT_EQ(c_4.get_value(), 4);
EXPECT_EQ(c_5.get_value(), 5);
EXPECT_EQ(c_6.get_value(), 6);
EXPECT_EQ(c_7.get_value(), 7);
}
// Serialization and subsequent deserialization must yield the same object
TEST(CardTest, SerializationEquality) {
card card_send(1);
card card_send(1,1);
rapidjson::Document* json_send = card_send.to_json();
std::string message = json_utils::to_string(json_send);
delete json_send;
......@@ -46,8 +46,10 @@ TEST(CardTest, SerializationEquality) {
rapidjson::Document json_recv = rapidjson::Document(rapidjson::kObjectType);
json_recv.Parse(message.c_str());
card* card_recv = card::from_json(json_recv);
EXPECT_EQ(card_send.get_id(), card_recv->get_id());
EXPECT_EQ(card_send.get_value(), card_recv->get_value());
EXPECT_EQ(card_send.get_color(), card_recv->get_color());
delete card_recv;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment