public void Choose_WhenCloneFuncWasNotDefined_WillThrowInvalidOperationException() { WeightedPool <int> pool = new WeightedPool <int>(Singleton.DefaultRandom); pool.Add(1, 1); Assert.ThrowsException <InvalidOperationException>(() => pool.Choose()); }
public void Choose_WhenPoolHas1Item_WillGetCloneOfItemWithDifferentReference() { WeightedPool <PlayingCard> pool = new WeightedPool <PlayingCard>(Singleton.DefaultRandom, PlayingCard.Clone); PlayingCard kingOfHearts = new PlayingCard { DisplayName = "King of Hearts", FaceValue = 13, Suit = PlayingCard.Suits.Hearts }; pool.Add(kingOfHearts, 1); PlayingCard selectedCard = pool.Choose(); Assert.AreNotEqual(kingOfHearts, selectedCard); Assert.AreEqual(kingOfHearts.FaceValue, selectedCard.FaceValue); Assert.AreEqual(kingOfHearts.DisplayName, selectedCard.DisplayName); Assert.AreEqual(kingOfHearts.Suit, selectedCard.Suit); Assert.AreEqual(1, pool.Count); }
public void Choose_WhenPoolHas0Items_WillThrowInvalidOperationException() { WeightedPool <int> pool = new WeightedPool <int>(Singleton.DefaultRandom, x => x); Assert.ThrowsException <InvalidOperationException>(() => pool.Choose()); }