Exemplo n.º 1
0
        public void TestUpperAndLowerBound()
        {
            BList <int> blist = NewList();

            blist.AddRange(new int[] { 0, 0, 10, 10, 20, 20, 25, 30, 30, 40, 40, 50, 50 });

            int item = 25;

            Assert.AreEqual(blist.FindUpperBound(item), 1 + blist.FindLowerBound(item));

            item = 10;
            Assert.That(blist.FindUpperBound(ref item) == 4 && item == 20);
            item = 0;
            Assert.That(blist.FindUpperBound(ref item) == 2 && item == 10);
            item = 999;
            Assert.That(blist.FindUpperBound(ref item) == blist.Count && item == 999);

            bool found;

            item = 5;
            Assert.That(blist.FindLowerBound(ref item, out found) == 2 && item == 10 && !found);
            item = 20;
            Assert.That(blist.FindLowerBound(ref item, out found) == 4 && item == 20 && found);
            item = 0;
            Assert.That(blist.FindLowerBound(ref item, out found) == 0 && item == 0 && found);
            item = 999;
            Assert.That(blist.FindLowerBound(ref item, out found) == blist.Count && item == 999 && !found);
        }
Exemplo n.º 2
0
        public void TestRangeOperations()
        {
            BList <int> blist  = NewList();
            var         primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 23 };

            blist.AddRange(new int[] { });
            blist.AddRange(primes);
            blist.AddRange(new int[] { });
            ExpectList(blist, primes);

            Assert.AreEqual(4, blist.AddRange(new int[] { 9, 9, 29, 9 }));
            ExpectList(blist, 2, 3, 5, 7, 9, 9, 9, 11, 13, 17, 23, 29);

            Assert.AreEqual(2, blist.RemoveRange(new int[] { 9, 9 }));
            ExpectList(blist, 2, 3, 5, 7, 9, 11, 13, 17, 23, 29);

            Assert.AreEqual(2, blist.RemoveRange(new int[] { 9, 9, 29, 9 }));
            ExpectList(blist, 2, 3, 5, 7, 11, 13, 17, 23);
        }
Exemplo n.º 3
0
        public void AddRange_AppendsList()
        {
            var blist1 = new BList {
                "item1", "item2"
            };
            var blist2 = new BList {
                "item3", "item4"
            };

            blist1.AddRange(blist2);

            blist1.Should().HaveCount(4);
            blist1.Should().ContainInOrder((BString)"item1", (BString)"item2", (BString)"item3", (BString)"item4");
        }
Exemplo n.º 4
0
        public void given_blist_when_item_replaced_then_collectionchanged_raised()
        {
            var blist = new BList<int>();

            var index = 10;
            var initial = new int[32].Select(_ => _random.Next()).ToArray();
            var expectedNew = _random.Next();
            var expectedOld = initial[index];

            blist.AddRange(initial);

            NotifyCollectionChangedEventArgs args = null;
            blist.CollectionChanged += (_, a) => args = a;

            blist[index] = expectedNew;

            Assert.That(args, Is.Not.Null);
            Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Replace));
            Assert.That(args.NewStartingIndex, Is.EqualTo(10));
            Assert.That(args.OldStartingIndex, Is.EqualTo(10));
            Assert.That(args.NewItems[0], Is.EqualTo(expectedNew));
            Assert.That(args.OldItems[0], Is.EqualTo(expectedOld));
        }
Exemplo n.º 5
0
        public void given_blist_when_item_added_then_collectionchanged_raised()
        {
            var blist = new BList<int>();

            var initial = new int[32].Select(_ => _random.Next()).ToArray();
            var expected = _random.Next();

            blist.AddRange(initial);

            NotifyCollectionChangedEventArgs args = null;
            blist.CollectionChanged += (_, a) => args = a;

            blist.Insert(16, expected);

            Assert.That(args, Is.Not.Null);
            Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
            Assert.That(args.NewStartingIndex, Is.EqualTo(16));
            Assert.That(args.NewItems[0], Is.EqualTo(expected));
        }
Exemplo n.º 6
0
        public void given_blist_when_clear_is_called_then_collectionchanged_raised()
        {
            var blist = new BList<int>();

            blist.AddRange(new int[32].Select(_ => _random.Next()).ToArray());

            NotifyCollectionChangedEventArgs args = null;
            blist.CollectionChanged += (_, a) => args = a;

            blist.Clear();

            Assert.That(args, Is.Not.Null);
            Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Reset));
        }
Exemplo n.º 7
0
            given_existing_blist_when_multiple_elements_replaced_at_index_zero_then_blist_iteractor_should_return_elements
            ()
        {
            var initial = new int[256].Select(_ => _random.Next()).ToArray();
            var replace = new int[32].Select(_ => _random.Next()).ToArray();
            var expected = replace.Concat(initial.Skip(32)).ToArray();

            var blist = new BList<int>();

            blist.AddRange(initial);
            blist.ReplaceRange(replace, 0);

            CollectionAssert.AreEqual(expected, blist);
        }
Exemplo n.º 8
0
            given_existing_blist_when_multiple_elements_inserted_at_zero_then_blist_iteractor_should_return_elements()
        {
            var initial = new int[256].Select(_ => _random.Next()).ToArray();
            var expected = initial.Concat(initial).ToArray();

            var blist = new BList<int>();

            blist.AddRange(initial);
            blist.InsertRange(initial, 0);

            CollectionAssert.AreEqual(expected, blist);
        }
Exemplo n.º 9
0
        public void given_empty_blist_when_multiple_elements_added_then_blist_iteractor_should_return_elements()
        {
            var expected = new int[512].Select(_ => _random.Next()).ToArray();

            var blist = new BList<int>();

            blist.AddRange(expected);

            CollectionAssert.AreEqual(expected, blist);
        }