示例#1
0
		public void NodeDecreaseLevel()
		{
			var rootNode = new ArneTreeNode<Int32, Int32>(100, 0);
			var aNode = new ArneTreeNode<Int32, Int32>(90, 4);
			var bNode = new ArneTreeNode<Int32, Int32>(20, 1);
			var cNode = new ArneTreeNode<Int32, Int32>(120, 3);
			var dNode = new ArneTreeNode<Int32, Int32>(10, 5);
			var eNode = new ArneTreeNode<Int32, Int32>(30, 3);

			// initialize
			rootNode.Left = aNode;
			aNode.Left = bNode;
			aNode.Right = cNode;
			bNode.Left = dNode;
			bNode.Right = eNode;

			// perform opeation

			Assert.AreEqual(dNode, dNode.DecraseLevel());
			Assert.AreEqual(eNode, eNode.DecraseLevel());

			aNode.DecraseLevel();

			Assert.AreEqual(2u, aNode.Level);
			Assert.AreEqual(2u, aNode.Right.Level);
		}
示例#2
0
		public void NodeSplit()
		{
			// prepare data
			var rootNode = new ArneTreeNode<Char, Char>('0', 0);
			var tNode = new ArneTreeNode<Char, Char>('T', 1);
			var rNode = new ArneTreeNode<Char, Char>('R', 1);
			var xNode = new ArneTreeNode<Char, Char>('X', 1);
			var aNode = new ArneTreeNode<Char, Char>('A', 2);
			var bNode = new ArneTreeNode<Char, Char>('B', 2);

			// initialize
			rootNode.Right = tNode;
			tNode.Left = aNode;
			tNode.Right = rNode;
			rNode.Left = bNode;
			rNode.Right = xNode;

			// perform operation
			Assert.AreEqual(xNode, xNode.Split());
			Assert.AreEqual(rNode, rNode.Split());
			Assert.AreEqual(rootNode, rootNode.Split());
			rootNode.Right = rootNode.Right.Split();

			// check results

			// references
			Assert.AreEqual(rNode, rootNode.Right);
			Assert.AreEqual(tNode, rNode.Left);
			Assert.AreEqual(xNode, rNode.Right);
			Assert.AreEqual(aNode, tNode.Left);
			Assert.AreEqual(bNode, tNode.Right);

			// levels
			Assert.AreEqual(0u, rootNode.Level);
			Assert.AreEqual(2u, rNode.Level);
			Assert.AreEqual(1u, tNode.Level);
			Assert.AreEqual(1u, xNode.Level);
			Assert.AreEqual(2u, aNode.Level);
			Assert.AreEqual(2u, bNode.Level);
		}
示例#3
0
		public void NodePredecessorAndSuccessor()
		{
			var rootNode = new ArneTreeNode<Int32, Int32>(100, 0);
			var aNode = new ArneTreeNode<Int32, Int32>(30, 1);
			var bNode = new ArneTreeNode<Int32, Int32>(60, 1);
			var cNode = new ArneTreeNode<Int32, Int32>(10, 2);
			var dNode = new ArneTreeNode<Int32, Int32>(20, 2);
			var eNode = new ArneTreeNode<Int32, Int32>(40, 2);
			var fNode = new ArneTreeNode<Int32, Int32>(50, 2);
			var gNode = new ArneTreeNode<Int32, Int32>(18, 3);
			var hNode = new ArneTreeNode<Int32, Int32>(42, 3);
			var iNode = new ArneTreeNode<Int32, Int32>(15, 3);
			var jNode = new ArneTreeNode<Int32, Int32>(45, 3);

			// initialize
			rootNode.Left = aNode;
			rootNode.Right = bNode;

			Assert.AreEqual(null, aNode.Predecessor);
			Assert.AreEqual(null, bNode.Successor);

			aNode.Left = cNode;
			aNode.Right = dNode;
			dNode.Left = gNode;
			gNode.Left = iNode;

			bNode.Left = eNode;
			bNode.Right = fNode;
			eNode.Right = hNode;
			hNode.Right = jNode;

			// perform operation

			Assert.AreEqual(dNode, rootNode.Predecessor);
			Assert.AreEqual(aNode, iNode.Predecessor);

			Assert.AreEqual(eNode, rootNode.Successor);
			Assert.AreEqual(bNode, jNode.Successor);
		}
示例#4
0
		public void NodeCtor()
		{
			// test data
			var expectedLeft = new ArneTreeNode<Int32, Int32>(0, 0);
			var expectedRight = new ArneTreeNode<Int32, Int32>(0, 0);

			const UInt32 ExpectedLevel = 777u;
			const Int32 ExpectdData = 100;

			// test object
			var root = new ArneTreeNode<Int32, Int32>(ExpectdData, ExpectedLevel, expectedLeft, expectedRight);

			// tests
			Assert.AreEqual(ExpectedLevel, root.Level);
			Assert.AreEqual(ExpectdData, root.Value);

			// Parent
			Assert.AreEqual(root, expectedLeft.Parent);
			Assert.AreEqual(root, expectedRight.Parent);

			// IsLeaf
			Assert.IsTrue(expectedLeft.IsLeaf);
			Assert.IsFalse(root.IsLeaf);

			// IsRoot
			Assert.IsFalse(expectedLeft.IsRoot);
			Assert.IsTrue(root.IsRoot);

			// left
			Assert.AreEqual(expectedLeft, root.Left);
			root.Left = null;
			Assert.IsNull(expectedLeft.Parent);

			// right
			Assert.AreEqual(expectedRight, root.Right);
			root.Right = null;
			Assert.IsNull(expectedRight.Parent);
		}