public void RemovePasses() { var helper = new HashSetHelper <int>(); var testData = new int[] { 100, 200 }; foreach (var d in testData) { helper.Add(d); } helper.Remove(testData[0]); AssertionUtils.AssertEnumerableByUnordered( new int[] { testData[1] } , helper.Items , "" ); helper.Remove(testData[1]); AssertionUtils.AssertEnumerableByUnordered( new int[] { } , helper.Items , "" ); }
public void OnRemovedInRemovePasses() { var helper = new HashSetHelper <int>(); var counter = 0; var recievedValue = 0; helper.OnRemoved.Add((v) => { counter++; recievedValue = v; }); var testData = new int[] { 100, 200 }; foreach (var d in testData) { helper.Add(d); } Assert.AreEqual(0, counter); helper.Remove(testData[0]); Assert.AreEqual(1, counter); Assert.AreEqual(testData[0], recievedValue); counter = 0; helper.Remove(testData[1]); Assert.AreEqual(1, counter); Assert.AreEqual(testData[1], recievedValue); }
public void OnRemovedInRemoveItemsPasses() { var helper = new HashSetHelper <int>(); var recievedList = new List <int>(); var counter = 0; helper.OnRemoved.Add((v) => { recievedList.Add(v); counter++; }); var testData = Enumerable.Range(0, 10); helper.Add(testData); helper.Remove(testData.Where(_v => _v % 2 == 0)); Assert.AreEqual(testData.Count() / 2, counter); AssertionUtils.AssertEnumerableByUnordered( testData.Where(_v => _v % 2 == 0), recievedList, "" ); AssertionUtils.AssertEnumerableByUnordered( testData.Where(_v => _v % 2 != 0), helper.Items, "" ); }
public void RemoveItemsWhenOccurExceptionPasses() { var helper = new HashSetHelper <int>(); var recievedList = new List <int>(); var counter = 0; helper.OnRemoved.Add((v) => { if (v % 2 == 0) { throw new System.Exception(); } recievedList.Add(v); counter++; }); var testData = Enumerable.Range(0, 10); helper.Add(testData); Assert.DoesNotThrow(() => { helper.Remove(testData); }); Assert.AreEqual(testData.Count() / 2, counter); AssertionUtils.AssertEnumerableByUnordered( testData.Where(_v => _v % 2 != 0), recievedList, "" ); AssertionUtils.AssertEnumerableByUnordered( new int[] { }, helper.Items, "" ); }
public void RemoveWhenNullPasses() { var helper = new HashSetHelper <string>(); Assert.DoesNotThrow(() => { Assert.AreEqual(0, helper.Count); helper.Remove(default(string)); Assert.AreEqual(0, helper.Count); }); }
public void OnRemovedWhenNotContainsPasses() { var helper = new HashSetHelper <int>(); var counter = 0; var recievedValue = 0; helper.OnRemoved.Add((v) => { counter++; recievedValue = v; }); Assert.AreEqual(0, counter); helper.Remove(123); Assert.AreEqual(0, counter); Assert.AreEqual(0, recievedValue); }
public void RemoveItemsPasses() { var helper = new HashSetHelper <int>(); var testData = Enumerable.Range(0, 10); helper.Add(testData); helper.Remove(testData); AssertionUtils.AssertEnumerableByUnordered( new int[] { }, helper.Items, "" ); }
public void OnChangedCountInRemoveItemsNotRemovePasses() { var helper = new HashSetHelper <int>(); var isCall = false; helper.OnChangedCount.Add((_helper, _count) => { isCall = true; }); var testData = new int[] { 1, 2, 3 }; helper.Remove(testData); Assert.IsFalse(isCall); }
public void ContainsPasses() { var helper = new HashSetHelper <int>(); var value = 100; helper.Add(value); Assert.IsTrue(helper.Contains(value)); helper.Remove(value); Assert.IsFalse(helper.Contains(value)); helper.Add(value); Assert.IsTrue(helper.Contains(value)); }
public void OnChangedCountInRemoveNotRemovePasses() { var helper = new HashSetHelper <int>(); helper.Add(1, 2, 4); bool isCall = false; helper.OnChangedCount.Add((_helper, _count) => { isCall = true; }); helper.Remove(1000); Assert.IsFalse(isCall); }
public void OnRemovedInRemoveWhenOccurExceptionPasses() { var helper = new HashSetHelper <int>(); helper.OnRemoved.Add((v) => { throw new System.Exception(); }); var value = 100; helper.Add(value); Assert.DoesNotThrow(() => { helper.Remove(value); }); }
public void RemoveWhenNotContainsPasses() { var helper = new HashSetHelper <int>(); var testData = new int[] { 100, 200 }; foreach (var d in testData) { helper.Add(d); } helper.Remove(testData[0]); Assert.DoesNotThrow(() => { helper.Remove(testData[0]); Assert.IsFalse(helper.Contains(testData[0])); }); Assert.DoesNotThrow(() => { helper.Remove(-123); Assert.IsFalse(helper.Contains(-123)); }); }
public void OnChangedCountInRemoveWhenOccurExceptionPasses() { var helper = new HashSetHelper <int>(); var value = 1; helper.Add(value, 2, 3, 4); helper.OnChangedCount.Add((_helper, _count) => { throw new System.NotImplementedException(); }); helper.Remove(value); AssertionUtils.AssertEnumerableByUnordered( new int[] { 2, 3, 4 }, helper.Items, "" ); }
public void OnChangedCountInRemoveItemsWhenOccurExceptionPasses() { var helper = new HashSetHelper <int>(); var testData = new int[] { 1, 2, 3 }; helper.Add(testData); helper.OnChangedCount.Add((_helper, _count) => { throw new System.NotImplementedException(); }); helper.Remove(testData); AssertionUtils.AssertEnumerableByUnordered( new int[] { }, helper.Items, "" ); }
public void CountPasses() { var helper = new HashSetHelper <int>(); var testData = Enumerable.Range(0, 100); foreach (var d in testData) { helper.Add(d); } Assert.AreEqual(testData.Count(), helper.Count); var c = helper.Count; foreach (var d in testData) { helper.Remove(d); c--; Assert.AreEqual(c, helper.Count); } }
public void OnChangedCountInRemovePasses() { var helper = new HashSetHelper <int>(); var value = 100; helper.Add(value, 2, 4); var callCounter = 0; (IReadOnlyHashSetHelper <int> self, int count)recievedData = default; helper.OnChangedCount.Add((_helper, _count) => { callCounter++; recievedData.self = _helper; recievedData.count = _count; }); helper.Remove(value); Assert.AreEqual(1, callCounter); Assert.AreEqual(helper, recievedData.self); Assert.AreEqual(helper.Count, recievedData.count); }
public void OnChangedCountInRemoveItemsPasses() { var helper = new HashSetHelper <int>(); var testData = new int[] { 1, 2, 3 }; helper.Add(testData); var callCounter = 0; var recievedData = (self : (IReadOnlyHashSetHelper <int>)null, count : (int)0); helper.OnChangedCount.Add((_helper, _count) => { callCounter++; recievedData.self = _helper; recievedData.count = _count; }); helper.Remove(2, 3); Assert.AreEqual(1, callCounter); Assert.AreEqual(helper, recievedData.self); Assert.AreEqual(helper.Count, recievedData.count); }
public void OnChangedCountInRemoveWhenOccurOnRemovedExceptionPasses() { var helper = new HashSetHelper <int>(); var value = 1; helper.Add(value, 2, 3, 4); helper.OnRemoved.Add((_v) => { throw new System.NotImplementedException(); }); var isCallOnChangedCount = false; helper.OnChangedCount.Add((_, __) => isCallOnChangedCount = true);; helper.Remove(value); Assert.IsTrue(isCallOnChangedCount); AssertionUtils.AssertEnumerableByUnordered( new int[] { 2, 3, 4 }, helper.Items, "" ); }
public void OnChangedCountInRemoveItemsWhenOccurOnRemovedExceptionPasses() { var helper = new HashSetHelper <int>(); var value = 1; var testData = new int[] { 2, 3, 4 }; helper.Add(value).Add(testData); helper.OnRemoved.Add((_v) => { throw new System.NotImplementedException(); }); var callCounter = 0; helper.OnChangedCount.Add((_, __) => callCounter++); helper.Remove(testData); Assert.AreEqual(1, callCounter); AssertionUtils.AssertEnumerableByUnordered( new int[] { value }, helper.Items, "" ); }