예제 #1
0
        public void DumbTest()
        {
            var node  = new CacheNode <int, int>(10, 10, 0, Comparer <int> .Default);
            int depth = 0;

            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
        }
예제 #2
0
 public void DumbTest()
 {
     
     var node = new CacheNode<int, int>(10, 10,0,  Comparer<int>.Default);
     int depth = 0;
     Assert.AreEqual(10, node.FindNode(10, 0, out depth));
     Assert.AreEqual(0, depth);
     Assert.AreEqual(0, node.FindNode(9, 0, out depth));
     Assert.AreEqual(0, node.FindNode(11, 0, out depth));
 }
예제 #3
0
 public void Add3Test()
 {
     var node = new CacheNode<int, int>(10, 10, 0, Comparer<int>.Default);
     node.AddNode(11, 11, 0, 0);
     node.AddNode(9, 9, 0, 0);
     int depth = 0;
     Assert.AreEqual(9, node.FindNode(9, 0, out depth));
     Assert.AreEqual(1, depth);          
     Assert.AreEqual(11, node.FindNode(11, 0, out depth));
     Assert.AreEqual(1, depth);
 }
예제 #4
0
        public void Add3Test()
        {
            var node = new CacheNode <int, int>(10, 10, 0, Comparer <int> .Default);

            node.AddNode(11, 11, 0, 0);
            node.AddNode(9, 9, 0, 0);
            int depth = 0;

            Assert.AreEqual(9, node.FindNode(9, 0, out depth));
            Assert.AreEqual(1, depth);
            Assert.AreEqual(11, node.FindNode(11, 0, out depth));
            Assert.AreEqual(1, depth);
        }
예제 #5
0
 public void AddWithCollectingTest()
 {
    
     var node = new CacheNode<int, int>(10, 10, 0, Comparer<int>.Default);
     node.AddNode(11, 11, 0, 0);
     node.AddNode(9, 9, 0, 0);
     int depth;
     Assert.AreEqual(9, node.FindNode(9, 0, out depth));
     Assert.AreEqual(1, depth);;
     Assert.AreEqual(11, node.FindNode(11, 0, out depth));
     Assert.AreEqual(1, depth);
     GC.Collect(2,GCCollectionMode.Forced);
     GC.Collect(2, GCCollectionMode.Forced);
     GC.Collect(2, GCCollectionMode.Forced);
     GC.WaitForPendingFinalizers();
     Assert.AreEqual(0, node.FindNode(9, 0, out depth));
     Assert.AreEqual(0, node.FindNode(11, 0, out depth));
 }
예제 #6
0
        public void AddWithCollectingTest()
        {
            var node = new CacheNode <int, int>(10, 10, 0, Comparer <int> .Default);

            node.AddNode(11, 11, 0, 0);
            node.AddNode(9, 9, 0, 0);
            int depth;

            Assert.AreEqual(9, node.FindNode(9, 0, out depth));
            Assert.AreEqual(1, depth);;
            Assert.AreEqual(11, node.FindNode(11, 0, out depth));
            Assert.AreEqual(1, depth);
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
        }
예제 #7
0
        public void DeepAddWithCollectingWithNonZeroFixedBranchLengthTest()
        {
            var node = new CacheNode <int, int>(10, 10, 1, Comparer <int> .Default);

            #region Prepare
            node.AddNode(8, 8, 1, 0);
            node.AddNode(7, 7, 1, 0);
            node.AddNode(9, 9, 1, 0);
            node.AddNode(12, 12, 1, 0);
            node.AddNode(11, 11, 1, 0);
            node.AddNode(13, 13, 1, 0);
            int depth = 0;
            Assert.AreEqual(7, node.FindNode(7, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(9, node.FindNode(9, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            depth = 0;
            Assert.AreEqual(11, node.FindNode(11, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(13, node.FindNode(13, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            #endregion

            #region First collection
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();
            Assert.AreEqual(0, node.FindNode(7, 0, out depth));
            depth = 0;
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
            depth = 0;
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(13, 0, out depth));
            #endregion

            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();
            Assert.AreEqual(0, node.FindNode(7, 0, out depth));
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(0, node.FindNode(13, 0, out depth));
        }
예제 #8
0
        public void DeepAddWithCollectingWithNonZeroFixedBranchLengthTest()
        {

            var node = new CacheNode<int, int>(10, 10,1, Comparer<int>.Default);
            #region Prepare
            node.AddNode(8, 8, 1, 0);
            node.AddNode(7, 7, 1, 0);
            node.AddNode(9, 9, 1, 0);
            node.AddNode(12, 12, 1, 0);
            node.AddNode(11, 11, 1, 0);
            node.AddNode(13, 13, 1, 0);
            int depth = 0;
            Assert.AreEqual(7, node.FindNode(7, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(9, node.FindNode(9, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            depth = 0;
            Assert.AreEqual(11, node.FindNode(11, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(13, node.FindNode(13, 0, out depth));
            Assert.AreEqual(2, depth);
            depth = 0;
            #endregion

            #region First collection
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();
            Assert.AreEqual(0, node.FindNode(7, 0, out depth));
            depth = 0;
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
            depth = 0;
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(1, depth);
            depth = 0;
            Assert.AreEqual(0, node.FindNode(13, 0, out depth));
            #endregion

            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();
            Assert.AreEqual(0, node.FindNode(7, 0, out depth));
            Assert.AreEqual(8, node.FindNode(8, 0, out depth));
            Assert.AreEqual(0, node.FindNode(9, 0, out depth));
            depth = 0;
            Assert.AreEqual(10, node.FindNode(10, 0, out depth));
            Assert.AreEqual(0, depth);
            Assert.AreEqual(0, node.FindNode(11, 0, out depth));
            Assert.AreEqual(12, node.FindNode(12, 0, out depth));
            Assert.AreEqual(0, node.FindNode(13, 0, out depth));
        }