Generalize from HashSets to IEnumerables or Collections

pull/52/head
Alexis Drai 2 years ago
parent 0f3471cb60
commit fb69b719b4

@ -1,29 +1,25 @@
using Model; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Xunit; using Xunit;
using Xunit.Sdk;
namespace Tests.Model_UTs namespace Tests.Model_UTs
{ {
public class PlayerManagerTest public class PlayerManagerTest
{ {
[Fact] [Fact]
public void TestConstructorReturnsEmptyHashSet() public void TestConstructorReturnsEmptyEnumerable()
{ {
// Arrange // Arrange
PlayerManager playerManager; PlayerManager playerManager = new();
HashSet<Player> expected; IEnumerable<Player> expected;
HashSet<Player> actual; IEnumerable<Player> actual;
// Act // Act
playerManager = new(); expected = new Collection<Player>();
expected = new(); actual = playerManager.GetAll();
actual = (HashSet<Player>)playerManager.GetAll();
// Assert // Assert
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
@ -36,10 +32,10 @@ namespace Tests.Model_UTs
PlayerManager playerManager = new(); PlayerManager playerManager = new();
Player alice = new("Alice"); Player alice = new("Alice");
Player bob = new("Bob"); Player bob = new("Bob");
HashSet<Player> expected = new() { alice, bob };
// Act // Act
HashSet<Player> actual = new() Collection<Player> expected = new() { alice, bob };
Collection<Player> actual = new()
{ {
playerManager.Add(alice), playerManager.Add(alice),
playerManager.Add(bob) playerManager.Add(bob)
@ -59,7 +55,7 @@ namespace Tests.Model_UTs
// Act // Act
expected = null; expected = null;
actual = playerManager.Add(expected); actual = playerManager.Add(expected);// Add() returns the added element if succesful
// Assert // Assert
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
@ -155,11 +151,11 @@ namespace Tests.Model_UTs
Player player = new("Dylan"); Player player = new("Dylan");
playerManager.Add(player); playerManager.Add(player);
Player notPlayer = null; Player notPlayer = null;
HashSet<Player> expected = new() { player }; IEnumerable<Player> expected = new Collection<Player> { player };
// Act // Act
playerManager.Remove(notPlayer); playerManager.Remove(notPlayer);
HashSet<Player> actual = (HashSet<Player>)playerManager.GetAll(); IEnumerable<Player> actual = playerManager.GetAll();
// Assert // Assert
Assert.Equal(actual, expected); Assert.Equal(actual, expected);
@ -173,11 +169,11 @@ namespace Tests.Model_UTs
Player player = new("Dylan"); Player player = new("Dylan");
playerManager.Add(player); playerManager.Add(player);
Player notPlayer = new("Eric"); Player notPlayer = new("Eric");
HashSet<Player> expected = new() { player }; IEnumerable<Player> expected = new Collection<Player> { player };
// Act // Act
playerManager.Remove(notPlayer); playerManager.Remove(notPlayer);
HashSet<Player> actual = (HashSet<Player>)playerManager.GetAll(); IEnumerable<Player> actual = playerManager.GetAll();
// Assert // Assert
Assert.Equal(actual, expected); Assert.Equal(actual, expected);
@ -198,6 +194,7 @@ namespace Tests.Model_UTs
// Assert // Assert
Assert.DoesNotContain(oldPlayer, playerManager.GetAll()); Assert.DoesNotContain(oldPlayer, playerManager.GetAll());
Assert.Contains(newPlayer, playerManager.GetAll()); Assert.Contains(newPlayer, playerManager.GetAll());
Assert.True(playerManager.GetAll().Count() == 1);
} }
[Theory] [Theory]

Loading…
Cancel
Save