Exemplo n.º 1
0
        public void Should_properly_expose_indexer()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            Check.That(list[0]).IsEqualTo(Card.Parse("QC"));
            Check.That(list[1]).IsEqualTo(Card.Parse("TS"));
        }
Exemplo n.º 2
0
        public void Should_properly_expose_IndexOf()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            Check.That(list.IndexOf(Card.Parse("QC"))).IsEqualTo(0);
            Check.That(list.IndexOf(Card.Parse("TS"))).IsEqualTo(1);
        }
Exemplo n.º 3
0
        public void Should_properly_expose_Contains()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            Check.That(list.Contains(Card.Parse("TS"))).IsTrue();
            Check.That(list.Contains(Card.Parse("4D"))).IsFalse();
        }
Exemplo n.º 4
0
        public void Should_properly_expose_IsReadOnly()
        {
            var originalList = new List <int>()
            {
                0, 1, 2
            };
            var listByValue = new ListByValue <int>(originalList);

            ICollection <int> original = originalList;

            Check.That(listByValue.IsReadOnly).IsEqualTo(original.IsReadOnly);
        }
Exemplo n.º 5
0
        public void Should_properly_expose_IEnumerable()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            foreach (var card in list)
            {
                Check.That(card == Card.Parse("QC") || card == Card.Parse("TS")).IsTrue();
            }
        }
Exemplo n.º 6
0
        public void Should_properly_expose_CopyTo()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var cards = new Card[5];

            list.CopyTo(cards, 2);

            Check.That(cards).ContainsExactly(null, null, Card.Parse("QC"), Card.Parse("TS"), null);
        }
Exemplo n.º 7
0
        public void Should_properly_expose_Count()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            Check.That(list.Count).IsEqualTo(2);

            list.Add(Card.Parse("4D"));
            Check.That(list.Count).IsEqualTo(3);
        }
Exemplo n.º 8
0
        public void Should_consider_Equals_two_instances_with_same_ValueType_elements_in_same_order()
        {
            var listA = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var listB = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            Check.That(listA).IsEqualTo(listB).And.ContainsExactly(Card.Parse("QC"), Card.Parse("TS"));
        }
Exemplo n.º 9
0
        public void Should_consider_Equals_two_instances_with_same_reference_types_elements_in_same_order()
        {
            var firstElement  = new object();
            var secondElement = new object();

            var listA = new ListByValue <object>()
            {
                firstElement, secondElement
            };
            var listB = new ListByValue <object>()
            {
                firstElement, secondElement
            };

            Check.That(listA).IsEqualTo(listB).And.ContainsExactly(firstElement, secondElement);
        }
Exemplo n.º 10
0
        public void Consider_two_Lists_of_the_same_integers_Equals()
        {
            var listA = new List <int>()
            {
                1, 2, 3, 4, 5
            };
            var listB = new List <int>()
            {
                1, 2, 3, 4, 5
            };

            var listByValueA = new ListByValue <int>(listA);
            var listByValueB = new ListByValue <int>(listB);

            Check.That(listByValueB).IsEqualTo(listByValueA);
        }
Exemplo n.º 11
0
        public void Consider_Not_Equals_two_instances_with_same_elements_in_different_order()
        {
            var firstElement  = new object();
            var secondElement = new object();

            var listA = new ListByValue <object>()
            {
                firstElement, secondElement
            };
            var listB = new ListByValue <object>()
            {
                secondElement, firstElement
            };

            Check.That(listB).IsNotEqualTo(listA).And.ContainsExactly(secondElement, firstElement);
        }
Exemplo n.º 12
0
        public void Should_change_its_hashcode_everytime_the_list_is_updated()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };

            var previousHashcode = list.GetHashCode();

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

            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);


            previousHashcode = list.GetHashCode();
            list.Remove(Card.Parse("QC")); // ---update the list ---
            currentHashcode = list.GetHashCode();
            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);

            previousHashcode = list.GetHashCode();
            list.Clear(); // ---update the list ---
            currentHashcode = list.GetHashCode();
            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);

            previousHashcode = list.GetHashCode();
            list.Insert(0, Card.Parse("AS")); // ---update the list ---
            currentHashcode = list.GetHashCode();
            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);

            previousHashcode = list.GetHashCode();
            list[0]          = Card.Parse("QH");
            currentHashcode  = list.GetHashCode();
            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);

            previousHashcode = list.GetHashCode();
            list.RemoveAt(0);
            currentHashcode = list.GetHashCode();
            Check.That(currentHashcode).IsNotEqualTo(previousHashcode);
        }
Exemplo n.º 13
0
        public void Should_change_its_hashcode_everytime_the_list_is_updated()
        {
            var list = new ListByValue <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var firstHashCode = list.GetHashCode();

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

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

            list.Remove(Card.Parse("QC")); // ---update the list ---
            var afterRemoveHash = list.GetHashCode();

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

            list.Clear(); // ---update the list ---
            var afterClearHash = list.GetHashCode();

            Check.That(afterClearHash).IsNotEqualTo(afterRemoveHash);
            Check.That(list.Count).IsZero();

            list.Insert(0, Card.Parse("AS")); // ---update the list ---
            Check.That(list.Count).IsEqualTo(1);
            var afterInsertHash = list.GetHashCode();

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

            list[0] = Card.Parse("QH");
            var afterIndexerHash = list.GetHashCode();

            Check.That(afterIndexerHash).IsNotEqualTo(afterInsertHash);

            list.RemoveAt(0);
            var afterRemoveAtHash = list.GetHashCode();

            Check.That(afterRemoveAtHash).IsNotEqualTo(afterIndexerHash);
        }