private void PrintTree(Node root, int tab = 0) { foreach (var item in root.Reverse()) { for (int i = 0; i < tab; i++) Console.Out.Write('\t'); Console.Out.WriteLine(item); PrintTree(item, tab + 1); } }
private void DoTree(Node<ICommandType> tree, Action<ICommandType> action, int parameters) { if (tree == null) return; tree.Value.Input = parameters; action(tree.Value); try { Task.WaitAll(tree.Neighbors.Select(node => Task.Factory.StartNew(() => DoTree(node, action, tree.Value.Input))).ToArray()); } catch (Exception ex) { } }
public void CanSetMergeAndGetValue() { dynamic bobs = new Node(); bobs.Recipe.Eggs.Count = 5; bobs.Commit(); dynamic alices = bobs.Clone(); alices.Recipe.Butter.Amount = 4; alices.Recipe.Eggs.Count = 3; alices.Commit(); bobs.Recipe.Salt.Amount = 7; bobs.Commit(); bobs.Pull(alices); }
public void TestUpdate() { var manager = new FileCacheManager("cache"); var root = GetRadomString(); var node1 = new Node {Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()}; manager.AddOrUpdate(node1, root); node1.Name = GetRadomString(); manager.AddOrUpdate(node1, root); var id = manager.GetIdByNameAndParent(node1.Name, root); Assert.AreEqual(node1.Id, id); //cleanup File.Delete("cache"); }
public void TestRead() { var manager = new FileCacheManager("cache"); var root = GetRadomString(); var node1 = new Node {Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()}; var node2 = new Node {Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()}; var child = new Node {Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()}; manager.AddOrUpdate(node1, root); manager.AddOrUpdate(node2, root); manager.AddOrUpdate(child, node1.Id); var fromCache = manager.GetIdByNameAndParent(child.Name, node1.Id); Assert.AreEqual(child.Id, fromCache); //cleanup File.Delete("cache"); }
public void TestNodeCommands() { Node<ICommandType> parentCommand = new Node<ICommandType>(new PlusOneCommand { Name = "Command1", Input = 10, }); var childCommand3 = new Node<ICommandType>(new PlusTwoCommand { Name = "ChildCOmmand3" });//13 var chidlCommand = new Node<ICommandType>(new PlusOneCommand { Name = "ChildCommand1"});//12 childCommand3.Neighbors.Add(new Node<ICommandType>(new PlusTwoCommand { Name = "ChildCOmmand5" }));//15 chidlCommand.Neighbors.Add(new Node<ICommandType>(new PlusOneCommand { Name = "ChildCOmmand2"}));//12 chidlCommand.Neighbors.Add(new Node<ICommandType>(new PlusOneCommand { Name = "ChildCOmmand4" }));//12 chidlCommand.Neighbors.Add(childCommand3); parentCommand.Neighbors.Add(chidlCommand); parentCommand.Value.Execute();//11 Parallel.ForEach(parentCommand.Neighbors, cmd => { DoTree(cmd, c =>{c.Execute();}, parentCommand.Value.Input); }); Assert.IsTrue(true); }
public void TestIsValid() { var node = new Node(); node.Id = -2; Contract.Assert(IsValid(node)); // it is not... }
public bool IsValid(Node node) { int i = node.Id; return this.First != null && 0 < i && i < First.Length && First[i] < LargeNode; }
public void TestDistanceCalc() { Node n1 = new Node(6.8, 4.4); Node n2 = new Node(-3.7, -11.2); Arc a = new Arc(n1, n2); // the Google calculated arc length = (((6.8 - (-3.7)) ^ 2) + ((4.4 - (-11.2)) ^ 2)) ^ (1/2) = 18.8045207331 double expectedResult = 18.8045207331; double diff = Math.Abs(expectedResult - a.Length); Assert.True(diff < 0.0000000001); // The expected (previously calculated) value has 10 digits after the decimal place. // Therefore, the difference between the computed value and the expected value must be less than 1 * (10 ^ (-10)). }
private void Init() { Origin = new Node(0, 0); NodeA = new Node(-10, 5); // sqrt(125) NodeB = new Node(-8, 7); // sqrt(113) NodeC = new Node(1, 11); // sqrt(122) NodeD = new Node(12, 9); // sqrt(225) SampleGraph = new Graph(Origin, NodeA, NodeB, NodeC, NodeD); }
public void TestNodeCompare() { var lowerNode = new Node<int>(1); var lowerNode2 = new Node<int>(1); var higherNode = new Node<int>(2); Assert.AreEqual(-1, lowerNode.CompareTo(higherNode)); Assert.AreEqual(1, higherNode.CompareTo(lowerNode)); Assert.AreEqual(-1, lowerNode.CompareTo(null)); Assert.AreEqual(0, lowerNode.CompareTo(lowerNode2)); }
public void CanSetAndGetValueByIndex() { dynamic one = new Node(); one["People"]["Gerald"]["Age"] = 34; Assert.AreEqual(34, one["People"]["Gerald"]["Age"]); }
public void CanSetAndGetValue() { dynamic one = new Node(); one.People.Gerald.Age = 34; Assert.AreEqual(34, one.People.Gerald.Age); }