Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../library/teamList.h"
- #include <gtest/gtest.h>
- #define LISTSIZE 6
- TEST(LinkedListTest, can_search_playerList)
- {
- PlayerNode testPlayers[LISTSIZE] = {
- {"Richard Simmons", 'U', 'd', 459, 32, 203, NULL},
- {"Richard Stallman", 'I', 'f', 70, 15, 52, NULL},
- {"Bill Joy", 'C', 'd', 37, 6, 55, NULL},
- {"Linus Torvalds", 'F', 'g', 19, 22, 123, NULL},
- {"Dave Cutler", 'U', 'g', 54, 10, 345, NULL},
- {"Mark Russonivich", 'U', 'd', 42, 62, 545, NULL},
- };
- int orderedMapping[LISTSIZE] = {2, 3, 0, 4, 5, 1};
- // Head of the player list we're building
- PlayerNode *playerList = NULL;
- for (int i = 0; i != LISTSIZE; i++) {
- PlayerNode *p = &testPlayers[i];
- PlayerNode *newplayer = createPlayer(p->name, p->team,
- p->position, p->goals,
- p->assists, p->goalsAgainst);
- ASSERT_TRUE(newplayer != NULL);
- insertPlayer(playerList, newplayer);
- }
- for (int i = 0; i != LISTSIZE; i++) {
- int expectedIndex = orderedMapping[i];
- PlayerNode *expected_player = &testPlayers[expectedIndex];
- PlayerNode *playerFound = NULL;
- bool success = false;
- search(playerList, i + 1, playerFound, success);
- ASSERT_TRUE(success) << " on index " << i;
- ASSERT_TRUE(playerFound != NULL);
- EXPECT_STREQ(expected_player->name, playerFound->name);
- EXPECT_EQ(expected_player->team, playerFound->team);
- EXPECT_EQ(expected_player->position, playerFound->position);
- EXPECT_EQ(expected_player->goals, playerFound->goals);
- EXPECT_EQ(expected_player->assists, playerFound->assists);
- EXPECT_EQ(expected_player->goalsAgainst, playerFound->goalsAgainst);
- }
- {
- PlayerNode *playerFound = &testPlayers[0];
- bool success = true;
- search(testPlayers, LISTSIZE + 1, playerFound, success);
- ASSERT_FALSE(success);
- ASSERT_TRUE(playerFound == NULL);
- }
- destroyList(playerList);
- }
- TEST(getIndexForTeamTest, fails_for_invalid_team)
- {
- ASSERT_EQ(-1, getIndexForTeam('Z'));
- }
- TEST(getIndexForTeamTest, works_for_valid_teams)
- {
- EXPECT_EQ(0, getIndexForTeam('C'));
- EXPECT_EQ(1, getIndexForTeam('F'));
- EXPECT_EQ(2, getIndexForTeam('U'));
- EXPECT_EQ(3, getIndexForTeam('I'));
- }
- TEST(createPlayerTest, can_make_player)
- {
- char expectedName [MAXNAMELEN + 1] = "Michael Walker";
- char expectedTeam = 'C';
- char expectedPosition = 'f';
- int expectedGoals = 1;
- int expectedAssists = 1;
- int expectedGoalsAgainst = 0;
- PlayerNode *node = createPlayer(expectedName, expectedTeam, expectedPosition,
- expectedGoals, expectedAssists, expectedGoalsAgainst);
- ASSERT_TRUE(node != NULL);
- EXPECT_STREQ(expectedName, node->name);
- EXPECT_EQ(expectedTeam, node->team);
- EXPECT_EQ(expectedGoals, node->goals);
- EXPECT_EQ(expectedAssists, node->assists);
- EXPECT_EQ(expectedPosition, node->position);
- EXPECT_EQ(expectedGoalsAgainst, node->goalsAgainst);
- delete node;
- }
- TEST(createPlayerTest, can_handle_really_long_name)
- {
- char loadName [] =
- "Michael Snufalufalufalufalufalufalufalu"
- "falufalufalufalufalufalufafagus";
- char compareName [] =
- "Michael Snufalufalufalufa";
- PlayerNode *node = createPlayer(loadName, 'C', 'f', 1, 2, 3);
- ASSERT_TRUE(node != NULL);
- EXPECT_STREQ(compareName, node->name);
- delete node;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement