示例#1
0
        public void Should_change_its_hashcode_everytime_the_set_is_updated()
        {
            var set = new SetByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var firstHashCode = set.GetHashCode();

            set.Add(Card.Parse("3H")); // ---update the set ---
            var afterAddHash = set.GetHashCode();

            Check.That(firstHashCode).IsNotEqualTo(afterAddHash);

            set.Clear();
            var afterClearHash = set.GetHashCode();

            Check.That(afterClearHash).IsNotEqualTo(afterAddHash);

            set.Add(Card.Parse("1C"));
            set.Add(Card.Parse("2C"));
            set.Add(Card.Parse("KD"));
            set.Add(Card.Parse("AC"));

            afterAddHash = set.GetHashCode();

            set.ExceptWith(new List <Card>()
            {
                Card.Parse("AC")
            });
            var afterExceptWithHash = set.GetHashCode();

            Check.That(afterExceptWithHash).IsNotEqualTo(afterAddHash);

            set.IntersectWith(new[] { Card.Parse("2C"), Card.Parse("1C") });
            var afterIntersectWithHash = set.GetHashCode();

            Check.That(afterIntersectWithHash).IsNotEqualTo(afterExceptWithHash);

            Check.That(set).ContainsExactly(Card.Parse("1C"), Card.Parse("2C"));
            set.Remove(Card.Parse("1C"));
            var afterRemoveHash = set.GetHashCode();

            Check.That(afterRemoveHash).IsNotEqualTo(afterIntersectWithHash);

            ((ISet <Card>)set).Add(Card.Parse("AD"));
            ((ISet <Card>)set).Add(Card.Parse("AS"));
            afterAddHash = set.GetHashCode();
            Check.That(afterAddHash).IsNotEqualTo(afterRemoveHash);

            set.UnionWith(new[] { Card.Parse("7H") });
            var afterUnionWithHash = set.GetHashCode();

            Check.That(afterUnionWithHash).IsNotEqualTo(afterAddHash);

            set.SymmetricExceptWith(new[] { Card.Parse("AD") });
            var afterSymetricExceptWithHash = set.GetHashCode();

            Check.That(afterSymetricExceptWithHash).IsNotEqualTo(afterUnionWithHash);
        }
示例#2
0
        public void Should_properly_expose_IsReadOnly()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            Check.That(byValueSet.IsReadOnly).IsEqualTo(((ICollection <Card>)originalSet).IsReadOnly);
        }
示例#3
0
        public void Should_properly_expose_SetEquals()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            Check.That(byValueSet.SetEquals(new[] { Card.Parse("QC") })).IsEqualTo(originalSet.SetEquals(new[] { Card.Parse("QC") }));
        }
        public void Properly_expose_IsSupersetOf()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            Check.That(byValueSet.IsSupersetOf(new[] { Card.Parse("QC") })).IsEqualTo(originalSet.IsSupersetOf(new[] { Card.Parse("QC") }));
        }
        public void Properly_expose_Count()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            Check.That(byValueSet.Count).IsEqualTo(originalSet.Count);
        }
示例#6
0
        public void Should_not_consider_a_classic_hashSet_and_a_HashSetByValue_Equals()
        {
            var set1 = new HashSet <string> {
                "Achille", "Anton", "Maxime"
            };
            var set2 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };

            Check.That(set2).IsNotEqualTo(set1);
        }
示例#7
0
        public void Should_consider_two_sets_with_same_items_in_different_order_equals()
        {
            var set1 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };
            var set2 = new SetByValue <string> {
                "Maxime", "Anton", "Achille"
            };

            Check.That(set2).IsEqualTo(set1);
        }
示例#8
0
        public void Should_provide_same_GetHashCode_from_two_sets_with_same_values_in_different_order()
        {
            var set1 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };
            var set2 = new SetByValue <string> {
                "Maxime", "Achille", "Anton"
            };

            Check.That(set2.GetHashCode()).IsEqualTo(set1.GetHashCode());
        }
示例#9
0
        public void Should_provide_different_GetHashCode_for_two_different_sets()
        {
            var set1 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };
            var set2 = new SetByValue <string> {
                "Hendrix", "De Lucia", "Reinhart"
            };

            Check.That(set2.GetHashCode()).IsNotEqualTo(set1.GetHashCode());
        }
        public void Provide_same_GetHashCode_from_two_sets_with_same_values()
        {
            var set1 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };
            var set2 = new SetByValue <string> {
                "Achille", "Anton", "Maxime"
            };

            Check.That(set2.GetHashCode()).IsEqualTo(set1.GetHashCode());
        }
示例#11
0
        public void Should_consider_an_instance_not_equals_with_SetByValue_instance()
        {
            var dico = new DictionaryByValue <int, string>(new Dictionary <int, string>()
            {
                { 1, "uno" }, { 4, "quatro" }, { 3, "tres" }
            });
            var set = new SetByValue <KeyValuePair <int, string> >()
            {
                new KeyValuePair <int, string>(1, "uno"), new KeyValuePair <int, string>(4, "quatro"), new KeyValuePair <int, string>(3, "tres")
            };

            Check.That(dico).IsNotEqualTo(set);
        }
        public void Consider_two_sets_of_the_same_integers_Equals()
        {
            var set1 = new SetByValue <int>()
            {
                1, 2, 3, 4, 5
            };
            var set2 = new SetByValue <int>()
            {
                1, 2, 3, 4, 5
            };

            Check.That(set2).IsEqualTo(set1);
        }
示例#13
0
        public void Should_properly_expose_CopyTo()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            var firstCards  = new Card[originalSet.Count];
            var secondCards = new Card[originalSet.Count];

            originalSet.CopyTo(firstCards, 0);
            byValueSet.CopyTo(secondCards, 0);

            Check.That(secondCards).ContainsExactly(firstCards);
        }