상속: IEquatable
예제 #1
0
        public void AddTest()
        {
            // ARRANGE
            var set = new CustomSet <int>();

            // ACT
            set.Add(1);

            // ASSERT
            Assert.AreEqual(1, set.Count);
        }
예제 #2
0
        public void CustomSet_TestForAdd(List <string> expectedValue, params string[] values)
        {
            var actual = new CustomSet <string>();

            foreach (var value in values)
            {
                actual.Add(value);
            }

            Assert.AreEqual(expectedValue, new List <string>(actual));
        }
예제 #3
0
    public bool Disjoint(CustomSet right)
    {
        if (this.hash.Count == 0)
        {
            return(true);
        }
        HashSet <int> tmp = new HashSet <int>(this.hash);

        tmp.IntersectWith(right.Hash);
        return(tmp.Count == 0 ? true : false);
    }
예제 #4
0
        public void Add_NormalConditions_Test()
        {
            CustomSet <string> testSet     = new CustomSet <string>();
            CustomSet <string> expectedSet = new CustomSet <string> {
                "Test", "Test2"
            };

            testSet.Add("Test");
            testSet.Add("Test");
            testSet.Add("Test2");
            CollectionAssert.AreEqual(testSet, expectedSet);
        }
예제 #5
0
        public bool TestUploadToFileDownload(CustomSet <Book> booksUp)
        {
            Logger.Logger   logger        = new Logger.Logger();
            BooksXmlStorage storage       = new BooksXmlStorage(logger, @"C:\Users\Polina\Documents\git\Net.W.2016.01.Freydlina.12\Net.W.2016.01.Freydlina.12\Net.W.2016.01.Freydlina.12\test2.xml");
            BookListService serviceToSave = new BookListService(booksUp, logger);

            serviceToSave.SaveTo(storage);
            BookListService serviceToOpen = new BookListService(logger);

            serviceToOpen.OpenFrom(storage);
            return(serviceToSave.Equals(serviceToOpen));
        }
예제 #6
0
        public void Subset_NormalCOnditions_Test()
        {
            CustomSet <string> testSet = new CustomSet <string> {
                "Test", "Test3", "Test4", "Test5"
            };
            CustomSet <string> subSet = new CustomSet <string> {
                "Test3", "Test4",
            };
            var result = subSet.SubsetWith(testSet);

            Assert.That(result, Is.EqualTo(true));
        }
예제 #7
0
        public void RemoveTest()
        {
            // ARRANGE
            var set = new CustomSet <int>();

            set.Add(1);

            // ACT
            set.Remove(1);

            // ASSERT
            Assert.AreEqual(0, set.Count);
        }
예제 #8
0
        private static void CreateBookService()
        {
            CustomSet <Book> books = new CustomSet <Book>(3)
            {
                new Book("Announcing.NET Framework 4.6.2", "Microsoft", 2016, "Haffner, Stacey"),
                new Book(".NET Core - .NET Goes Cross - Platform with.NET Core", "Microsoft", 2016,
                         "Carter, Phillip", "Knezevic, Zlatko"),
                new Book("Understanding .NET Just-In-Time Compilation", "Telerik")
            };

            service = new BookListService(books, logger);
            Console.WriteLine(service.PrintBooks());
        }
예제 #9
0
        public void CustomQueue_TestForCopyTo(params string[] expectedResult)
        {
            var set = new CustomSet <string>(expectedResult.ToList());

            var actual = new string[set.Count];

            Console.WriteLine(string.Join(" ", set));

            set.CopyTo(actual, 0);

            Console.WriteLine(string.Join(" ", actual.ToList()));

            Assert.AreEqual(expectedResult, actual);
        }
예제 #10
0
    public CustomSet Difference(CustomSet right)
    {
        CustomSet     res  = this.Intersection(right);
        HashSet <int> res1 = new HashSet <int>();

        foreach (int val in this.hash)
        {
            if (!right.Contains(val))
            {
                res1.Add(val);
            }
        }
        return(new CustomSet(res1));
    }
예제 #11
0
        public void Intersection_NormalConditions_Test()
        {
            CustomSet <string> testSet = new CustomSet <string> {
                "Test", "Test3", "Test4"
            };
            CustomSet <string> intersectionSet = new CustomSet <string> {
                "Test3", "Test4"
            };
            CustomSet <string> expectedSet = new CustomSet <string> {
                "Test3", "Test4"
            };

            testSet.IntersectionWith(intersectionSet);
            CollectionAssert.AreEqual(testSet, expectedSet);
        }
예제 #12
0
        public void Difference_NormalConditions_Test()
        {
            CustomSet <string> testSet = new CustomSet <string> {
                "Test", "Test3", "Test4", "Test5"
            };
            CustomSet <string> differenceSet = new CustomSet <string> {
                "Test3", "Test4",
            };
            CustomSet <string> expectedSet = new CustomSet <string> {
                "Test", "Test5"
            };

            testSet.DifferenceWith(differenceSet);
            CollectionAssert.AreEqual(testSet, expectedSet);
        }
예제 #13
0
    public CustomSet Intersection(CustomSet right)
    {
        System.Collections.Generic.List <int> comValues = new  System.Collections.Generic.List <int>();
        foreach (int i in right.values)
        {
            foreach (int j in this.values)
            {
                if (i == j)
                {
                    comValues.Add(i);
                }
            }
        }

        return(new CustomSet(comValues.ToArray()));
    }
예제 #14
0
        public void CustomQueue_TestForCustomEqualityComparer(int[] values, int expectedResult)
        {
            var list = new List <CustomQueue <int> > ();

            while (list.Count != 5)
            {
                var queue = new CustomQueue <int>(5);
                foreach (var value in values)
                {
                    queue.Enqueue(value);
                }
                list.Add(queue);
            }

            var set = new CustomSet <CustomQueue <int> >(list, new CustomQueueEqualityComparerByValues <int>());

            Assert.AreEqual(1, set.Count);
        }
예제 #15
0
    public CustomSet Union(CustomSet right)
    {
        if (this.values.Length == 0 && right.values.Length == 0)
        {
            return(new CustomSet());
        }
        else if (this.values.Length == 0)
        {
            return(right);
        }
        else if (right.values.Length == 0)
        {
            return(this);
        }
        CustomSet retVal = new CustomSet(this.values);

        foreach (int i in right.values)
        {
            retVal = retVal.Add(i);
        }
        return(retVal);
    }
예제 #16
0
    public bool Disjoint(CustomSet right)
    {
        if (this.values.Length == 0)
        {
            return(true);
        }
        if (right.values.Length == 0 && this.values.Length != 0)
        {
            return(true);
        }

        foreach (int i in right.values)
        {
            foreach (int j in this.values)
            {
                if (j == i)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
예제 #17
0
    public CustomSet Difference(CustomSet right)
    {
        if (right.values.Length == 0)
        {
            return(new CustomSet(this.values));
        }
        if (this.values.Length == 0)
        {
            return(new CustomSet());
        }

        CustomSet tmpSet = this.Intersection(right);
        CustomSet retVal = new CustomSet();

        foreach (int i in this.values)
        {
            if (Array.IndexOf(tmpSet.values, i) == -1)
            {
                retVal = retVal.Add(i);
            }
        }
        return(retVal);
    }
예제 #18
0
    public override bool Equals(object obj)
    {
        CustomSet tmpSet = (CustomSet)obj;

        if (tmpSet.values.Length != this.values.Length)
        {
            return(false);
        }
        if (tmpSet.values.Length == 0 && this.values.Length == 0)
        {
            return(true);
        }
        Array left = Array.CreateInstance(typeof(int), this.values.Length);

        for (int i = 0; i < this.values.Length; i++)
        {
            left.SetValue(this.values[i], i);
        }
        Array.Sort(left);
        Array right = Array.CreateInstance(typeof(int), tmpSet.values.Length);

        for (int i = 0; i < tmpSet.values.Length; i++)
        {
            right.SetValue(tmpSet.values[i], i);
        }
        Array.Sort(right);

        for (int i = 0; i < this.values.Length; i++)
        {
            if (!left.GetValue(i).Equals(right.GetValue(i)))
            {
                return(false);
            }
        }
        return(true);
    }
예제 #19
0
 public bool IsDisjointFrom(CustomSet <T> right) => !items.Keys.Any(key => right.items.ContainsKey(key));
예제 #20
0
 public bool IsSubsetOf(CustomSet <T> right) => items.Keys.All(key => right.items.ContainsKey(key));
예제 #21
0
 public CustomSet Union(CustomSet right)
 {
     return(new CustomSet(items.Values.Concat(right.items.Values).ToArray()));
 }
예제 #22
0
 public bool Disjoint(CustomSet right) => !items.Keys.Any(key => right.items.ContainsKey(key));
예제 #23
0
 public bool Subset(CustomSet right) => items.Keys.All(key => right.items.ContainsKey(key));
예제 #24
0
    public void Sets_with_no_elements_are_empty()
    {
        var actual = new CustomSet <int>();

        Assert.True(actual.IsEmpty());
    }
예제 #25
0
    public void Sets_with_elements_are_not_empty()
    {
        var sut = new CustomSet(new[] { 1 });

        Assert.False(sut.Empty());
    }
예제 #26
0
    public CustomSet <T> Intersection(CustomSet <T> right)
    {
        var intersectionKeys = items.Keys.Intersect(right.items.Keys);

        return(new CustomSet <T>(GetValuesFromKeys(intersectionKeys)));
    }
예제 #27
0
    public CustomSet <T> Difference(CustomSet <T> right)
    {
        var differenceKeys = items.Keys.Except(right.items.Keys);

        return(new CustomSet <T>(GetValuesFromKeys(differenceKeys)));
    }
예제 #28
0
    public void Nothing_is_contained_in_an_empty_set()
    {
        var actual = new CustomSet <int>();

        Assert.False(actual.Contains(1));
    }
예제 #29
0
    public void Sets_with_no_elements_are_empty()
    {
        var sut = new CustomSet();

        Assert.True(sut.Empty());
    }
예제 #30
0
    public void Detect_if_the_element_is_not_in_the_set()
    {
        var actual = new CustomSet <int>(new[] { 1, 2, 3 });

        Assert.False(actual.Contains(4));
    }