public void SortedArrayKeyList_can_allow_duplicates()
        {
            var a = new CKSortedArrayKeyList<int, string>( i => i.ToString() );

            a.AddRangeArray( 1, 10, 100, 100, 1000, 10000, 2, 20, 3, 30, 100, 46, 56 );
            CheckList( a, 1, 10, 100, 1000, 10000, 2, 20, 3, 30, 46, 56 );

            Assert.That( a.IndexOf( 1 ), Is.EqualTo( 0 ) );
            Assert.That( a.IndexOf( 2 ), Is.EqualTo( 5 ) );
            Assert.That( a.IndexOf( 3 ), Is.EqualTo( 7 ) );

            Assert.That( a.KeyCount( "100" ), Is.EqualTo( 1 ) );

            object o;
            o = "2";
            Assert.That( a.IndexOf( o ), Is.EqualTo( 5 ) );
            o = 2;
            Assert.That( a.IndexOf( o ), Is.EqualTo( 5 ) );
            o = null;
            Assert.That( a.IndexOf( o ), Is.EqualTo( Int32.MinValue ) );
            o = new ClassToTest( "A" );
            Assert.That( a.IndexOf( o ), Is.EqualTo( Int32.MinValue ) );
            o = "42";
            Assert.That( a.Contains( o ), Is.False );

            a.Remove( "10" );
            Assert.That( a.KeyCount( "10" ), Is.EqualTo( 0 ) );
            CheckList( a, 1, 100, 1000, 10000, 2, 20, 3, 30, 46, 56 );
            a.Remove( "20" );
            CheckList( a, 1, 100, 1000, 10000, 2, 3, 30, 46, 56 );
            a.Remove( "100" );
            Assert.That( a.KeyCount( "100" ), Is.EqualTo( 0 ) );
            CheckList( a, 1, 1000, 10000, 2, 3, 30, 46, 56 );
            Assert.That( a.Remove( "Nothing" ), Is.False );
        }
        public void SortedArrayKeyList_can_allow_duplicates()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => i.ToString());

            a.AddRangeArray(1, 10, 100, 100, 1000, 10000, 2, 20, 3, 30, 100, 46, 56);
            CheckList(a, 1, 10, 100, 1000, 10000, 2, 20, 3, 30, 46, 56);

            Assert.That(a.IndexOf(1), Is.EqualTo(0));
            Assert.That(a.IndexOf(2), Is.EqualTo(5));
            Assert.That(a.IndexOf(3), Is.EqualTo(7));

            Assert.That(a.KeyCount("100"), Is.EqualTo(1));

            object o;

            o = "2";
            Assert.That(a.IndexOf(o), Is.EqualTo(5));
            o = 2;
            Assert.That(a.IndexOf(o), Is.EqualTo(5));
            o = null;
            Assert.That(a.IndexOf(o), Is.EqualTo(Int32.MinValue));
            o = new ClassToTest("A");
            Assert.That(a.IndexOf(o), Is.EqualTo(Int32.MinValue));
            o = "42";
            Assert.That(a.Contains(o), Is.False);

            a.Remove("10");
            Assert.That(a.KeyCount("10"), Is.EqualTo(0));
            CheckList(a, 1, 100, 1000, 10000, 2, 20, 3, 30, 46, 56);
            a.Remove("20");
            CheckList(a, 1, 100, 1000, 10000, 2, 3, 30, 46, 56);
            a.Remove("100");
            Assert.That(a.KeyCount("100"), Is.EqualTo(0));
            CheckList(a, 1, 1000, 10000, 2, 3, 30, 46, 56);
            Assert.That(a.Remove("Nothing"), Is.False);
        }
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => (i % 100).ToString(), true);

            a.AddRangeArray(2, 1);

            bool exists;

            Assert.That(a.GetByKey("1", out exists) == 1 && exists);
            Assert.That(a.GetByKey("2", out exists) == 2 && exists);

            Assert.That(a.Add(102));
            Assert.That(a.Add(101));

            int v1 = a.GetByKey("1");

            Assert.That(v1, Is.EqualTo(1).Or.EqualTo(101), "It is one or the other that is returned.");
            int v2 = a.GetByKey("2");

            Assert.That(v2, Is.EqualTo(2).Or.EqualTo(102), "It is one or the other that is returned.");

            Assert.That(a.KeyCount("2") == 2);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102);

            Assert.That(a.Add(102));
            Assert.That(a.Add(102));
            Assert.That(a.Add(102));
            Assert.That(a.Add(202));
            Assert.That(a.Add(302));

            Assert.That(a.KeyCount("2") == 7);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102, 102, 102, 102, 202, 302);

            Assert.That(a.KeyCount("5454") == 0);
            Assert.That(a.GetAllByKey("5454"), Is.Empty);
        }
示例#4
0
        public void SortedArrayKeyList_can_allow_duplicates()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => i.ToString());

            a.AddRangeArray(1, 10, 100, 100, 1000, 10000, 2, 20, 3, 30, 100, 46, 56);
            CheckList(a, 1, 10, 100, 1000, 10000, 2, 20, 3, 30, 46, 56);

            a.IndexOf(1).Should().Be(0);
            a.IndexOf(2).Should().Be(5);
            a.IndexOf(3).Should().Be(7);

            a.KeyCount("100").Should().Be(1);

            object o;

            o = "2";
            a.IndexOf(o).Should().Be(5);
            o = 2;
            a.IndexOf(o).Should().Be(5);
            o = null;
            a.IndexOf(o).Should().Be(Int32.MinValue);
            o = new ClassToTest("A");
            a.IndexOf(o).Should().Be(Int32.MinValue);
            o = "42";
            a.Contains(o).Should().BeFalse();

            a.Remove("10");
            a.KeyCount("10").Should().Be(0);
            CheckList(a, 1, 100, 1000, 10000, 2, 20, 3, 30, 46, 56);
            a.Remove("20");
            CheckList(a, 1, 100, 1000, 10000, 2, 3, 30, 46, 56);
            a.Remove("100");
            a.KeyCount("100").Should().Be(0);
            CheckList(a, 1, 1000, 10000, 2, 3, 30, 46, 56);
            a.Remove("Nothing").Should().BeFalse();
        }
示例#5
0
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => (i % 100).ToString(), true);

            a.AddRangeArray(2, 1);

            bool exists;

            a.GetByKey("1", out exists).Should().Be(1); exists.Should().BeTrue();
            a.GetByKey("2", out exists).Should().Be(2); exists.Should().BeTrue();

            a.Add(102);
            a.Add(101);

            int v1 = a.GetByKey("1");

            v1.Should().BeOneOf(new[] { 1, 101 }, "It is one or the other that is returned.");
            int v2 = a.GetByKey("2");

            v2.Should().BeOneOf(new[] { 2, 102 }, "It is one or the other that is returned.");

            a.KeyCount("2").Should().Be(2);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102);

            a.Add(102);
            a.Add(102);
            a.Add(102);
            a.Add(202);
            a.Add(302);

            a.KeyCount("2").Should().Be(7);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102, 102, 102, 102, 202, 302);

            a.KeyCount("5454").Should().Be(0);
            a.GetAllByKey("5454").Should().BeEmpty();
        }
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList<int, string>( i => (i%100).ToString(), true );
            a.AddRangeArray( 2, 1 );

            bool exists;
            Assert.That( a.GetByKey( "1", out exists ) == 1 && exists );
            Assert.That( a.GetByKey( "2", out exists ) == 2 && exists );

            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 101 ) );
            
            int v1 = a.GetByKey( "1" );
            Assert.That( v1, Is.EqualTo( 1 ).Or.EqualTo( 101 ), "It is one or the other that is returned." );
            int v2 = a.GetByKey( "2" );
            Assert.That( v2, Is.EqualTo( 2 ).Or.EqualTo( 102 ), "It is one or the other that is returned." );

            Assert.That( a.KeyCount( "2" ) == 2 );
            CheckList( a.GetAllByKey( "2" ).OrderBy( Util.FuncIdentity ), 2, 102 );

            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 202 ) );
            Assert.That( a.Add( 302 ) );

            Assert.That( a.KeyCount( "2" ) == 7 );
            CheckList( a.GetAllByKey( "2" ).OrderBy( Util.FuncIdentity ), 2, 102, 102, 102, 102, 202, 302 );

            Assert.That( a.KeyCount( "5454" ) == 0 );
            Assert.That( a.GetAllByKey( "5454" ), Is.Empty );

        }