public void TryInsertStringTest() { var bst = new DSWBalancedBinarySearchTree<string>(); var json = "{\"Value\":\"B\",\"LeftChild\":null,\"RightChild\":null}"; Assert.IsTrue(bst.TryInsert("B", out Node<string> node1)); Assert.IsFalse(bst.TryInsert("B", out Node<string> node3)); Assert.AreEqual(json, bst.GetJson()); Assert.IsTrue(bst.TryInsert("A", out Node<string> node2)); Assert.IsTrue(bst.TryInsert("C", out Node<string> node4)); var balanced = "{\"Value\":\"B\",\"LeftChild\":{\"Value\":\"A\",\"LeftChild\":null,\"RightChild\":null}," + "\"RightChild\":{\"Value\":\"C\",\"LeftChild\":null,\"RightChild\":null}}"; Assert.AreEqual(balanced, bst.GetJson()); }
public void TryInsertDoubleTest() { var bst = new DSWBalancedBinarySearchTree<double>(); var json = "{\"Value\":14.7,\"LeftChild\":null,\"RightChild\":null}"; Assert.IsTrue(bst.TryInsert(14.7, out Node<double> node1)); Assert.IsFalse(bst.TryInsert(14.7, out Node<double> node3)); Assert.AreEqual(json, bst.GetJson()); Assert.IsTrue(bst.TryInsert(2.7, out Node<double> node2)); Assert.IsTrue(bst.TryInsert(16.7, out Node<double> node4)); var balanced = "{\"Value\":14.7,\"LeftChild\":{\"Value\":2.7,\"LeftChild\":null,\"RightChild\":null}," + "\"RightChild\":{\"Value\":16.7,\"LeftChild\":null,\"RightChild\":null}}"; Assert.AreEqual(balanced, bst.GetJson()); }