public void Remove() { var variants = new HashSet <int>(new int[] { 1, 2, 6, 7, 8 }); var enumerator = new ThemeDeletersEnumerator(new ThemeDeletersEnumerator.IndexInfo[] { new ThemeDeletersEnumerator.IndexInfo(4), new ThemeDeletersEnumerator.IndexInfo(0), new ThemeDeletersEnumerator.IndexInfo(3), new ThemeDeletersEnumerator.IndexInfo(variants), new ThemeDeletersEnumerator.IndexInfo(variants), new ThemeDeletersEnumerator.IndexInfo(variants), new ThemeDeletersEnumerator.IndexInfo(variants), new ThemeDeletersEnumerator.IndexInfo(variants), new ThemeDeletersEnumerator.IndexInfo(5) }); enumerator.RemoveAt(1); var newVariants = new HashSet <int>(new int[] { 1, 5, 6, 7 }); enumerator.Reset(false); enumerator.MoveNext(); Assert.AreEqual(3, enumerator.Current.PlayerIndex); enumerator.MoveNext(); Assert.AreEqual(0, enumerator.Current.PlayerIndex); enumerator.MoveNext(); Assert.AreEqual(2, enumerator.Current.PlayerIndex); enumerator.MoveNext(); Assert.AreEqual(-1, enumerator.Current.PlayerIndex); Assert.AreEqual(newVariants, enumerator.Current.PossibleIndicies); enumerator.MoveNext(); Assert.AreEqual(-1, enumerator.Current.PlayerIndex); Assert.AreEqual(newVariants, enumerator.Current.PossibleIndicies); enumerator.MoveNext(); Assert.AreEqual(-1, enumerator.Current.PlayerIndex); Assert.AreEqual(newVariants, enumerator.Current.PossibleIndicies); enumerator.MoveNext(); Assert.AreEqual(-1, enumerator.Current.PlayerIndex); Assert.AreEqual(newVariants, enumerator.Current.PossibleIndicies); enumerator.MoveNext(); Assert.AreEqual(4, enumerator.Current.PlayerIndex); Assert.IsFalse(enumerator.MoveNext()); }
public void RemoveNew() { var variants = new HashSet <int>(new int[] { 4 }); var newVariants = new HashSet <int>(new int[] { 3 }); var enumerator = new ThemeDeletersEnumerator(new [] { new ThemeDeletersEnumerator.IndexInfo(1), new ThemeDeletersEnumerator.IndexInfo(0), new ThemeDeletersEnumerator.IndexInfo(2), new ThemeDeletersEnumerator.IndexInfo(variants) }); enumerator.RemoveAt(3); enumerator.Reset(false); enumerator.MoveNext(); enumerator.MoveNext(); enumerator.MoveNext(); enumerator.MoveNext(); Assert.AreEqual(newVariants, enumerator.Current.PossibleIndicies); }
public void FinalStakersTest(int[] sums, int themesCount, int[] order) { var players = new List <GamePlayerAccount>(); for (int i = 0; i < sums.Length; i++) { players.Add(new GamePlayerAccount(new Account()) { Sum = sums[i], InGame = sums[i] > 0 }); } var enumerator = new ThemeDeletersEnumerator(players, themesCount); enumerator.Reset(false); var playerSets = new List <HashSet <int> >(); for (int i = 0; i < order.Length; i++) { Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(enumerator.Current.PlayerIndex, order[i]); if (enumerator.Current.PlayerIndex == -1) { var found = false; for (int j = 0; j < playerSets.Count; j++) { if (playerSets[j].Intersect(enumerator.Current.PossibleIndicies).Any()) { found = true; Assert.AreEqual(playerSets[j], enumerator.Current.PossibleIndicies); } } if (!found) { playerSets.Add(enumerator.Current.PossibleIndicies); } } } Assert.IsFalse(enumerator.MoveNext()); enumerator.Reset(false); while (enumerator.MoveNext()) { if (enumerator.Current.PlayerIndex == -1) { var list = enumerator.Current.PossibleIndicies; var count = list.Count; var newIndex = list.First(); enumerator.Current.SetIndex(newIndex); Assert.AreEqual(enumerator.Current.PlayerIndex, newIndex); Assert.IsTrue(list.Count == count - 1); Assert.IsTrue(!list.Contains(newIndex)); } } }