public void reftype_equal() { //Arrange var tree1 = new nutility.Tree <string>(); var tree2 = new nutility.Tree <string>(); //Act tree1.Value = "2"; tree1.Add(new nutility.Tree <string> { Value = "1" }); tree1.Add(new nutility.Tree <string> { Value = "3" }); tree1.Add(new nutility.Tree <string> { Value = null }); tree2.Value = "2"; tree2.Add(new nutility.Tree <string> { Value = "1" }); tree2.Add(new nutility.Tree <string> { Value = "3" }); tree2.Add(new nutility.Tree <string> { Value = null }); //Assert Assert.AreEqual(tree1, tree2); }
public void nullable_equal() { //Arrange var tree1 = new nutility.Tree <int?>(); var tree2 = new nutility.Tree <int?>(); //Act tree1.Value = 2; tree1.Add(new nutility.Tree <int?> { Value = 1 }); tree1.Add(new nutility.Tree <int?> { Value = 3 }); tree1.Add(new nutility.Tree <int?> { Value = null }); tree2.Value = 2; tree2.Add(new nutility.Tree <int?> { Value = 1 }); tree2.Add(new nutility.Tree <int?> { Value = 3 }); tree2.Add(new nutility.Tree <int?> { Value = null }); //Assert Assert.AreEqual(tree1, tree2); }
public void valuetype_equal() { //Arrange var tree1 = new nutility.Tree <int>(); var tree2 = new nutility.Tree <int>(); //Act tree1.Value = 2; tree1.Add(new nutility.Tree <int> { Value = 1 }); tree1.Add(new nutility.Tree <int> { Value = 3 }); tree1.Add(new nutility.Tree <int> { Value = 0 }); tree2.Value = 2; tree2.Add(new nutility.Tree <int> { Value = 1 }); tree2.Add(new nutility.Tree <int> { Value = 3 }); tree2.Add(new nutility.Tree <int> { Value = 0 }); //Assert Assert.AreEqual(tree1, tree2); }
public void nullable_char_not_equal() { //Arrange var tree1 = new nutility.Tree <char?>(); var tree2 = new nutility.Tree <char?>(); //Act tree1.Value = '2'; tree1.Add(new nutility.Tree <char?> { Value = '1' }); tree1.Add(new nutility.Tree <char?> { Value = '3' }); tree1.Add(new nutility.Tree <char?> { Value = null }); tree2.Value = '2'; tree2.Add(new nutility.Tree <char?> { Value = '1' }); tree2.Add(new nutility.Tree <char?> { Value = '3' }); tree2.Add(new nutility.Tree <char?> { Value = '1' }); //Assert Assert.AreNotEqual(tree1.GetHashCode(), tree2.GetHashCode()); Assert.AreNotEqual(tree1, tree2); Assert.IsFalse(tree1.Equals(tree2)); }
public void valuetype_not_equal() { //Arrange var tree1 = new nutility.Tree <int>(); var tree2 = new nutility.Tree <int>(); //Act tree1.Value = 2; tree1.Add(new nutility.Tree <int> { Value = 1 }); tree1.Add(new nutility.Tree <int> { Value = 3 }); tree1.Add(new nutility.Tree <int> { Value = 0 }); tree2.Value = 2; tree2.Add(new nutility.Tree <int> { Value = 1 }); tree2.Add(new nutility.Tree <int> { Value = 3 }); tree2.Add(new nutility.Tree <int> { Value = 2 }); //Assert Assert.AreNotEqual(tree1, tree2); Assert.AreEqual("<tree value=\"2\">\r\n <tree value=\"1\" />\r\n <tree value=\"3\" />\r\n <tree value=\"0\" />\r\n</tree>", $"{tree1}"); Assert.AreEqual("<tree value=\"2\">\r\n <tree value=\"1\" />\r\n <tree value=\"3\" />\r\n <tree value=\"2\" />\r\n</tree>", $"{tree2}"); }
public void value_ref_equal() { //Arrange var tree1 = new nutility.Tree <int, string>(); var tree2 = new nutility.Tree <int, string>(); //Act tree1.Value = "R"; tree1[1] = new nutility.Tree <int, string> { Value = "2" }; tree1.Add(2, new nutility.Tree <int, string> { Value = "3" }); tree1[3] = new nutility.Tree <int, string> { Value = null }; tree2.Value = "R"; tree2.Add(1, new nutility.Tree <int, string> { Value = "2" }); tree2[2] = new nutility.Tree <int, string> { Value = "3" }; tree2[3] = new nutility.Tree <int, string> { Value = null }; //Assert Assert.AreEqual(tree1, tree2); }
public void ref_ref_equal() { //Arrange var tree1 = new nutility.Tree <string, string>(); var tree2 = new nutility.Tree <string, string>(); //Act tree1.Value = "R"; tree1["1"] = new nutility.Tree <string, string> { Value = "2" }; tree1.Add("2", new nutility.Tree <string, string> { Value = "3" }); tree1["3"] = new nutility.Tree <string, string> { Value = null }; tree2.Value = "R"; tree2.Add("1", new nutility.Tree <string, string> { Value = "2" }); tree2["2"] = new nutility.Tree <string, string> { Value = "3" }; tree2["3"] = new nutility.Tree <string, string> { Value = null }; //Assert Assert.AreEqual(tree1, tree2); }
public void valuetype_nullable_not_equal() { //Arrange var tree1 = new nutility.Tree <int, int?>(); var tree2 = new nutility.Tree <int, int?>(); //Act tree1.Value = 1; tree1[1] = new nutility.Tree <int, int?> { Value = 11 }; tree1.Add(2, new nutility.Tree <int, int?> { Value = 12 }); tree1[3] = new nutility.Tree <int, int?> { Value = null }; tree2.Value = 1; tree2.Add(1, new nutility.Tree <int, int?> { Value = 11 }); tree2[2] = new nutility.Tree <int, int?> { Value = 13 }; tree2[3] = new nutility.Tree <int, int?> { Value = null }; //Assert Assert.AreNotEqual(tree1, tree2); }
public void parent() { //Arrange var head = new nutility.Tree <int>(); head.Value = 1; head.Parent = null; head.Add(new nutility.Tree <int> { Value = 2, Parent = head }); var child2 = new nutility.Tree <int> { Value = 3, Parent = head }; head.Add(child2); //Act var parent = child2.Parent; //Assert Assert.AreSame(head, parent); }
public void serialized() { //Arrange var tree = new nutility.Tree <string> { Value = "2" }; tree.Add(new nutility.Tree <string> { Value = "1" }); tree.Add(new nutility.Tree <string> { Value = "3" }); string expected = "<tree value='2'><tree value='1' /><tree value='3' /></tree>"; var expected_result = System.Xml.Linq.XDocument.Parse(expected); //Act var actual_result = System.Xml.Linq.XDocument.Parse($"{tree}"); //Assert Assert.AreEqual($"{expected_result}", $"{actual_result}"); }
public void is_binary_tree() { //Arrange bool is_binary_tree(nutility.Tree <string> _tree) { bool _result = false; if (_tree != null) { _result = _tree.Count == 0 || _tree.Count == 2; var k = _tree.GetEnumerator(); while (_result == true && k.MoveNext()) { _result = is_binary_tree(k.Current); } } return(_result); } var tree = new nutility.Tree <string> { Value = "2" }; tree.Add(new nutility.Tree <string> { Value = "1" }); tree.Add(new nutility.Tree <string> { Value = "3" }); //Act var result = is_binary_tree(tree); //Assert Assert.IsTrue(result); }
public void serialized() { //Arrange var tree = new nutility.Tree <int, string>(); tree.Value = "R"; tree[1] = new nutility.Tree <int, string> { Value = "R1" }; tree.Add(2, new nutility.Tree <int, string> { Value = "R2" }); string expected = "<tree value='R'><tree key='1'><tree value='R1' /></tree><tree key='2'><tree value='R2' /></tree></tree>"; var expected_result = System.Xml.Linq.XDocument.Parse(expected); //Act var actual_result = System.Xml.Linq.XDocument.Parse($"{tree}"); //Assert Assert.AreEqual($"{expected_result}", $"{actual_result}"); }