trackler 2.2.1.162 → 2.2.1.163

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b0f3914ed0507205511f5d2b4c3cf1216af589b
4
- data.tar.gz: dc3375041de356a74a5c00d445b4206c948aba60
3
+ metadata.gz: 76612316f315c3fe85ebb27ebc85f29488a65b74
4
+ data.tar.gz: c97049c73a649f2216b10ba50f56003b6b64deda
5
5
  SHA512:
6
- metadata.gz: 563678d4ddf4f37de1d3103ce49c59744bfe20ae6a11ae45db829df3fff8586315f51912edea14dcd468f0cf6933f468eec555d3521f8036e1a297309f36236c
7
- data.tar.gz: 879532e919e270cc49831f1c225f981c68067a866d8b5ad5d22ca3bbcf9a3a702f3e6a2db6c34dba00b320215f1d37d9cc9df6209c4935d905ddcaddc1834a60
6
+ metadata.gz: 1f4fc4a223296db0466472ad905734207eff98965acfbc43db71ee8e6572bd566ebea8d70c799a70aad6bedbe6e66693229fd0dfb57886084096a50b28ef2a35
7
+ data.tar.gz: 8f862eda68d3bb98bb2bd362b76f650a6f6d4597134b6d2aed7110e60b6015147f2afeee7a00677c4b71a3c762494bfab67106463becf051552f2395b36801c5
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.2.1.162"
2
+ VERSION = "2.2.1.163"
3
3
  end
@@ -13,7 +13,8 @@
13
13
  "topics": [
14
14
  "stdout",
15
15
  "strings"
16
- ]
16
+ ],
17
+ "auto_approve": true
17
18
  },
18
19
  {
19
20
  "slug": "reverse-string",
@@ -1,5 +1,5 @@
1
- C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.
1
+ C is a general purpose language, used for a wide range of applications, from embedded computers to high-performance computing clusters.
2
2
 
3
- C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs, and used to re-implement the Unix operating system. It has since become one of the most widely used programming languages of all time, with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by the American National Standards Institute (ANSI) since 1989 (see ANSI C) and subsequently by the International Organization for Standardization (ISO).
3
+ C is commonly found in low level applications as it's a good alternative to harder-to-read assembly languages. It can be compiled to assembly to keep the same level of performance, while increasing readability, and providing a small level of safety with static types!
4
4
 
5
- Taken from https://en.wikipedia.org/wiki/C_(programming_language)
5
+ C was created by Dennis Ritchie at Bell Labs, and used to re-implement the Unix operating system. Now, it's one of the most used programming languages, with many compilers supporting providing support for most available hardware and platforms - there's plenty of resources and support available to help you get started!
@@ -1,6 +1,5 @@
1
- #include "hello_world.h"
1
+ #include <stdio.h>
2
2
 
3
- const char *hello(void)
4
- {
5
- return "Hello, World!";
3
+ int main(int argc, char* argv[]) {
4
+ printf("Hello, World!\n");
6
5
  }
@@ -24,7 +24,7 @@ most popularly linked introductory works.
24
24
  by David S. Touretzky
25
25
  * [Common Lisp: An Interactive Approach](http://www.cse.buffalo.edu/~shapiro/Commonlisp/) (PDF),
26
26
  by Stuart C. Shapiro
27
- * [Successful Lisp: How to Understand and Use Common Lisp](http://psg.com/~dlamkins/sl/cover.html),
27
+ * [Successful Lisp: How to Understand and Use Common Lisp](http://successful-lisp.blogspot.com/),
28
28
  by David B. Lamkins
29
29
 
30
30
  Following these are two more advanced books, but beginners shouldn't
@@ -10,6 +10,7 @@
10
10
  "slug": "hello-world",
11
11
  "uuid": "3eeadff6-82b6-43be-8834-d9ef258e454d",
12
12
  "core": false,
13
+ "auto_approve": true,
13
14
  "unlocked_by": null,
14
15
  "difficulty": 1,
15
16
  "topics": [
@@ -2,75 +2,72 @@
2
2
  using System.Collections.Generic;
3
3
  using System.Linq;
4
4
 
5
- public class Graph<T> : IEquatable<Graph<T>>
5
+ public class Tree : IEquatable<Tree>
6
6
  {
7
- public Graph(T value, IEnumerable<Graph<T>> children)
8
- {
9
- Value = value;
10
- Children = children;
11
- }
7
+ public Tree(string value, params Tree[] children)
8
+ => (Value, Children) = (value, children);
12
9
 
13
- public T Value { get; }
14
- public IEnumerable<Graph<T>> Children { get; }
10
+ public string Value { get; }
11
+ public Tree[] Children { get; }
15
12
 
16
- public bool Equals(Graph<T> other) =>
17
- Value.Equals(other.Value) && Children.SequenceEqual(other.Children);
13
+ public bool Equals(Tree other)
14
+ => Value.Equals(other.Value) &&
15
+ Children.OrderBy(child => child.Value).SequenceEqual(other.Children.OrderBy(child => child.Value));
18
16
  }
19
17
 
20
- public class GraphCrumb<T>
18
+ public class TreeCrumb
21
19
  {
22
- public GraphCrumb(T value, IEnumerable<Graph<T>> left, IEnumerable<Graph<T>> right)
23
- {
24
- Value = value;
25
- Left = left;
26
- Right = right;
27
- }
20
+ public TreeCrumb(string value, IEnumerable<Tree> left, IEnumerable<Tree> right)
21
+ => (Value, Left, Right) = (value, left, right);
28
22
 
29
- public T Value { get; }
30
- public IEnumerable<Graph<T>> Left { get; }
31
- public IEnumerable<Graph<T>> Right { get; }
23
+ public string Value { get; }
24
+ public IEnumerable<Tree> Left { get; }
25
+ public IEnumerable<Tree> Right { get; }
32
26
  }
33
27
 
34
- public class GraphZipper<T>
28
+ public class TreeZipper
35
29
  {
36
- public GraphZipper(Graph<T> focus, IEnumerable<GraphCrumb<T>> crumbs)
37
- {
38
- Focus = focus;
39
- Crumbs = crumbs;
40
- }
30
+ public TreeZipper(Tree focus, IEnumerable<TreeCrumb> crumbs)
31
+ => (Focus, Crumbs) = (focus, crumbs);
41
32
 
42
- public Graph<T> Focus { get; }
43
- public IEnumerable<GraphCrumb<T>> Crumbs { get; }
33
+ public Tree Focus { get; }
34
+ public IEnumerable<TreeCrumb> Crumbs { get; }
44
35
  }
45
36
 
46
37
  public static class Pov
47
38
  {
48
- public static Graph<T> CreateGraph<T>(T value, IEnumerable<Graph<T>> children)
49
- => new Graph<T>(value, children);
39
+ public static Tree FromPov(Tree graph, string value)
40
+ {
41
+ var zipper = FindNode(value, GraphToZipper(graph));
42
+ if (zipper == null)
43
+ throw new ArgumentException();
44
+
45
+ return ChangeParent(zipper);
46
+ }
50
47
 
51
- public static Graph<T> FromPOV<T>(T value, Graph<T> graph) where T : IComparable
52
- => ChangeParent(FindNode(value, GraphToZipper(graph)));
48
+ public static IEnumerable<string> PathTo(string value1, string value2, Tree graph)
49
+ {
50
+ var zipper = FindNode(value2, GraphToZipper(FromPov(graph, value1)));
51
+ if (zipper == null)
52
+ throw new ArgumentException();
53
53
 
54
- public static IEnumerable<T> TracePathBetween<T>(T value1, T value2, Graph<T> graph) where T : IComparable
55
- => ZipperToPath(FindNode(value2, GraphToZipper(FromPOV(value1, graph))));
54
+ return ZipperToPath(zipper);
55
+ }
56
56
 
57
- private static GraphZipper<T> GraphToZipper<T>(Graph<T> graph)
57
+ private static TreeZipper GraphToZipper(Tree graph)
58
58
  {
59
59
  if (graph == null)
60
60
  return null;
61
61
 
62
- return new GraphZipper<T>(graph, Enumerable.Empty<GraphCrumb<T>>());
62
+ return new TreeZipper(graph, Enumerable.Empty<TreeCrumb>());
63
63
  }
64
64
 
65
- private static IEnumerable<T> ZipperToPath<T>(GraphZipper<T> zipper)
65
+ private static IEnumerable<string> ZipperToPath(TreeZipper zipper)
66
66
  {
67
- if (zipper == null)
68
- return null;
69
-
70
- return zipper.Crumbs.Select(c => c.Value).Reverse().Concat(new[] { zipper.Focus.Value });
67
+ return zipper?.Crumbs.Select(c => c.Value).Reverse().Concat(new[] { zipper.Focus.Value });
71
68
  }
72
69
 
73
- private static GraphZipper<T> GoDown<T>(GraphZipper<T> zipper)
70
+ private static TreeZipper GoDown(TreeZipper zipper)
74
71
  {
75
72
  if (zipper == null || !zipper.Focus.Children.Any())
76
73
  return null;
@@ -78,12 +75,12 @@ public static class Pov
78
75
  var focus = zipper.Focus;
79
76
  var children = focus.Children;
80
77
 
81
- var newCrumb = new GraphCrumb<T>(focus.Value, Enumerable.Empty<Graph<T>>(), children.Skip(1));
78
+ var newCrumb = new TreeCrumb(focus.Value, Array.Empty<Tree>(), children.Skip(1).ToArray());
82
79
 
83
- return new GraphZipper<T>(children.First(), new[] { newCrumb }.Concat(zipper.Crumbs));
80
+ return new TreeZipper(children.First(), new[] { newCrumb }.Concat(zipper.Crumbs));
84
81
  }
85
82
 
86
- private static GraphZipper<T> GoRight<T>(GraphZipper<T> zipper)
83
+ private static TreeZipper GoRight(TreeZipper zipper)
87
84
  {
88
85
  if (zipper == null || !zipper.Crumbs.Any() || !zipper.Crumbs.First().Right.Any())
89
86
  return null;
@@ -91,13 +88,12 @@ public static class Pov
91
88
  var crumbs = zipper.Crumbs;
92
89
  var firstCrumb = crumbs.First();
93
90
 
94
- var newCrumb = new GraphCrumb<T>(firstCrumb.Value, firstCrumb.Left.Concat(new[] { zipper.Focus }), firstCrumb.Right.Skip(1));
91
+ var newCrumb = new TreeCrumb(firstCrumb.Value, firstCrumb.Left.Concat(new[] { zipper.Focus }).ToArray(), firstCrumb.Right.Skip(1).ToArray());
95
92
 
96
- return new GraphZipper<T>(firstCrumb.Right.First(), new[] { newCrumb }.Concat(crumbs.Skip(1)));
93
+ return new TreeZipper(firstCrumb.Right.First(), new[] { newCrumb }.Concat(crumbs.Skip(1)));
97
94
  }
98
95
 
99
- private static GraphZipper<T> FindNode<T>(T value, GraphZipper<T> zipper)
100
- where T : IComparable
96
+ private static TreeZipper FindNode(string value, TreeZipper zipper)
101
97
  {
102
98
  if (zipper == null || zipper.Focus.Value.CompareTo(value) == 0)
103
99
  return zipper;
@@ -105,7 +101,7 @@ public static class Pov
105
101
  return FindNode(value, GoDown(zipper)) ?? FindNode(value, GoRight(zipper));
106
102
  }
107
103
 
108
- private static Graph<T> ChangeParent<T>(GraphZipper<T> zipper)
104
+ private static Tree ChangeParent(TreeZipper zipper)
109
105
  {
110
106
  if (zipper == null)
111
107
  return null;
@@ -116,10 +112,10 @@ public static class Pov
116
112
  var firstCrumb = zipper.Crumbs.First();
117
113
  var focus = zipper.Focus;
118
114
 
119
- var newZipper = new GraphZipper<T>(CreateGraph(firstCrumb.Value, firstCrumb.Left.Concat(firstCrumb.Right)), zipper.Crumbs.Skip(1));
115
+ var newZipper = new TreeZipper(new Tree(firstCrumb.Value, firstCrumb.Left.Concat(firstCrumb.Right).ToArray()), zipper.Crumbs.Skip(1));
120
116
  var parentGraph = ChangeParent(newZipper);
121
117
 
122
- var ys = focus.Children.Concat(new[] { parentGraph });
123
- return CreateGraph(focus.Value, ys);
118
+ var ys = focus.Children.Concat(new[] { parentGraph }).ToArray();
119
+ return new Tree(focus.Value, ys);
124
120
  }
125
121
  }
@@ -1,42 +1,22 @@
1
1
  using System;
2
2
  using System.Collections.Generic;
3
3
 
4
- public class Graph<T>
4
+ public class Tree
5
5
  {
6
- public Graph(T value, IEnumerable<Graph<T>> children)
6
+ public Tree(string value, params Tree[] children)
7
7
  {
8
- }
9
-
10
- public T Value
11
- {
12
- get
13
- {
14
- throw new NotImplementedException("You need to implement this function.");
15
- }
16
- }
17
-
18
- public IEnumerable<Graph<T>> Children
19
- {
20
- get
21
- {
22
- throw new NotImplementedException("You need to implement this function.");
23
- }
8
+ throw new NotImplementedException("You need to implement this function.");
24
9
  }
25
10
  }
26
11
 
27
12
  public static class Pov
28
13
  {
29
- public static Graph<T> CreateGraph<T>(T value, IEnumerable<Graph<T>> children)
30
- {
31
- throw new NotImplementedException("You need to implement this function.");
32
- }
33
-
34
- public static Graph<T> FromPOV<T>(T value, Graph<T> graph) where T : IComparable
14
+ public static Tree FromPov(Tree tree, string from)
35
15
  {
36
16
  throw new NotImplementedException("You need to implement this function.");
37
17
  }
38
18
 
39
- public static IEnumerable<T> TracePathBetween<T>(T value1, T value2, Graph<T> graph) where T : IComparable
19
+ public static IEnumerable<string> PathTo(string from, string to, Tree tree)
40
20
  {
41
21
  throw new NotImplementedException("You need to implement this function.");
42
22
  }
@@ -1,154 +1,171 @@
1
- using Xunit;
2
- using System.Linq;
1
+ // This file was auto-generated based on version 1.3.0 of the canonical data.
2
+
3
+ using Xunit;
4
+ using System;
3
5
 
4
6
  public class PovTest
5
7
  {
6
- private const string x = "x";
7
-
8
- private static Graph<T> leaf<T>(T v) => Pov.CreateGraph(v, new Graph<T>[0]);
9
-
10
- private static readonly Graph<string> singleton = Pov.CreateGraph(x, new Graph<string>[0]);
11
-
12
- private static readonly Graph<string> flat = Pov.CreateGraph("root", new[] { "a", "b", x, "c" }.Select(leaf));
13
-
14
- private static readonly Graph<string> nested =
15
- Pov.CreateGraph("level-0", new[] {
16
- Pov.CreateGraph("level-1", new[] {
17
- Pov.CreateGraph("level-2", new[] {
18
- Pov.CreateGraph("level-3", new[] {
19
- Pov.CreateGraph(x, new Graph<string>[0])
20
- })
21
- })
22
- })
23
- });
24
-
25
- private static readonly Graph<string> kids =
26
- Pov.CreateGraph("root", new[] {
27
- Pov.CreateGraph(x, new[] {
28
- Pov.CreateGraph("kid-0", new Graph<string>[0]),
29
- Pov.CreateGraph("kid-1", new Graph<string>[0])
30
- })
31
- });
32
-
33
- private static readonly Graph<string> cousins =
34
- Pov.CreateGraph("grandparent", new[] {
35
- Pov.CreateGraph("parent", new [] {
36
- Pov.CreateGraph(x, new [] {
37
- leaf("kid-a"),
38
- leaf("kid-b")
39
- }),
40
- leaf("sibling-0"),
41
- leaf("sibling-1")
42
- }),
43
- Pov.CreateGraph("uncle", new [] {
44
- leaf("cousin-0"),
45
- leaf("cousin-1")
46
- })
47
- });
48
-
49
- private static readonly Graph<string> singleton_ = singleton;
50
-
51
- private static readonly Graph<string> flat_ =
52
- Pov.CreateGraph(x, new[] {
53
- Pov.CreateGraph("root", new [] { "a", "b", "c" }.Select(leaf))
54
- });
55
-
56
- private static readonly Graph<string> nested_ =
57
- Pov.CreateGraph(x, new[] {
58
- Pov.CreateGraph("level-3", new [] {
59
- Pov.CreateGraph("level-2", new [] {
60
- Pov.CreateGraph("level-1", new [] {
61
- Pov.CreateGraph("level-0", new Graph<string>[0])
62
- })
63
- })
64
- })
65
- });
66
-
67
- private static readonly Graph<string> kids_ =
68
- Pov.CreateGraph(x, new[] {
69
- Pov.CreateGraph("kid-0", new Graph<string>[0]),
70
- Pov.CreateGraph("kid-1", new Graph<string>[0]),
71
- Pov.CreateGraph("root", new Graph<string>[0])
72
- });
73
-
74
- private static readonly Graph<string> cousins_ =
75
- Pov.CreateGraph(x, new[] {
76
- leaf("kid-a"),
77
- leaf("kid-b"),
78
- Pov.CreateGraph("parent", new [] {
79
- Pov.CreateGraph("sibling-0", new Graph<string>[0]),
80
- Pov.CreateGraph("sibling-1", new Graph<string>[0]),
81
- Pov.CreateGraph("grandparent", new [] {
82
- Pov.CreateGraph("uncle", new [] {
83
- Pov.CreateGraph("cousin-0", new Graph<string>[0]),
84
- Pov.CreateGraph("cousin-1", new Graph<string>[0])
85
- })
86
- })
87
- })
88
- });
89
-
90
8
  [Fact]
91
- public void Reparent_singleton()
9
+ public void Results_in_the_same_tree_if_the_input_tree_is_a_singleton()
10
+ {
11
+ var tree = new Tree("x");
12
+ var from = "x";
13
+ var expected = new Tree("x");
14
+ Assert.Equal(expected, Pov.FromPov(tree, from));
15
+ }
16
+
17
+ [Fact(Skip = "Remove to run test")]
18
+ public void Can_reroot_a_tree_with_a_parent_and_one_sibling()
19
+ {
20
+ var tree = new Tree("parent", new Tree("x"), new Tree("sibling"));
21
+ var from = "x";
22
+ var expected = new Tree("x", new Tree("parent", new Tree("sibling")));
23
+ Assert.Equal(expected, Pov.FromPov(tree, from));
24
+ }
25
+
26
+ [Fact(Skip = "Remove to run test")]
27
+ public void Can_reroot_a_tree_with_a_parent_and_many_siblings()
28
+ {
29
+ var tree = new Tree("parent", new Tree("a"), new Tree("x"), new Tree("b"), new Tree("c"));
30
+ var from = "x";
31
+ var expected = new Tree("x", new Tree("parent", new Tree("a"), new Tree("b"), new Tree("c")));
32
+ Assert.Equal(expected, Pov.FromPov(tree, from));
33
+ }
34
+
35
+ [Fact(Skip = "Remove to run test")]
36
+ public void Can_reroot_a_tree_with_new_root_deeply_nested_in_tree()
92
37
  {
93
- Assert.Equal(singleton_, Pov.FromPOV(x, singleton));
38
+ var tree = new Tree("level-0", new Tree("level-1", new Tree("level-2", new Tree("level-3", new Tree("x")))));
39
+ var from = "x";
40
+ var expected = new Tree("x", new Tree("level-3", new Tree("level-2", new Tree("level-1", new Tree("level-0")))));
41
+ Assert.Equal(expected, Pov.FromPov(tree, from));
94
42
  }
95
43
 
96
44
  [Fact(Skip = "Remove to run test")]
97
- public void Reparent_flat()
45
+ public void Moves_children_of_the_new_root_to_same_level_as_former_parent()
98
46
  {
99
- Assert.Equal(flat_, Pov.FromPOV(x, flat));
47
+ var tree = new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")));
48
+ var from = "x";
49
+ var expected = new Tree("x", new Tree("kid-0"), new Tree("kid-1"), new Tree("parent"));
50
+ Assert.Equal(expected, Pov.FromPov(tree, from));
100
51
  }
101
52
 
102
53
  [Fact(Skip = "Remove to run test")]
103
- public void Reparent_nested()
54
+ public void Can_reroot_a_complex_tree_with_cousins()
104
55
  {
105
- Assert.Equal(nested_, Pov.FromPOV(x, nested));
56
+ var tree = new Tree("grandparent", new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")), new Tree("sibling-0"), new Tree("sibling-1")), new Tree("uncle", new Tree("cousin-0"), new Tree("cousin-1")));
57
+ var from = "x";
58
+ var expected = new Tree("x", new Tree("kid-1"), new Tree("kid-0"), new Tree("parent", new Tree("sibling-0"), new Tree("sibling-1"), new Tree("grandparent", new Tree("uncle", new Tree("cousin-0"), new Tree("cousin-1")))));
59
+ Assert.Equal(expected, Pov.FromPov(tree, from));
106
60
  }
107
61
 
108
62
  [Fact(Skip = "Remove to run test")]
109
- public void Reparent_kids()
63
+ public void Errors_if_target_does_not_exist_in_a_singleton_tree()
110
64
  {
111
- Assert.Equal(kids_, Pov.FromPOV(x, kids));
65
+ var tree = new Tree("x");
66
+ var from = "nonexistent";
67
+ Assert.Throws<ArgumentException>(() => Pov.FromPov(tree, from));
112
68
  }
113
69
 
114
70
  [Fact(Skip = "Remove to run test")]
115
- public void Reparent_cousins()
71
+ public void Errors_if_target_does_not_exist_in_a_large_tree()
116
72
  {
117
- Assert.Equal(cousins_, Pov.FromPOV(x, cousins));
73
+ var tree = new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")), new Tree("sibling-0"), new Tree("sibling-1"));
74
+ var from = "nonexistent";
75
+ Assert.Throws<ArgumentException>(() => Pov.FromPov(tree, from));
118
76
  }
119
77
 
120
78
  [Fact(Skip = "Remove to run test")]
121
- public void Reparent_from_POV_of_non_existent_node()
79
+ public void Can_find_path_to_parent()
122
80
  {
123
- Assert.Null(Pov.FromPOV(x, leaf("foo")));
81
+ var from = "x";
82
+ var to = "parent";
83
+ var tree = new Tree("parent", new Tree("x"), new Tree("sibling"));
84
+ var expected = new[]
85
+ {
86
+ "x",
87
+ "parent"
88
+ };
89
+ Assert.Equal(expected, Pov.PathTo(from, to, tree));
90
+ }
91
+
92
+ [Fact(Skip = "Remove to run test")]
93
+ public void Can_find_path_to_sibling()
94
+ {
95
+ var from = "x";
96
+ var to = "b";
97
+ var tree = new Tree("parent", new Tree("a"), new Tree("x"), new Tree("b"), new Tree("c"));
98
+ var expected = new[]
99
+ {
100
+ "x",
101
+ "parent",
102
+ "b"
103
+ };
104
+ Assert.Equal(expected, Pov.PathTo(from, to, tree));
124
105
  }
125
106
 
126
107
  [Fact(Skip = "Remove to run test")]
127
- public void Should_not_be_able_to_find_a_missing_node()
108
+ public void Can_find_path_to_cousin()
128
109
  {
129
- var nodes = new[] { singleton, flat, kids, nested, cousins }.Select(graph => Pov.FromPOV("NOT THERE", graph));
130
-
131
- Assert.All(nodes, node =>
110
+ var from = "x";
111
+ var to = "cousin-1";
112
+ var tree = new Tree("grandparent", new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")), new Tree("sibling-0"), new Tree("sibling-1")), new Tree("uncle", new Tree("cousin-0"), new Tree("cousin-1")));
113
+ var expected = new[]
132
114
  {
133
- Assert.Null(node);
134
- });
115
+ "x",
116
+ "parent",
117
+ "grandparent",
118
+ "uncle",
119
+ "cousin-1"
120
+ };
121
+ Assert.Equal(expected, Pov.PathTo(from, to, tree));
135
122
  }
136
123
 
137
124
  [Fact(Skip = "Remove to run test")]
138
- public void Cannot_trace_between_unconnected_nodes()
125
+ public void Can_find_path_not_involving_root()
139
126
  {
140
- Assert.Null(Pov.TracePathBetween(x, "NOT THERE", cousins));
127
+ var from = "x";
128
+ var to = "sibling-1";
129
+ var tree = new Tree("grandparent", new Tree("parent", new Tree("x"), new Tree("sibling-0"), new Tree("sibling-1")));
130
+ var expected = new[]
131
+ {
132
+ "x",
133
+ "parent",
134
+ "sibling-1"
135
+ };
136
+ Assert.Equal(expected, Pov.PathTo(from, to, tree));
137
+ }
138
+
139
+ [Fact(Skip = "Remove to run test")]
140
+ public void Can_find_path_from_nodes_other_than_x()
141
+ {
142
+ var from = "a";
143
+ var to = "c";
144
+ var tree = new Tree("parent", new Tree("a"), new Tree("x"), new Tree("b"), new Tree("c"));
145
+ var expected = new[]
146
+ {
147
+ "a",
148
+ "parent",
149
+ "c"
150
+ };
151
+ Assert.Equal(expected, Pov.PathTo(from, to, tree));
141
152
  }
142
153
 
143
154
  [Fact(Skip = "Remove to run test")]
144
- public void Can_trace_a_path_from_x_to_cousin()
155
+ public void Errors_if_destination_does_not_exist()
145
156
  {
146
- Assert.Equal(new[] { "x", "parent", "grandparent", "uncle", "cousin-1" }, Pov.TracePathBetween(x, "cousin-1", cousins));
157
+ var from = "x";
158
+ var to = "nonexistent";
159
+ var tree = new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")), new Tree("sibling-0"), new Tree("sibling-1"));
160
+ Assert.Throws<ArgumentException>(() => Pov.PathTo(from, to, tree));
147
161
  }
148
162
 
149
163
  [Fact(Skip = "Remove to run test")]
150
- public void Can_trace_from_a_leaf_to_a_leaf()
164
+ public void Errors_if_source_does_not_exist()
151
165
  {
152
- Assert.Equal(new[] { "kid-a", "x", "parent", "grandparent", "uncle", "cousin-0" }, Pov.TracePathBetween("kid-a", "cousin-0", cousins));
166
+ var from = "nonexistent";
167
+ var to = "x";
168
+ var tree = new Tree("parent", new Tree("x", new Tree("kid-0"), new Tree("kid-1")), new Tree("sibling-0"), new Tree("sibling-1"));
169
+ Assert.Throws<ArgumentException>(() => Pov.PathTo(from, to, tree));
153
170
  }
154
171
  }
@@ -3,8 +3,6 @@ using System.Collections;
3
3
  using System.Collections.Generic;
4
4
  using System.Linq;
5
5
 
6
- public delegate void ChangedEventHandler(object sender, int value);
7
-
8
6
  public class Reactor
9
7
  {
10
8
  private readonly Dictionary<int, Cell> cells = new Dictionary<int, Cell>();
@@ -61,7 +59,7 @@ public abstract class Cell
61
59
  public List<Cell> Consumers { get; }
62
60
 
63
61
  public abstract int Value { get; set; }
64
- public abstract event ChangedEventHandler Changed;
62
+ public abstract event EventHandler<int> Changed;
65
63
  }
66
64
 
67
65
  public class InputCell : Cell
@@ -73,7 +71,7 @@ public class InputCell : Cell
73
71
  _value = value;
74
72
  }
75
73
 
76
- public override event ChangedEventHandler Changed;
74
+ public override event EventHandler<int> Changed;
77
75
 
78
76
  public override int Value
79
77
  {
@@ -109,7 +107,7 @@ public class ComputeCell : Cell
109
107
  }
110
108
 
111
109
  public override int Value { get; set; }
112
- public override event ChangedEventHandler Changed;
110
+ public override event EventHandler<int> Changed;
113
111
 
114
112
  public void Recompute()
115
113
  {
@@ -12,6 +12,7 @@
12
12
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
13
13
  <PackageReference Include="xunit" Version="2.3.1" />
14
14
  <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
15
+ <PackageReference Include="FakeItEasy" Version="4.6.0" />
15
16
  </ItemGroup>
16
17
 
17
18
  </Project>