Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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}");
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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}");
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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}");
        }