trackler 2.2.1.155 → 2.2.1.156

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/lib/trackler/version.rb +1 -1
  4. data/problem-specifications/exercises/simple-cipher/canonical-data.json +147 -0
  5. data/tracks/clojure/exercises/hexadecimal/src/hexadecimal.clj +5 -0
  6. data/tracks/clojure/exercises/isogram/src/isogram.clj +5 -0
  7. data/tracks/clojure/exercises/kindergarten-garden/src/kindergarten-garden.clj +5 -0
  8. data/tracks/csharp/exercises/list-ops/Example.cs +14 -9
  9. data/tracks/csharp/exercises/list-ops/ListOps.cs +4 -4
  10. data/tracks/csharp/exercises/list-ops/ListOpsTest.cs +90 -88
  11. data/tracks/csharp/exercises/zipper/Example.cs +51 -43
  12. data/tracks/csharp/exercises/zipper/Zipper.cs +16 -19
  13. data/tracks/csharp/exercises/zipper/ZipperTest.cs +94 -45
  14. data/tracks/csharp/generators/Exercises/ListOps.cs +123 -0
  15. data/tracks/csharp/generators/Exercises/Zipper.cs +107 -0
  16. data/tracks/csharp/generators/Output/ValueFormatter.cs +14 -0
  17. data/tracks/delphi/config.json +10 -1
  18. data/tracks/delphi/config/maintainers.json +11 -11
  19. data/tracks/elisp/config.json +8 -0
  20. data/tracks/elisp/exercises/run-length-encoding/README.md +36 -0
  21. data/tracks/elisp/exercises/run-length-encoding/example.el +62 -0
  22. data/tracks/elisp/exercises/run-length-encoding/run-length-encoding-test.el +61 -0
  23. data/tracks/elisp/exercises/run-length-encoding/run-length-encoding.el +9 -0
  24. data/tracks/fsharp/docs/LEARNING.md +3 -0
  25. data/tracks/java/exercises/armstrong-numbers/.meta/hints.md +2 -0
  26. data/tracks/java/exercises/armstrong-numbers/README.md +6 -0
  27. data/tracks/java/exercises/bracket-push/.meta/version +1 -1
  28. data/tracks/java/exercises/bracket-push/src/test/java/BracketCheckerTest.java +7 -0
  29. data/tracks/java/exercises/isbn-verifier/.meta/version +1 -1
  30. data/tracks/java/exercises/isbn-verifier/src/test/java/IsbnVerifierTest.java +12 -1
  31. data/tracks/java/exercises/kindergarten-garden/.meta/version +1 -1
  32. data/tracks/java/exercises/list-ops/.meta/version +1 -1
  33. data/tracks/java/exercises/list-ops/src/test/java/ListOpsTest.java +32 -1
  34. data/tracks/nim/config.json +13 -2
  35. data/tracks/nim/exercises/bob/bob_test.nim +1 -1
  36. data/tracks/nim/exercises/bob/example.nim +6 -3
  37. data/tracks/nim/exercises/bracket-push/README.md +11 -0
  38. data/tracks/nim/exercises/bracket-push/bracket_push_test.nim +52 -0
  39. data/tracks/nim/exercises/bracket-push/example.nim +22 -0
  40. data/tracks/ocaml/exercises/bracket-push/test.ml +3 -1
  41. data/tracks/ocaml/exercises/luhn/example.ml +8 -5
  42. data/tracks/ocaml/exercises/luhn/test.ml +3 -1
  43. data/tracks/powershell/.gitignore +2 -1
  44. data/tracks/powershell/config.json +46 -13
  45. data/tracks/powershell/exercises/bob/.version +1 -0
  46. data/tracks/powershell/exercises/bob/BobResponse.example.ps1 +28 -0
  47. data/tracks/powershell/exercises/bob/BobResponse.ps1 +8 -0
  48. data/tracks/powershell/exercises/bob/BobResponse.tests.ps1 +109 -0
  49. data/tracks/powershell/exercises/bob/README.md +20 -0
  50. data/tracks/powershell/exercises/nucleotide-count/.version +1 -0
  51. data/tracks/powershell/exercises/nucleotide-count/NucleotideCount.example.ps1 +36 -0
  52. data/tracks/powershell/exercises/nucleotide-count/NucleotideCount.ps1 +8 -0
  53. data/tracks/powershell/exercises/nucleotide-count/NucleotideCount.tests.ps1 +25 -0
  54. data/tracks/powershell/exercises/nucleotide-count/README.md +19 -0
  55. data/tracks/powershell/exercises/raindrops/.version +1 -0
  56. data/tracks/powershell/exercises/raindrops/README.md +24 -0
  57. data/tracks/powershell/exercises/raindrops/Raindrops.example.ps1 +32 -0
  58. data/tracks/powershell/exercises/raindrops/Raindrops.ps1 +8 -0
  59. data/tracks/powershell/exercises/raindrops/Raindrops.tests.ps1 +34 -0
  60. data/tracks/prolog/exercises/complex-numbers/complex_numbers_tests.plt +28 -29
  61. data/tracks/reasonml/.gitignore +4 -0
  62. data/tracks/reasonml/.travis.yml +5 -0
  63. data/tracks/reasonml/LICENSE +21 -0
  64. data/tracks/reasonml/README.md +67 -0
  65. data/tracks/reasonml/bin/fetch-configlet +32 -0
  66. data/tracks/reasonml/config.json +11 -0
  67. data/tracks/reasonml/config/exercise-readme-insert.md +0 -0
  68. data/tracks/reasonml/config/exercise_readme.go.tmpl +16 -0
  69. data/tracks/reasonml/config/maintainers.json +4 -0
  70. data/tracks/reasonml/docs/ABOUT.md +0 -0
  71. data/tracks/reasonml/docs/INSTALLATION.md +0 -0
  72. data/tracks/reasonml/docs/LEARNING.md +0 -0
  73. data/tracks/reasonml/docs/RESOURCES.md +0 -0
  74. data/tracks/reasonml/docs/TESTS.md +0 -0
  75. data/tracks/reasonml/img/.keep +0 -0
  76. data/tracks/scala/config.json +11 -0
  77. data/tracks/scala/exercises/armstrong-numbers/README.md +29 -0
  78. data/tracks/scala/exercises/armstrong-numbers/build.sbt +3 -0
  79. data/tracks/scala/exercises/armstrong-numbers/example.scala +7 -0
  80. data/tracks/scala/exercises/armstrong-numbers/src/main/scala/.keep +0 -0
  81. data/tracks/scala/exercises/armstrong-numbers/src/test/scala/ArmstrongNumbersTest.scala +44 -0
  82. data/tracks/scala/testgen/src/main/scala/ArmstrongNumbersTestGenerator.scala +33 -0
  83. data/tracks/scheme/config.json +8 -0
  84. data/tracks/scheme/exercises/atbash-cipher/README.md +36 -0
  85. data/tracks/scheme/exercises/atbash-cipher/atbash-cipher-test.scm +67 -0
  86. data/tracks/scheme/exercises/atbash-cipher/atbash-cipher.scm +8 -0
  87. data/tracks/scheme/exercises/atbash-cipher/example.scm +40 -0
  88. metadata +57 -3
  89. data/tracks/python/exercises/rna-transcription/.meta/hints.md +0 -1
@@ -2,24 +2,24 @@
2
2
  using System.Collections.Generic;
3
3
  using System.Linq;
4
4
 
5
- public class BinTree<T> : IEquatable<BinTree<T>>
5
+ public class BinTree : IEquatable<BinTree>
6
6
  {
7
- public BinTree(T value, BinTree<T> left, BinTree<T> right)
7
+ public BinTree(int value, BinTree left, BinTree right)
8
8
  {
9
9
  Value = value;
10
10
  Left = left;
11
11
  Right = right;
12
12
  }
13
13
 
14
- public BinTree(BinTree<T> tree) : this(tree.Value, tree.Left, tree.Right)
14
+ public BinTree(BinTree tree) : this(tree.Value, tree.Left, tree.Right)
15
15
  {
16
16
  }
17
17
 
18
- public T Value { get; }
19
- public BinTree<T> Left { get; }
20
- public BinTree<T> Right { get; }
18
+ public int Value { get; }
19
+ public BinTree Left { get; }
20
+ public BinTree Right { get; }
21
21
 
22
- public bool Equals(BinTree<T> other)
22
+ public bool Equals(BinTree other)
23
23
  {
24
24
  if (other == null || !Equals(Value, other.Value))
25
25
  return false;
@@ -34,40 +34,40 @@ public bool Equals(BinTree<T> other)
34
34
  }
35
35
  }
36
36
 
37
- public abstract class BinTreeCrumb<T>
37
+ public abstract class BinTreeCrumb
38
38
  {
39
- public BinTreeCrumb(T value, BinTree<T> tree)
39
+ public BinTreeCrumb(int value, BinTree tree)
40
40
  {
41
41
  Value = value;
42
42
  Tree = tree;
43
43
  }
44
44
 
45
- public T Value { get; }
46
- public BinTree<T> Tree { get; }
45
+ public int Value { get; }
46
+ public BinTree Tree { get; }
47
47
  }
48
48
 
49
- public class BinTreeLeftCrumb<T> : BinTreeCrumb<T>
49
+ public class BinTreeLeftCrumb : BinTreeCrumb
50
50
  {
51
- public BinTreeLeftCrumb(T value, BinTree<T> tree) : base(value, tree)
51
+ public BinTreeLeftCrumb(int value, BinTree tree) : base(value, tree)
52
52
  {
53
53
  }
54
54
  }
55
55
 
56
- public class BinTreeRightCrumb<T> : BinTreeCrumb<T>
56
+ public class BinTreeRightCrumb : BinTreeCrumb
57
57
  {
58
- public BinTreeRightCrumb(T value, BinTree<T> tree) : base(value, tree)
58
+ public BinTreeRightCrumb(int value, BinTree tree) : base(value, tree)
59
59
  {
60
60
  }
61
61
  }
62
62
 
63
- public class Zipper<T>
63
+ public class Zipper : IEquatable<Zipper>
64
64
  {
65
- private readonly T value;
66
- private readonly BinTree<T> left;
67
- private readonly BinTree<T> right;
68
- private readonly List<BinTreeCrumb<T>> crumbs;
65
+ private readonly int value;
66
+ private readonly BinTree left;
67
+ private readonly BinTree right;
68
+ private readonly List<BinTreeCrumb> crumbs;
69
69
 
70
- public Zipper(T value, BinTree<T> left, BinTree<T> right, List<BinTreeCrumb<T>> crumbs)
70
+ public Zipper(int value, BinTree left, BinTree right, List<BinTreeCrumb> crumbs)
71
71
  {
72
72
  this.value = value;
73
73
  this.left = left;
@@ -75,33 +75,33 @@ public Zipper(T value, BinTree<T> left, BinTree<T> right, List<BinTreeCrumb<T>>
75
75
  this.crumbs = crumbs;
76
76
  }
77
77
 
78
- public T Value => value;
78
+ public int Value() => value;
79
79
 
80
- public Zipper<T> SetValue(T newValue) => new Zipper<T>(newValue, left, right, crumbs);
80
+ public Zipper SetValue(int newValue) => new Zipper(newValue, left, right, crumbs);
81
81
 
82
- public Zipper<T> SetLeft(BinTree<T> binTree) => new Zipper<T>(value, binTree, right, crumbs);
82
+ public Zipper SetLeft(BinTree binTree) => new Zipper(value, binTree, right, crumbs);
83
83
 
84
- public Zipper<T> SetRight(BinTree<T> binTree) => new Zipper<T>(value, left, binTree, crumbs);
84
+ public Zipper SetRight(BinTree binTree) => new Zipper(value, left, binTree, crumbs);
85
85
 
86
- public Zipper<T> Left()
86
+ public Zipper Left()
87
87
  {
88
88
  if (left == null)
89
89
  return null;
90
90
 
91
- var newCrumbs = new[] { new BinTreeLeftCrumb<T>(value, right) }.Concat(crumbs).ToList();
92
- return new Zipper<T>(left.Value, left.Left, left.Right, newCrumbs);
91
+ var newCrumbs = new[] { new BinTreeLeftCrumb(value, right) }.Concat(crumbs).ToList();
92
+ return new Zipper(left.Value, left.Left, left.Right, newCrumbs);
93
93
  }
94
94
 
95
- public Zipper<T> Right()
95
+ public Zipper Right()
96
96
  {
97
97
  if (right == null)
98
98
  return null;
99
99
 
100
- var newCrumbs = new[] { new BinTreeRightCrumb<T>(value, left) }.Concat(crumbs).ToList();
101
- return new Zipper<T>(right.Value, right.Left, right.Right, newCrumbs);
100
+ var newCrumbs = new[] { new BinTreeRightCrumb(value, left) }.Concat(crumbs).ToList();
101
+ return new Zipper(right.Value, right.Left, right.Right, newCrumbs);
102
102
  }
103
103
 
104
- public Zipper<T> Up()
104
+ public Zipper Up()
105
105
  {
106
106
  if (crumbs.Count == 0)
107
107
  return null;
@@ -109,29 +109,37 @@ public Zipper<T> Up()
109
109
  var firstCrumb = crumbs[0];
110
110
  var remainingCrumbs = crumbs.Skip(1).ToList();
111
111
 
112
- if (firstCrumb is BinTreeLeftCrumb<T>)
113
- return new Zipper<T>(firstCrumb.Value, new BinTree<T>(value, left, right), firstCrumb.Tree, remainingCrumbs);
112
+ if (firstCrumb is BinTreeLeftCrumb)
113
+ return new Zipper(firstCrumb.Value, new BinTree(value, left, right), firstCrumb.Tree, remainingCrumbs);
114
114
 
115
- if (firstCrumb is BinTreeRightCrumb<T>)
116
- return new Zipper<T>(firstCrumb.Value, firstCrumb.Tree, new BinTree<T>(value, left, right), remainingCrumbs);
115
+ if (firstCrumb is BinTreeRightCrumb)
116
+ return new Zipper(firstCrumb.Value, firstCrumb.Tree, new BinTree(value, left, right), remainingCrumbs);
117
117
 
118
118
  return null;
119
119
  }
120
120
 
121
- public BinTree<T> ToTree()
121
+ public BinTree ToTree()
122
122
  {
123
- var tree = new BinTree<T>(value, left, right);
123
+ var tree = new BinTree(value, left, right);
124
124
 
125
125
  foreach (var crumb in crumbs)
126
126
  {
127
- if (crumb is BinTreeLeftCrumb<T>)
128
- tree = new BinTree<T>(crumb.Value, new BinTree<T>(tree), crumb.Tree);
129
- if (crumb is BinTreeRightCrumb<T>)
130
- tree = new BinTree<T>(crumb.Value, crumb.Tree, new BinTree<T>(tree));
127
+ if (crumb is BinTreeLeftCrumb)
128
+ tree = new BinTree(crumb.Value, new BinTree(tree), crumb.Tree);
129
+ if (crumb is BinTreeRightCrumb)
130
+ tree = new BinTree(crumb.Value, crumb.Tree, new BinTree(tree));
131
131
  }
132
132
 
133
133
  return tree;
134
134
  }
135
135
 
136
- public static Zipper<T> FromTree(BinTree<T> tree) => new Zipper<T>(tree.Value, tree.Left, tree.Right, new List<BinTreeCrumb<T>>());
136
+ public bool Equals(Zipper other)
137
+ {
138
+ if (other == null)
139
+ return false;
140
+
141
+ return ToTree().Equals(other.ToTree());
142
+ }
143
+
144
+ public static Zipper FromTree(BinTree tree) => new Zipper(tree.Value, tree.Left, tree.Right, new List<BinTreeCrumb>());
137
145
  }
@@ -1,63 +1,60 @@
1
1
  using System;
2
2
 
3
- public class BinTree<T>
3
+ public class BinTree
4
4
  {
5
- public BinTree(T value, BinTree<T> left, BinTree<T> right)
5
+ public BinTree(int value, BinTree left, BinTree right)
6
6
  {
7
7
  throw new NotImplementedException("You need to implement this function.");
8
8
  }
9
9
 
10
- public T Value { get; }
11
- public BinTree<T> Left { get; }
12
- public BinTree<T> Right { get; }
10
+ public int Value { get; }
11
+ public BinTree Left { get; }
12
+ public BinTree Right { get; }
13
13
  }
14
14
 
15
- public class Zipper<T>
15
+ public class Zipper
16
16
  {
17
- public T Value
17
+ public int Value()
18
18
  {
19
- get
20
- {
21
- throw new NotImplementedException("You need to implement this function.");
22
- }
19
+ throw new NotImplementedException("You need to implement this function.");
23
20
  }
24
21
 
25
- public Zipper<T> SetValue(T newValue)
22
+ public Zipper SetValue(int newValue)
26
23
  {
27
24
  throw new NotImplementedException("You need to implement this function.");
28
25
  }
29
26
 
30
- public Zipper<T> SetLeft(BinTree<T> binTree)
27
+ public Zipper SetLeft(BinTree binTree)
31
28
  {
32
29
  throw new NotImplementedException("You need to implement this function.");
33
30
  }
34
31
 
35
- public Zipper<T> SetRight(BinTree<T> binTree)
32
+ public Zipper SetRight(BinTree binTree)
36
33
  {
37
34
  throw new NotImplementedException("You need to implement this function.");
38
35
  }
39
36
 
40
- public Zipper<T> Left()
37
+ public Zipper Left()
41
38
  {
42
39
  throw new NotImplementedException("You need to implement this function.");
43
40
  }
44
41
 
45
- public Zipper<T> Right()
42
+ public Zipper Right()
46
43
  {
47
44
  throw new NotImplementedException("You need to implement this function.");
48
45
  }
49
46
 
50
- public Zipper<T> Up()
47
+ public Zipper Up()
51
48
  {
52
49
  throw new NotImplementedException("You need to implement this function.");
53
50
  }
54
51
 
55
- public BinTree<T> ToTree()
52
+ public BinTree ToTree()
56
53
  {
57
54
  throw new NotImplementedException("You need to implement this function.");
58
55
  }
59
56
 
60
- public static Zipper<T> FromTree(BinTree<T> tree)
57
+ public static Zipper FromTree(BinTree tree)
61
58
  {
62
59
  throw new NotImplementedException("You need to implement this function.");
63
60
  }
@@ -1,85 +1,134 @@
1
- using Xunit;
1
+ // This file was auto-generated based on version 1.1.0 of the canonical data.
2
+
3
+ using Xunit;
2
4
 
3
5
  public class ZipperTest
4
6
  {
5
- private static BinTree<int> bt(int v, BinTree<int> l, BinTree<int> r) => new BinTree<int>(v, l, r);
6
- private static BinTree<int> leaf(int v) => bt(v, null, null);
7
-
8
- private readonly BinTree<int> empty;
9
- private readonly BinTree<int> t1;
10
- private readonly BinTree<int> t2;
11
- private readonly BinTree<int> t3;
12
- private readonly BinTree<int> t4;
13
-
14
- public ZipperTest()
15
- {
16
- empty = null;
17
- t1 = new BinTree<int>(1, bt(2, empty, leaf(3)), leaf(4));
18
- t2 = new BinTree<int>(1, bt(5, empty, leaf(3)), leaf(4));
19
- t3 = new BinTree<int>(1, bt(2, leaf(5), leaf(3)), leaf(4));
20
- t4 = new BinTree<int>(1, leaf(2), leaf(4));
21
- }
22
-
23
7
  [Fact]
24
8
  public void Data_is_retained()
25
9
  {
26
- var zipper = Zipper<int>.FromTree(t1);
27
- var tree = zipper.ToTree();
28
- Assert.Equal(t1, tree);
10
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
11
+ var sut = Zipper.FromTree(tree);
12
+ var actual = sut.ToTree();
13
+ var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
14
+ Assert.Equal(expected, actual);
29
15
  }
30
16
 
31
17
  [Fact(Skip = "Remove to run test")]
32
18
  public void Left_right_and_value()
33
19
  {
34
- var zipper = Zipper<int>.FromTree(t1);
35
- Assert.Equal(3, zipper.Left().Right().Value);
20
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
21
+ var sut = Zipper.FromTree(tree);
22
+ var actual = sut.Left().Right().Value();
23
+ var expected = 3;
24
+ Assert.Equal(expected, actual);
36
25
  }
37
26
 
38
27
  [Fact(Skip = "Remove to run test")]
39
28
  public void Dead_end()
40
29
  {
41
- var zipper = Zipper<int>.FromTree(t1);
42
- Assert.Null(zipper.Left().Left());
30
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
31
+ var sut = Zipper.FromTree(tree);
32
+ var actual = sut.Left().Left();
33
+ Assert.Null(actual);
43
34
  }
44
35
 
45
36
  [Fact(Skip = "Remove to run test")]
46
37
  public void Tree_from_deep_focus()
47
38
  {
48
- var zipper = Zipper<int>.FromTree(t1);
49
- Assert.Equal(t1, zipper.Left().Right().ToTree());
39
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
40
+ var sut = Zipper.FromTree(tree);
41
+ var actual = sut.Left().Right().ToTree();
42
+ var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
43
+ Assert.Equal(expected, actual);
44
+ }
45
+
46
+ [Fact(Skip = "Remove to run test")]
47
+ public void Traversing_up_from_top()
48
+ {
49
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
50
+ var sut = Zipper.FromTree(tree);
51
+ var actual = sut.Up();
52
+ Assert.Null(actual);
53
+ }
54
+
55
+ [Fact(Skip = "Remove to run test")]
56
+ public void Left_right_and_up()
57
+ {
58
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
59
+ var sut = Zipper.FromTree(tree);
60
+ var actual = sut.Left().Up().Right().Up().Left().Right().Value();
61
+ var expected = 3;
62
+ Assert.Equal(expected, actual);
50
63
  }
51
64
 
52
65
  [Fact(Skip = "Remove to run test")]
53
66
  public void Set_value()
54
67
  {
55
- var zipper = Zipper<int>.FromTree(t1);
56
- var updatedZipper = zipper.Left().SetValue(5);
57
- var tree = updatedZipper.ToTree();
58
- Assert.Equal(t2, tree);
68
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
69
+ var sut = Zipper.FromTree(tree);
70
+ var actual = sut.Left().SetValue(5).ToTree();
71
+ var expected = new BinTree(1, new BinTree(5, null, new BinTree(3, null, null)), new BinTree(4, null, null));
72
+ Assert.Equal(expected, actual);
73
+ }
74
+
75
+ [Fact(Skip = "Remove to run test")]
76
+ public void Set_value_after_traversing_up()
77
+ {
78
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
79
+ var sut = Zipper.FromTree(tree);
80
+ var actual = sut.Left().Right().Up().SetValue(5).ToTree();
81
+ var expected = new BinTree(1, new BinTree(5, null, new BinTree(3, null, null)), new BinTree(4, null, null));
82
+ Assert.Equal(expected, actual);
83
+ }
84
+
85
+ [Fact(Skip = "Remove to run test")]
86
+ public void Set_left_with_leaf()
87
+ {
88
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
89
+ var sut = Zipper.FromTree(tree);
90
+ var actual = sut.Left().SetLeft(new BinTree(5, null, null)).ToTree();
91
+ var expected = new BinTree(1, new BinTree(2, new BinTree(5, null, null), new BinTree(3, null, null)), new BinTree(4, null, null));
92
+ Assert.Equal(expected, actual);
93
+ }
94
+
95
+ [Fact(Skip = "Remove to run test")]
96
+ public void Set_right_with_null()
97
+ {
98
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
99
+ var sut = Zipper.FromTree(tree);
100
+ var actual = sut.Left().SetRight(null).ToTree();
101
+ var expected = new BinTree(1, new BinTree(2, null, null), new BinTree(4, null, null));
102
+ Assert.Equal(expected, actual);
59
103
  }
60
104
 
61
105
  [Fact(Skip = "Remove to run test")]
62
- public void Set_left_with_value()
106
+ public void Set_right_with_subtree()
63
107
  {
64
- var zipper = Zipper<int>.FromTree(t1);
65
- var updatedZipper = zipper.Left().SetLeft(new BinTree<int>(5, null, null));
66
- var tree = updatedZipper.ToTree();
67
- Assert.Equal(t3, tree);
108
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
109
+ var sut = Zipper.FromTree(tree);
110
+ var actual = sut.SetRight(new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null))).ToTree();
111
+ var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null)));
112
+ Assert.Equal(expected, actual);
68
113
  }
69
114
 
70
115
  [Fact(Skip = "Remove to run test")]
71
- public void Set_right_to_null()
116
+ public void Set_value_on_deep_focus()
72
117
  {
73
- var zipper = Zipper<int>.FromTree(t1);
74
- var updatedZipper = zipper.Left().SetRight(null);
75
- var tree = updatedZipper.ToTree();
76
- Assert.Equal(t4, tree);
118
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
119
+ var sut = Zipper.FromTree(tree);
120
+ var actual = sut.Left().Right().SetValue(5).ToTree();
121
+ var expected = new BinTree(1, new BinTree(2, null, new BinTree(5, null, null)), new BinTree(4, null, null));
122
+ Assert.Equal(expected, actual);
77
123
  }
78
124
 
79
125
  [Fact(Skip = "Remove to run test")]
80
126
  public void Different_paths_to_same_zipper()
81
127
  {
82
- var zipper = Zipper<int>.FromTree(t1);
83
- Assert.Equal(zipper.Right().ToTree(), zipper.Left().Up().Right().ToTree());
128
+ var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
129
+ var sut = Zipper.FromTree(tree);
130
+ var actual = sut.Left().Up().Right();
131
+ var expected = Zipper.FromTree(new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null))).Right();
132
+ Assert.Equal(expected, actual);
84
133
  }
85
- }
134
+ }
@@ -0,0 +1,123 @@
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using System.Linq;
5
+ using Generators.Input;
6
+ using Generators.Output;
7
+ using Newtonsoft.Json.Linq;
8
+
9
+ namespace Generators.Exercises
10
+ {
11
+ public class ListOps : GeneratorExercise
12
+ {
13
+ protected override void UpdateCanonicalData(CanonicalData canonicalData)
14
+ {
15
+ foreach (var canonicalDataCase in canonicalData.Cases)
16
+ {
17
+ canonicalDataCase.UseFullDescriptionPath = true;
18
+ canonicalDataCase.UseVariablesForInput = true;
19
+ canonicalDataCase.UseVariableForExpected = !(canonicalDataCase.Expected is int);
20
+
21
+ if (canonicalDataCase.Input.TryGetValue("list", out var list))
22
+ canonicalDataCase.Input["list"] = ConvertToList(list);
23
+
24
+ if (canonicalDataCase.Input.TryGetValue("list1", out var list1))
25
+ canonicalDataCase.Input["list1"] = ConvertToList(list1);
26
+
27
+ if (canonicalDataCase.Input.TryGetValue("list2", out var list2))
28
+ canonicalDataCase.Input["list2"] = ConvertToList(list2);
29
+
30
+ if (canonicalDataCase.Input.TryGetValue("lists", out var lists))
31
+ canonicalDataCase.Input["lists"] = ConvertToNestedList(lists, true);
32
+
33
+ if (canonicalDataCase.Input.TryGetValue("function", out var function))
34
+ canonicalDataCase.Input["function"] = ConvertToFunction(canonicalDataCase.Property, function);
35
+
36
+ if (canonicalDataCase.Expected is IEnumerable)
37
+ {
38
+ if (canonicalDataCase.Input.ContainsKey("lists"))
39
+ canonicalDataCase.Expected = ConvertToNestedList(canonicalDataCase.Expected, false);
40
+ else
41
+ canonicalDataCase.Expected = ConvertToList(canonicalDataCase.Expected);
42
+ }
43
+ }
44
+ }
45
+
46
+ private static UnescapedValue ConvertToFunction(string property, dynamic function)
47
+ {
48
+ var signature =
49
+ property == "filter" ? "<int, bool>" :
50
+ property == "map" ? "<int, int>" :
51
+ "<int, int, int>";
52
+
53
+ var body = function
54
+ .Replace("modulo", "%")
55
+ .Replace("->", "=>");
56
+
57
+ return new UnescapedValue($"new Func{signature}({body})");
58
+ }
59
+
60
+ private static dynamic ConvertToList(dynamic value)
61
+ {
62
+ if (value is JArray jArray)
63
+ {
64
+ if (jArray.Count == 0)
65
+ return new List<int>();
66
+
67
+ if (jArray.Any(jToken => jToken.Type == JTokenType.Array))
68
+ return jArray.Select(ConvertToList).ToList();
69
+
70
+ return jArray.ToObject<int[]>().ToList();
71
+ }
72
+
73
+ if (value is IEnumerable<int> ints)
74
+ {
75
+ return ints.ToList();
76
+ }
77
+
78
+ return value;
79
+ }
80
+
81
+ private static dynamic ConvertToNestedList(dynamic value, bool unescapeEmpty)
82
+ {
83
+ if (value is JArray jArray)
84
+ {
85
+ if (jArray.Count == 0)
86
+ {
87
+ if (unescapeEmpty)
88
+ {
89
+ return new UnescapedValue("new List<List<int>>()");
90
+ }
91
+
92
+ return new List<int>();
93
+ }
94
+
95
+ var nestedList = jArray
96
+ .Children<JArray>()
97
+ .Select(ConvertToList)
98
+ .Select(ValueFormatter.Format)
99
+ .Select(formattedValue => new UnescapedValue(formattedValue))
100
+ .ToList();
101
+
102
+ return new UnescapedValue(ValueFormatter.Format(nestedList)
103
+ .Replace("<object>", "<int>")
104
+ .Replace("new List<int> { new List<int>", "new List<List<int>> { new List<int>")
105
+ .Replace("new[] { new List<List<int>>", "new List<List<List<int>>> { new List<List<int>>")
106
+ .Replace("new[] { new List<int>", "new List<List<int>> { new List<int>"));
107
+ }
108
+
109
+ if (value is IEnumerable<int> ints)
110
+ {
111
+ return new UnescapedValue(ValueFormatter.Format(ints.ToList()));
112
+ }
113
+
114
+ return value;
115
+ }
116
+
117
+ protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string>
118
+ {
119
+ typeof(Func<int,int>).Namespace,
120
+ typeof(List<int>).Namespace
121
+ };
122
+ }
123
+ }