Beispiel #1
0
        public void Add_OneElement_ShouldReturnWhenTravers()
        {
            var st = new SortedTree<int>();
            st.Add(3);

            CollectionAssert.AreEqual(new List<int> { 3 }, st.Traverse());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //SingleLinkedList<int> temp = new SingleLinkedList<int>();
            //for (int i = 0; i < 5; i++)
            //{
            //    temp.Add(i);
            //    Console.WriteLine(temp[i]);
            //}

            SortedTree<int> stree = new SortedTree<int>();
            stree.Add(20);
            stree.Add(8);
            stree.Add(12);
            stree.Add(9);
            stree.Add(14);
            stree.FindSpecialNode(10);
        }
        public void QueryChilds_ReturnsAllLayers()
        {
            // Arrange
            var sut = new SortedTree <int>(1);

            sut.Add(12).Add(122).Add(1222);
            sut.Add(13);
            sut.Add(11).Add(111).Add(1111);
            var expected = new List <int> {
                1, 11, 111, 1111, 12, 122, 1222, 13
            };

            // Act
            var result = sut.Select(x => x.Data).ToList();

            // Assert
            CollectionAssert.AreEqual(expected, result, $"{string.Join(",", expected.Select(x => x.ToString()))} => {string.Join(",", result.Select(x => x.ToString()))}");
        }
Beispiel #4
0
        public void Remove_AddThreeElementsRemoveOne_ShouldRemoveElement()
        {
            var st = new SortedTree<int>(true);
            st.Add(2);
            st.Add(4);
            st.Add(1);
            st.Remove(1);

            CollectionAssert.AreEqual(new List<int> { 2,4 }, st.Traverse());
        }
        public void TestCompressCases()
        {
            using (BinaryStream bs = new BinaryStream())
            {
                SortedTree <HistorianKey, HistorianValue> tree = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096, HistorianFileEncodingDefinition.TypeGuid);

                HistorianKey   key   = new HistorianKey();
                HistorianKey   key1  = new HistorianKey();
                HistorianValue value = new HistorianValue();

                key.Timestamp   = 0;
                key.PointID     = 0;
                key.EntryNumber = 0;

                value.Value1 = 0;
                value.Value2 = 0;
                value.Value3 = 0;

                tree.Add(key, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID = 1;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID  = 2;
                value.Value1 = 1;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(1ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID  = 3;
                value.Value1 = 561230651435234523ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID  = 35602353232;
                value.Value1 = 561230651435234523ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID++;
                value.Value1 = 561230651435234523ul;
                value.Value2 = 561230651435234524ul;
                value.Value3 = 561230651435234525ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(561230651435234524ul, value.Value2);
                Assert.AreEqual(561230651435234525ul, value.Value3);

                key.EntryNumber = 1;
                value.Value1    = 561230651435234523ul;
                value.Value2    = 561230651435234524ul;
                value.Value3    = 561230651435234525ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(561230651435234524ul, value.Value2);
                Assert.AreEqual(561230651435234525ul, value.Value3);

                key.PointID++;
                key.EntryNumber = 0;
                value.AsSingle  = 60.1f;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(60.1f, value.AsSingle);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID++;
                key.EntryNumber = 0;
                value.AsSingle  = -60.1f;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(-60.1f, value.AsSingle);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.Timestamp++;
                key.EntryNumber = 0;
                value.Value1    = 0;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);
            }
        }