Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. #include "../library/teamList.h"
  2. #include <gtest/gtest.h>
  3.  
  4. #define LISTSIZE 6
  5.  
  6. TEST(LinkedListTest, can_search_playerList)
  7. {
  8.     PlayerNode testPlayers[LISTSIZE] = {
  9.         {"Richard Simmons",  'U', 'd', 459, 32, 203, NULL},
  10.         {"Richard Stallman", 'I', 'f', 70,  15,  52, NULL},
  11.         {"Bill Joy",         'C', 'd', 37,   6,  55, NULL},
  12.         {"Linus Torvalds",   'F', 'g', 19,  22, 123, NULL},
  13.         {"Dave Cutler",      'U', 'g', 54,  10, 345, NULL},
  14.         {"Mark Russonivich", 'U', 'd', 42,  62, 545, NULL},
  15.     };
  16.    
  17.     int orderedMapping[LISTSIZE] = {2, 3, 0, 4, 5, 1};
  18.  
  19.     // Head of the player list we're building    
  20.     PlayerNode *playerList = NULL;  
  21.    
  22.     for (int i = 0; i != LISTSIZE; i++) {
  23.    
  24.         PlayerNode *p = &testPlayers[i];
  25.         PlayerNode *newplayer = createPlayer(p->name,     p->team,
  26.                                              p->position, p->goals,
  27.                                              p->assists,  p->goalsAgainst);
  28.    
  29.         ASSERT_TRUE(newplayer != NULL);
  30.         insertPlayer(playerList, newplayer);
  31.    
  32.     }
  33.    
  34.     for (int i = 0; i != LISTSIZE; i++) {
  35.    
  36.         int expectedIndex = orderedMapping[i];
  37.         PlayerNode *expected_player = &testPlayers[expectedIndex];
  38.         PlayerNode *playerFound = NULL;
  39.         bool success = false;
  40.        
  41.         search(playerList, i + 1, playerFound, success);
  42.        
  43.         ASSERT_TRUE(success) << " on index " << i;
  44.         ASSERT_TRUE(playerFound != NULL);
  45.        
  46.         EXPECT_STREQ(expected_player->name,      playerFound->name);
  47.         EXPECT_EQ(expected_player->team,         playerFound->team);
  48.         EXPECT_EQ(expected_player->position,     playerFound->position);
  49.         EXPECT_EQ(expected_player->goals,        playerFound->goals);
  50.         EXPECT_EQ(expected_player->assists,      playerFound->assists);
  51.         EXPECT_EQ(expected_player->goalsAgainst, playerFound->goalsAgainst);
  52.     }
  53.    
  54.     {  
  55.         PlayerNode *playerFound = &testPlayers[0];
  56.         bool success = true;
  57.        
  58.         search(testPlayers, LISTSIZE + 1, playerFound, success);
  59.        
  60.         ASSERT_FALSE(success);
  61.         ASSERT_TRUE(playerFound == NULL);
  62.     }
  63.    
  64.     destroyList(playerList);
  65. }
  66.  
  67. TEST(getIndexForTeamTest, fails_for_invalid_team)
  68. {
  69.     ASSERT_EQ(-1, getIndexForTeam('Z'));
  70. }
  71.  
  72. TEST(getIndexForTeamTest, works_for_valid_teams)
  73. {
  74.     EXPECT_EQ(0, getIndexForTeam('C'));
  75.     EXPECT_EQ(1, getIndexForTeam('F'));
  76.     EXPECT_EQ(2, getIndexForTeam('U'));
  77.     EXPECT_EQ(3, getIndexForTeam('I'));
  78. }
  79.  
  80. TEST(createPlayerTest, can_make_player)
  81. {
  82.     char expectedName [MAXNAMELEN + 1] = "Michael Walker";
  83.     char expectedTeam = 'C';
  84.     char expectedPosition = 'f';
  85.     int expectedGoals = 1;
  86.     int expectedAssists = 1;
  87.     int expectedGoalsAgainst = 0;
  88.    
  89.     PlayerNode *node = createPlayer(expectedName, expectedTeam, expectedPosition,
  90.                                     expectedGoals, expectedAssists, expectedGoalsAgainst);
  91.     ASSERT_TRUE(node != NULL);
  92.    
  93.     EXPECT_STREQ(expectedName,      node->name);  
  94.     EXPECT_EQ(expectedTeam,         node->team);
  95.     EXPECT_EQ(expectedGoals,        node->goals);
  96.     EXPECT_EQ(expectedAssists,      node->assists);
  97.     EXPECT_EQ(expectedPosition,     node->position);
  98.     EXPECT_EQ(expectedGoalsAgainst, node->goalsAgainst);
  99.     delete node;
  100. }
  101.  
  102. TEST(createPlayerTest, can_handle_really_long_name)
  103. {
  104.     char loadName [] =    
  105.         "Michael Snufalufalufalufalufalufalufalu"
  106.         "falufalufalufalufalufalufafagus";
  107.  
  108.     char compareName [] =
  109.         "Michael Snufalufalufalufa";
  110.    
  111.     PlayerNode *node = createPlayer(loadName, 'C', 'f', 1, 2, 3);
  112.     ASSERT_TRUE(node != NULL);
  113.     EXPECT_STREQ(compareName, node->name);
  114.     delete node;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement