예제 #1
0
        public void RangeTest()
        {
            //Arrange
            var bst = new BinarySearchTree<int, string>();
            var testData = new[]
            {
                new KeyValuePair<int, string>(5, "A"),
                new KeyValuePair<int, string>(3, "B"),
                new KeyValuePair<int, string>(6, "C"),
                new KeyValuePair<int, string>(2, "D"),
                new KeyValuePair<int, string>(7, "E"),
                new KeyValuePair<int, string>(4, "F"),
            };

            //Act
            testData.All(t =>
            {
                bst.Add(t.Key, t.Value);
                return true;
            });
            var resultList = bst.Range(4, 7).ToList();

            //Assert
            Assert.AreEqual(resultList.Count, 4);

            Assert.AreEqual(resultList[0].Key, 4);
            Assert.AreEqual(resultList[1].Key, 5);
            Assert.AreEqual(resultList[2].Key, 6);
            Assert.AreEqual(resultList[3].Key, 7);
        }