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 +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/bash/config.json +2 -1
- data/tracks/c/docs/ABOUT.md +3 -3
- data/tracks/c/docs/SNIPPET.txt +3 -4
- data/tracks/common-lisp/docs/RESOURCES.md +1 -1
- data/tracks/cpp/config.json +1 -0
- data/tracks/csharp/exercises/pov/Example.cs +49 -53
- data/tracks/csharp/exercises/pov/Pov.cs +5 -25
- data/tracks/csharp/exercises/pov/PovTest.cs +127 -110
- data/tracks/csharp/exercises/react/Example.cs +3 -5
- data/tracks/csharp/exercises/react/React.csproj +1 -0
- data/tracks/csharp/exercises/react/ReactTest.cs +167 -78
- data/tracks/csharp/exercises/simple-cipher/Example.cs +18 -21
- data/tracks/csharp/exercises/simple-cipher/SimpleCipher.cs +3 -3
- data/tracks/csharp/exercises/simple-cipher/SimpleCipherTest.cs +43 -79
- data/tracks/csharp/generators/Exercises/Pov.cs +54 -0
- data/tracks/csharp/generators/Exercises/React.cs +136 -0
- data/tracks/csharp/generators/Exercises/SimpleCipher.cs +67 -0
- data/tracks/elixir/config/maintainers.json +16 -16
- data/tracks/elixir/config.json +370 -369
- data/tracks/java/config.json +1 -1
- data/tracks/racket/docs/LEARNING.md +1 -1
- data/tracks/sml/config/maintainers.json +8 -8
- data/tracks/sml/config.json +57 -103
- data/tracks/sml/exercises/nth-prime/.meta/hints.md +1 -1
- metadata +5 -2
@@ -0,0 +1,136 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Text;
|
5
|
+
using System.Text.RegularExpressions;
|
6
|
+
using Generators.Output;
|
7
|
+
using Humanizer;
|
8
|
+
using Newtonsoft.Json.Linq;
|
9
|
+
|
10
|
+
namespace Generators.Exercises
|
11
|
+
{
|
12
|
+
public class React : GeneratorExercise
|
13
|
+
{
|
14
|
+
protected override string RenderTestMethodBodyArrange(TestMethodBody testMethodBody)
|
15
|
+
{
|
16
|
+
var arrange = new StringBuilder();
|
17
|
+
arrange.AppendLine("var sut = new Reactor();");
|
18
|
+
|
19
|
+
var cells = RenderCells(testMethodBody.CanonicalDataCase.Input["cells"]);
|
20
|
+
arrange.AppendLine(cells);
|
21
|
+
|
22
|
+
var operations = RenderOperations(testMethodBody.CanonicalDataCase.Input["operations"]);
|
23
|
+
arrange.AppendLine(operations);
|
24
|
+
|
25
|
+
return arrange.ToString();
|
26
|
+
}
|
27
|
+
|
28
|
+
private static string RenderCells(dynamic cells)
|
29
|
+
{
|
30
|
+
if (cells.Length == 0)
|
31
|
+
{
|
32
|
+
return "";
|
33
|
+
}
|
34
|
+
|
35
|
+
var renderedCells = ((object[])cells).Select(RenderCell);
|
36
|
+
return string.Join("\n", renderedCells);
|
37
|
+
}
|
38
|
+
|
39
|
+
private static string RenderCell(dynamic cell)
|
40
|
+
{
|
41
|
+
var cellType = (string)cell["type"];
|
42
|
+
var cellName = ToVariableName(cell["name"]);
|
43
|
+
|
44
|
+
switch (cellType)
|
45
|
+
{
|
46
|
+
case "input":
|
47
|
+
return $"var {cellName} = sut.CreateInputCell({cell["initial_value"]});";
|
48
|
+
case "compute":
|
49
|
+
var inputs = string.Join(", ", ((string[])cell["inputs"]).Select(ToVariableName));
|
50
|
+
var computeFunction = RenderComputeFunction(cell["compute_function"]);
|
51
|
+
return $"var {cellName} = sut.CreateComputeCell(new[] {{ {inputs} }}, inputs => {computeFunction});";
|
52
|
+
default:
|
53
|
+
throw new InvalidOperationException($"Unknown cell type: {cellType}");
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
private static string RenderComputeFunction(dynamic computeFunction)
|
58
|
+
{
|
59
|
+
var match = Regex.Match((string)computeFunction, "if (.+) then (.+) else (.+)");
|
60
|
+
|
61
|
+
if (match.Success)
|
62
|
+
{
|
63
|
+
return $"{match.Groups[1]} ? {match.Groups[2]} : {match.Groups[3]}";
|
64
|
+
}
|
65
|
+
|
66
|
+
return computeFunction;
|
67
|
+
}
|
68
|
+
|
69
|
+
private static string RenderOperations(dynamic operations)
|
70
|
+
{
|
71
|
+
if (operations.Length == 0)
|
72
|
+
{
|
73
|
+
return "";
|
74
|
+
}
|
75
|
+
|
76
|
+
var renderedOperations = ((object[])operations).Select(RenderOperation);
|
77
|
+
return string.Join("\n", renderedOperations);
|
78
|
+
}
|
79
|
+
|
80
|
+
private static string RenderOperation(dynamic operation)
|
81
|
+
{
|
82
|
+
var operationType = (string)operation["type"];
|
83
|
+
|
84
|
+
switch (operationType)
|
85
|
+
{
|
86
|
+
case "set_value":
|
87
|
+
var renderedSetValue = new StringBuilder();
|
88
|
+
renderedSetValue.AppendLine($"{ToVariableName(operation["cell"])}.Value = {operation["value"]};");
|
89
|
+
|
90
|
+
if (operation.ContainsKey("expect_callbacks_not_to_be_called"))
|
91
|
+
{
|
92
|
+
var callbacksNotToBeCalled = ((string[])operation["expect_callbacks_not_to_be_called"]).Select(ToVariableName);
|
93
|
+
|
94
|
+
foreach (var callbackNotToBeCalled in callbacksNotToBeCalled)
|
95
|
+
{
|
96
|
+
renderedSetValue.AppendLine($"A.CallTo(() => {callbackNotToBeCalled}.Invoke(A<object>._, A<int>._)).MustNotHaveHappened();");
|
97
|
+
}
|
98
|
+
}
|
99
|
+
else if (operation.ContainsKey("expect_callbacks"))
|
100
|
+
{
|
101
|
+
var expectedCallbacks = operation["expect_callbacks"];
|
102
|
+
|
103
|
+
foreach (var expectedCallback in expectedCallbacks)
|
104
|
+
{
|
105
|
+
var expectedCallbackName = ToVariableName(expectedCallback.Key);
|
106
|
+
renderedSetValue.AppendLine($"A.CallTo(() => {expectedCallbackName}.Invoke(A<object>._, {expectedCallback.Value})).MustHaveHappenedOnceExactly();");
|
107
|
+
renderedSetValue.AppendLine($"Fake.ClearRecordedCalls({expectedCallbackName});");
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
return renderedSetValue.ToString();
|
112
|
+
case "expect_cell_value":
|
113
|
+
return $"Assert.Equal({operation["value"]}, {ToVariableName(operation["cell"])}.Value);";
|
114
|
+
case "add_callback":
|
115
|
+
var addCallbackName = ToVariableName(operation["name"]);
|
116
|
+
return $"var {addCallbackName} = A.Fake<EventHandler<int>>();\n" +
|
117
|
+
$"{ToVariableName(operation["cell"])}.Changed += {addCallbackName};";
|
118
|
+
case "remove_callback":
|
119
|
+
var removeCallbackName = ToVariableName(operation["name"]);
|
120
|
+
return $"{ToVariableName(operation["cell"])}.Changed -= {removeCallbackName};";
|
121
|
+
default:
|
122
|
+
return $"qweqwe";
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) => "";
|
127
|
+
|
128
|
+
protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string>
|
129
|
+
{
|
130
|
+
typeof(EventHandler).Namespace,
|
131
|
+
"FakeItEasy"
|
132
|
+
};
|
133
|
+
|
134
|
+
private static string ToVariableName(dynamic value) => ((string)value).Camelize();
|
135
|
+
}
|
136
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using Generators.Input;
|
4
|
+
using Generators.Output;
|
5
|
+
|
6
|
+
namespace Generators.Exercises
|
7
|
+
{
|
8
|
+
public class SimpleCipher : GeneratorExercise
|
9
|
+
{
|
10
|
+
protected override void UpdateCanonicalData(CanonicalData canonicalData)
|
11
|
+
{
|
12
|
+
foreach (var canonicalDataCase in canonicalData.Cases)
|
13
|
+
{
|
14
|
+
canonicalDataCase.UseFullDescriptionPath = true;
|
15
|
+
|
16
|
+
if (canonicalDataCase.Property == "new")
|
17
|
+
{
|
18
|
+
continue;
|
19
|
+
}
|
20
|
+
|
21
|
+
canonicalDataCase.TestedMethodType = TestedMethodType.Instance;
|
22
|
+
|
23
|
+
if (canonicalDataCase.Input.ContainsKey("key"))
|
24
|
+
{
|
25
|
+
canonicalDataCase.SetConstructorInputParameters("key");
|
26
|
+
}
|
27
|
+
|
28
|
+
if (canonicalDataCase.Input.TryGetValue("ciphertext", out var cipherText))
|
29
|
+
{
|
30
|
+
if (cipherText == "cipher.key")
|
31
|
+
{
|
32
|
+
canonicalDataCase.Input["ciphertext"] = new UnescapedValue("sut.Key.Substring(0, 10)");
|
33
|
+
}
|
34
|
+
else if (cipherText == "cipher.encode")
|
35
|
+
{
|
36
|
+
var plaintext = ValueFormatter.Format(canonicalDataCase.Input["plaintext"]);
|
37
|
+
canonicalDataCase.Input["ciphertext"] = new UnescapedValue($"sut.Encode({plaintext})");
|
38
|
+
canonicalDataCase.SetInputParameters("ciphertext");
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
if (canonicalDataCase.Expected is string s && s == "cipher.key")
|
43
|
+
{
|
44
|
+
canonicalDataCase.Expected = new UnescapedValue("sut.Key.Substring(0, 10)");
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody)
|
50
|
+
{
|
51
|
+
if (testMethodBody.CanonicalDataCase.Property == "new")
|
52
|
+
{
|
53
|
+
var key = ValueFormatter.Format(testMethodBody.CanonicalDataCase.Input["key"]);
|
54
|
+
return $"Assert.Throws<ArgumentException>(() => new SimpleCipher({key}));";
|
55
|
+
}
|
56
|
+
else if (testMethodBody.CanonicalDataCase.Property == "key")
|
57
|
+
{
|
58
|
+
var pattern = ValueFormatter.Format(testMethodBody.CanonicalDataCase.Expected["match"]);
|
59
|
+
return $"Assert.Matches({pattern}, sut.Key);";
|
60
|
+
}
|
61
|
+
|
62
|
+
return base.RenderTestMethodBodyAssert(testMethodBody);
|
63
|
+
}
|
64
|
+
|
65
|
+
protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string> { typeof(ArgumentException).Namespace };
|
66
|
+
}
|
67
|
+
}
|
@@ -2,34 +2,34 @@
|
|
2
2
|
"docs_url": "https://github.com/exercism/docs/blob/master/maintaining-a-track/maintainer-configuration.md",
|
3
3
|
"maintainers": [
|
4
4
|
{
|
5
|
-
"alumnus": false,
|
6
|
-
"avatar_url": null,
|
7
|
-
"bio": null,
|
8
5
|
"github_username": "rubysolo",
|
6
|
+
"alumnus": false,
|
7
|
+
"show_on_website": false,
|
8
|
+
"name": null,
|
9
9
|
"link_text": null,
|
10
10
|
"link_url": null,
|
11
|
-
"
|
12
|
-
"
|
11
|
+
"avatar_url": null,
|
12
|
+
"bio": null
|
13
13
|
},
|
14
14
|
{
|
15
|
-
"alumnus": false,
|
16
|
-
"avatar_url": null,
|
17
|
-
"bio": null,
|
18
15
|
"github_username": "parkerl",
|
16
|
+
"alumnus": false,
|
17
|
+
"show_on_website": false,
|
18
|
+
"name": null,
|
19
19
|
"link_text": null,
|
20
20
|
"link_url": null,
|
21
|
-
"
|
22
|
-
"
|
21
|
+
"avatar_url": null,
|
22
|
+
"bio": null
|
23
23
|
},
|
24
24
|
{
|
25
|
-
"alumnus": false,
|
26
|
-
"avatar_url": null,
|
27
|
-
"bio": null,
|
28
25
|
"github_username": "devonestes",
|
26
|
+
"alumnus": false,
|
27
|
+
"show_on_website": false,
|
28
|
+
"name": null,
|
29
29
|
"link_text": null,
|
30
30
|
"link_url": null,
|
31
|
-
"
|
32
|
-
"
|
31
|
+
"avatar_url": null,
|
32
|
+
"bio": null
|
33
33
|
}
|
34
34
|
]
|
35
|
-
}
|
35
|
+
}
|