Esempio n. 1
0
        public void SortedArrayListSimpleTest()
        {
            var a = new CKSortedArrayList <int>();

            a.AddRangeArray(12, -34, 7, 545, 12);
            a.AllowDuplicates.Should().BeFalse();
            a.Count.Should().Be(4);
            a.Should().BeInAscendingOrder();

            a.Contains(14).Should().BeFalse();
            a.IndexOf(12).Should().Be(2);

            object o = 21;

            a.Contains(o).Should().BeFalse();
            a.IndexOf(o).Should().BeLessThan(0);

            o = 12;
            a.Contains(o).Should().BeTrue();
            a.IndexOf(o).Should().Be(2);

            o = null;
            a.Contains(o).Should().BeFalse();
            a.IndexOf(o).Should().Be(int.MinValue);

            int[] arrayToTest = new int[5];
            a.CopyTo(arrayToTest, 1);
            arrayToTest[0].Should().Be(0);
            arrayToTest[1].Should().Be(-34);
            arrayToTest[4].Should().Be(545);
        }
Esempio n. 2
0
        public void SortedArrayListSimpleTest()
        {
            var a = new CKSortedArrayList <int>();

            a.AddRangeArray(12, -34, 7, 545, 12);
            Assert.That(a.AllowDuplicates, Is.False);
            Assert.That(a.Count, Is.EqualTo(4));
            Assert.That(a, Is.Ordered);

            Assert.That(a.Contains(14), Is.False);
            Assert.That(a.IndexOf(12), Is.EqualTo(2));

            object o = 21;

            Assert.That(a.Contains(o), Is.False);
            Assert.That(a.IndexOf(o), Is.LessThan(0));

            o = 12;
            Assert.That(a.Contains(o), Is.True);
            Assert.That(a.IndexOf(o), Is.EqualTo(2));

            o = null;
            Assert.That(a.Contains(o), Is.False);
            Assert.That(a.IndexOf(o), Is.EqualTo(Int32.MinValue));

            int[] arrayToTest = new int[5];
            a.CopyTo(arrayToTest, 1);
            Assert.That(arrayToTest[0], Is.EqualTo(0));
            Assert.That(arrayToTest[1], Is.EqualTo(-34));
            Assert.That(arrayToTest[4], Is.EqualTo(545));
        }
Esempio n. 3
0
        public void SortedArrayListAllowDuplicatesTest()
        {
            var b = new CKSortedArrayList <int>(true);

            b.AddRangeArray(12, -34, 7, 545, 12);
            b.AllowDuplicates.Should().BeTrue();
            b.Count.Should().Be(5);
            b.Should().BeInAscendingOrder();
            b.IndexOf(12).Should().Be(2);
            b.CheckPosition(2).Should().Be(2);
            b.CheckPosition(3).Should().Be(3);
        }
Esempio n. 4
0
        public void SortedArrayListAllowDuplicatesTest()
        {
            var b = new CKSortedArrayList <int>(true);

            b.AddRangeArray(12, -34, 7, 545, 12);
            Assert.That(b.AllowDuplicates, Is.True);
            Assert.That(b.Count, Is.EqualTo(5));
            Assert.That(b, Is.Ordered);
            Assert.That(b.IndexOf(12), Is.EqualTo(2));
            Assert.That(b.CheckPosition(2), Is.EqualTo(2));
            Assert.That(b.CheckPosition(3), Is.EqualTo(3));
        }
Esempio n. 5
0
        public void testing_expected_Argument_InvalidOperation_and_IndexOutOfRangeException()
        {
            var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name));

            Assert.Throws <ArgumentNullException>(() => a.IndexOf(null));
            Assert.Throws <ArgumentNullException>(() => a.IndexOf <Mammal>(new Mammal("Nothing"), null));
            Assert.Throws <ArgumentNullException>(() => a.Add(null));

            a.Add(new Mammal("A"));
            a.Add(new Mammal("B"));

            Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[2]; });
            Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(2));
            Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[-1]; });
            Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(-1));

            //Enumerator Exception
            var enumerator = a.GetEnumerator();

            Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; });
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(a[0]));
            enumerator.Reset();
            Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; });
            a.Clear(); //change _version
            Assert.Throws <InvalidOperationException>(() => enumerator.Reset());
            Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());

            //Exception
            IList <Mammal> testException = new CKSortedArrayList <Mammal>();

            testException.Add(new Mammal("Nothing"));
            Assert.Throws <IndexOutOfRangeException>(() => testException[-1] = new Mammal("A"));
            Assert.Throws <IndexOutOfRangeException>(() => testException[1]  = new Mammal("A"));
            Assert.Throws <ArgumentNullException>(() => testException[0]     = null);
            Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(-1, new Mammal("A")));
            Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(2, new Mammal("A")));
            Assert.Throws <ArgumentNullException>(() => testException.Insert(0, null));
        }