static void Main(string[] args) { var tree = CreateRandomTree(10, 10000); //var tree = CreateStaticTestTree(); Console.WriteLine("Printing Original Tree"); // PrintTree(tree); Console.WriteLine(); var serializer = new IdTreeSerializer(); var serialized = serializer.Serialize(tree); var deserialized = serializer.Deserialize(serialized); Console.WriteLine("Printing Tree After Serialization/Deserialization"); //PrintTree(deserialized); Console.WriteLine($"Trees are the same: {tree.Equals(deserialized)}"); Console.WriteLine($"Time with current serializer: {serializer.GetTime()}"); var oldSerializer = new OldSerializer(); var oldSerialized = oldSerializer.Serialize(tree); var oldDeserialized = oldSerializer.Deserialize(oldSerialized); Console.WriteLine($"Trees are the same: {tree.Equals(oldDeserialized)}"); Console.WriteLine($"Time with old serializer: {oldSerializer.GetTime()}"); Console.ReadLine(); }
public void CanSerializeWbsTree() { var bomberTree = BuildBomberTree(); var serializer = new IdTreeSerializer(); byte[] serializedBomber = serializer.Serialize(bomberTree); Assert.That(serializedBomber.Length, Is.EqualTo(84)); }
public void CanSerializeEmptyTree() { var idTree = new IdTree(); var serializer = new IdTreeSerializer(); byte[] serializedIdTree = serializer.Serialize(idTree); int deserializedId = BitConverter.ToInt32(serializedIdTree, 0); Assert.That(deserializedId, Is.EqualTo(IdNode.EmptyNodeId)); }
public void CanSerializeTreeWithSingleNodeWithNoParentAndNoChildren() { const int rootNodeId = 100; var rootNode = new IdNode(rootNodeId); var idTree = new IdTree(rootNode); var serializer = new IdTreeSerializer(); byte[] serializedIdTree = serializer.Serialize(idTree); int actualRootNodeId = BitConverter.ToInt32(serializedIdTree, 0); int actualParentNodeId = BitConverter.ToInt32(serializedIdTree, 4); Assert.That(actualRootNodeId, Is.EqualTo(rootNodeId)); Assert.That(actualParentNodeId, Is.EqualTo(IdNode.EmptyNodeId)); }
public void CanDeserializeWbsTree() { IdTree bomberTree = BuildBomberTree(); var serializer = new IdTreeSerializer(); byte[] serializedBomber = serializer.Serialize(bomberTree); IdTree deserializedBomberTree = serializer.DeSerialize(serializedBomber); Assert.IsNotNull(deserializedBomberTree.RootNode); IdNode bomber = deserializedBomberTree.RootNode; Assert.That(bomber.Id, Is.EqualTo(100)); IdNode fuselage = bomber.Children[0]; Assert.That(fuselage.Id, Is.EqualTo(200)); Assert.That(fuselage.Parent.Id, Is.EqualTo(100)); IdNode engineerFuselage = fuselage.Children[0]; Assert.That(engineerFuselage.Id, Is.EqualTo(300)); IdNode testFuselage = fuselage.Children[1]; Assert.That(testFuselage.Id, Is.EqualTo(400)); IdNode bombs = bomber.Children[1]; Assert.That(bombs.Id, Is.EqualTo(500)); IdNode engineerBombs = bombs.Children[0]; Assert.That(engineerBombs.Id, Is.EqualTo(600)); IdNode testBombs = bombs.Children[1]; Assert.That(testBombs.Id, Is.EqualTo(700)); }
public void CanSerializeTreeWithOneChild() { const int rootNodeId = 100; const int childNodeId = 200; var rootNode = new IdNode(rootNodeId); var childNode = new IdNode(childNodeId, rootNode); var idTree = new IdTree(rootNode); var serializer = new IdTreeSerializer(); byte[] serializedIdTree = serializer.Serialize(idTree); int actualRootNodeId = BitConverter.ToInt32(serializedIdTree, 0); int actualParentNodeId = BitConverter.ToInt32(serializedIdTree, 4); int actualChildCount = BitConverter.ToInt32(serializedIdTree, 8); int actualChildId = BitConverter.ToInt32(serializedIdTree, 12); Assert.That(actualRootNodeId, Is.EqualTo(rootNodeId)); Assert.That(actualParentNodeId, Is.EqualTo(IdNode.EmptyNodeId)); Assert.That(actualChildCount, Is.EqualTo(1)); Assert.That(actualChildId, Is.EqualTo(childNodeId)); }