Exemple #1
0
        public void AddWhenContainsPasses()
        {
            var helper = new HashSetHelper <int>();
            var value  = 100;

            helper.Add(value);

            Assert.DoesNotThrow(() => {
                helper.Add(value);
            });
            Assert.IsTrue(helper.Contains(value));
            Assert.AreEqual(1, helper.Count);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        public void OnChangedCountInAddItemsNotAddPasses()
        {
            var helper   = new HashSetHelper <int>();
            var testData = new int[] { 1, 2, 3 };

            helper.Add(testData);
            var isCall = false;

            helper.OnChangedCount.Add((_helper, _count) => {
                isCall = true;
            });

            helper.Add(testData);
            Assert.IsFalse(isCall);
        }
Exemple #4
0
        public void AddItemsWhenOccurExceptionPasses()
        {
            var helper       = new HashSetHelper <int>();
            var recievedList = new List <int>();
            var counter      = 0;

            helper.OnAdded.Add((v) => {
                if (v % 2 == 0)
                {
                    throw new System.Exception();
                }
                recievedList.Add(v); counter++;
            });


            var testData = Enumerable.Range(0, 10);

            Assert.DoesNotThrow(() => {
                helper.Add(testData);
            });

            Assert.AreEqual(testData.Count() / 2, counter);
            AssertionUtils.AssertEnumerableByUnordered(
                testData.Where(_v => _v % 2 != 0),
                recievedList,
                ""
                );
            AssertionUtils.AssertEnumerableByUnordered(
                testData,
                helper.Items,
                ""
                );
        }
Exemple #5
0
        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
                , ""
                );
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public void AddPasses()
        {
            var helper = new HashSetHelper <int>();

            var value = 100;

            helper.Add(value);
            Assert.IsTrue(helper.Contains(value));
            Assert.AreEqual(1, helper.Count);

            var value2 = 101;

            helper.Add(value2);
            Assert.IsTrue(helper.Contains(value2));
            Assert.AreEqual(2, helper.Count);
        }
Exemple #8
0
        public void OnChangedCountInAddNotAddPasses()
        {
            var helper = new HashSetHelper <int>();
            var value  = 1;

            helper.Add(value);

            var isCall = false;

            helper.OnChangedCount.Add((_helper, _count) => {
                isCall = true;
            });

            helper.Add(value);
            Assert.IsFalse(isCall);
        }
Exemple #9
0
        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,
                ""
                );
        }
Exemple #10
0
        public void AddWhenNullPasses()
        {
            var helper = new HashSetHelper <string>();

            Assert.DoesNotThrow(() => {
                helper.Add(default(string));
            });
            Assert.AreEqual(0, helper.Count);
        }
Exemple #11
0
        public void OnChangedCountInAddItemsWhenOccurOnAddedExceptionPasses()
        {
            var helper = new HashSetHelper <int>();
            var value  = 1;

            helper.Add(value);
            helper.OnAdded.Add((_v) => {
                throw new System.NotImplementedException();
            });
            var callCounter = 0;

            helper.OnChangedCount.Add((_, __) => callCounter++);

            helper.Add(2, 3, 4);

            Assert.AreEqual(1, callCounter);
            AssertionUtils.AssertEnumerableByUnordered(
                new int[] { value, 2, 3, 4 },
                helper.Items,
                ""
                );
        }
Exemple #12
0
        public void OnAddedInAddWhenNotAddPasses()
        {
            var helper        = new HashSetHelper <string>();
            var counter       = 0;
            var recievedValue = "";

            helper.OnAdded.Add((v) => { recievedValue = v; counter++; });


            helper.Add(default(string));
            Assert.AreEqual("", recievedValue);
            Assert.AreEqual(0, counter);
        }
Exemple #13
0
        public void GetEnumeratorPasses()
        {
            var helper   = new HashSetHelper <int>();
            var testData = new int[] { 10, 20, 40 };

            helper.Add(testData);

            AssertionUtils.AssertEnumerableByUnordered(
                testData,
                helper,
                ""
                );
        }
Exemple #14
0
        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,
                ""
                );
        }
Exemple #15
0
        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);
            });
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        public void OnAddedInAddPasses()
        {
            var helper        = new HashSetHelper <int>();
            var counter       = 0;
            var recievedValue = 0;

            helper.OnAdded.Add((v) => { recievedValue = v; counter++; });


            var value = 100;

            helper.Add(value);
            Assert.AreEqual(value, recievedValue);
            Assert.AreEqual(1, counter);
        }
Exemple #18
0
        public void OnAddedInAddWhenOccurExceptionPasses()
        {
            var helper = new HashSetHelper <int>();

            helper.OnAdded.Add((v) => {
                throw new System.Exception();
            });

            Assert.DoesNotThrow(() => {
                int value = 100;
                helper.Add(value);
                Assert.IsTrue(helper.Contains(value));
                Assert.AreEqual(1, helper.Count);
            });
        }
Exemple #19
0
        public void OnChangedCountInAddItemsPasses()
        {
            var helper       = new HashSetHelper <int>();
            var recievedData = (self : (IReadOnlyHashSetHelper <int>)null, count : (int)0);

            helper.OnChangedCount.Add((_helper, _count) => {
                recievedData.self  = _helper;
                recievedData.count = _count;
            });

            var testData = new int[] { 1, 2, 3 };

            helper.Add(testData);
            Assert.AreEqual(helper, recievedData.self);
            Assert.AreEqual(helper.Count, recievedData.count);
        }
Exemple #20
0
        public void ClearPasses()
        {
            var helper = new HashSetHelper <int>();

            var testData = new int[] {
                0, 1, 2, 3, 4
            };

            foreach (var d in testData)
            {
                helper.Add(d);
            }

            helper.Clear();
            Assert.AreEqual(0, helper.Count);
        }
Exemple #21
0
        public void OnChangedCountInAddPasses()
        {
            var helper       = new HashSetHelper <int>();
            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.Add(1);
            Assert.AreEqual(1, callCounter);
            Assert.AreEqual(helper, recievedData.self);
            Assert.AreEqual(helper.Count, recievedData.count);
        }
Exemple #22
0
        public void OnChangedCountInClearWhenOccurExceptionPasses()
        {
            var helper = new HashSetHelper <int>();

            helper.Add(1, 2, 3);
            helper.OnChangedCount.Add((_helper, _count) => {
                throw new System.NotImplementedException();
            });

            helper.Clear();

            AssertionUtils.AssertEnumerableByUnordered(
                new int[] { },
                helper.Items,
                ""
                );
        }
Exemple #23
0
        public void OnChangedCountInAddItemsWhenOccurExceptionPasses()
        {
            var helper = new HashSetHelper <int>();

            helper.OnChangedCount.Add((_helper, _count) => {
                throw new System.NotImplementedException();
            });

            var testData = new int[] { 1, 2, 3 };

            helper.Add(testData);

            AssertionUtils.AssertEnumerableByUnordered(
                testData,
                helper.Items,
                ""
                );
        }
Exemple #24
0
        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,
                ""
                );
        }
Exemple #25
0
        public void OnClearedInClearPasses()
        {
            var helper  = new HashSetHelper <int>();
            var counter = 0;

            helper.OnCleared.Add(() => counter++);

            var testData = new int[] {
                0, 1, 2, 3, 4
            };

            foreach (var d in testData)
            {
                helper.Add(d);
            }

            helper.Clear();
            Assert.AreEqual(1, counter);
        }
Exemple #26
0
        public void OnAddedInAddItemsPasses()
        {
            var helper       = new HashSetHelper <int>();
            var recievedList = new List <int>();
            var counter      = 0;

            helper.OnAdded.Add((v) => { recievedList.Add(v); counter++; });


            var testData = Enumerable.Range(0, 10);

            helper.Add(testData);

            Assert.AreEqual(testData.Count(), counter);
            AssertionUtils.AssertEnumerableByUnordered(
                testData,
                recievedList,
                ""
                );
        }
Exemple #27
0
        public void ClearInClearWhenOccurExceptionPasses()
        {
            var helper = new HashSetHelper <int>();

            helper.OnCleared.Add(() => throw new System.Exception());

            var testData = new int[] {
                0, 1, 2, 3, 4
            };

            foreach (var d in testData)
            {
                helper.Add(d);
            }

            Assert.DoesNotThrow(() => {
                helper.Clear();
                Assert.AreEqual(0, helper.Count);
            });
        }
Exemple #28
0
        public void OnChangedCountInAddWhenOccurOnAddedExceptionPasses()
        {
            var helper = new HashSetHelper <int>();
            var isCallOnChangedCount = false;

            helper.OnAdded.Add((_v) => {
                throw new System.NotImplementedException();
            });
            helper.OnChangedCount.Add((_, __) => isCallOnChangedCount = true);;

            var value = 1;

            helper.Add(value);

            Assert.IsTrue(isCallOnChangedCount);
            AssertionUtils.AssertEnumerableByUnordered(
                new int[] { value },
                helper.Items,
                ""
                );
        }
Exemple #29
0
        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);
        }
Exemple #30
0
        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);
            }
        }