public void SortedArrayKeyList_does_not_accept_null_entries()
        {
            var         b           = new CKSortedArrayKeyList <ClassToTest, string>(i => i.ToString(), false);
            ClassToTest classToTest = new ClassToTest("A");

            b.Add(classToTest);
            b.Add(new ClassToTest("B"));

            Assert.That(b.Contains(classToTest), Is.True);
            Assert.That(b.IndexOf(classToTest), Is.EqualTo(0));
            Assert.Throws <ArgumentNullException>(() => b.IndexOf((ClassToTest)null));
        }
Exemple #2
0
        private VirtualFileStorageDriver FindClosestDriver(string fullPath)
        {
            VirtualFileStorageDriver closestDriver;
            int idxDriver = _drivers.IndexOf(fullPath);

            Debug.Assert(idxDriver != 0, "Since fullPath is not empty and the 0 is the root: the dichotomic search can not have found the root.");
            if (idxDriver > 0)
            {
                // Pathological case: the path designates a container:
                // we redirect the action to its Parent.
                closestDriver = _drivers[idxDriver];
                closestDriver = closestDriver.Parent;
            }
            else
            {
                idxDriver = ~idxDriver;
                Debug.Assert(idxDriver > 0, "Since fullPath is not empty.");
                for ( ; ;)
                {
                    var d = _drivers[--idxDriver];
                    if (idxDriver == 0 || fullPath.StartsWith(d.RootPath, StringComparison.OrdinalIgnoreCase))
                    {
                        closestDriver = d;
                        break;
                    }
                }
            }
            return(closestDriver);
        }
        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 );
        }
Exemple #4
0
        public void SortedArrayKeyList_does_not_accept_null_entries()
        {
            var         b           = new CKSortedArrayKeyList <ClassToTest, string>(i => i.ToString(), false);
            ClassToTest classToTest = new ClassToTest("A");

            b.Add(classToTest);
            b.Add(new ClassToTest("B"));

            b.Contains(classToTest).Should().BeTrue();
            b.IndexOf(classToTest).Should().Be(0);
            b.Invoking(sut => sut.IndexOf((ClassToTest)null)).Should().Throw <ArgumentNullException>();
        }
        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);
        }
Exemple #6
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();
        }
        public void SortedArrayKeyList_does_not_accept_null_entries()
        {
            var b = new CKSortedArrayKeyList<ClassToTest, string>( i => i.ToString(), false );
            ClassToTest classToTest = new ClassToTest( "A" );

            b.Add( classToTest );
            b.Add( new ClassToTest( "B" ) );

            Assert.That( b.Contains( classToTest ), Is.True );
            Assert.That( b.IndexOf( classToTest ), Is.EqualTo( 0 ) );
            Assert.Throws<ArgumentNullException>( () => b.IndexOf( (ClassToTest)null ) );
        }