trackler 2.0.6.19 → 2.0.6.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/csharp/config.json +8 -0
  4. data/tracks/csharp/exercises/forth/Example.cs +257 -0
  5. data/tracks/csharp/exercises/forth/ForthTest.cs +134 -0
  6. data/tracks/fsharp/config.json +7 -1
  7. data/tracks/fsharp/exercises/exercises.fsproj +20 -0
  8. data/tracks/fsharp/exercises/lens-person/Example.fs +50 -0
  9. data/tracks/fsharp/exercises/lens-person/HINTS.md +2 -0
  10. data/tracks/fsharp/exercises/lens-person/LensPerson.fs +24 -0
  11. data/tracks/fsharp/exercises/lens-person/LensPersonTest.fs +43 -0
  12. data/tracks/fsharp/exercises/paket.references +2 -1
  13. data/tracks/fsharp/paket.dependencies +1 -0
  14. data/tracks/fsharp/paket.lock +1 -0
  15. data/tracks/javascript/exercises/{bob/bob.js → leap/leap.js} +3 -3
  16. data/tracks/julia/README.md +16 -0
  17. data/tracks/objective-c/config.json +17 -0
  18. data/tracks/objective-c/exercises/bracket-push/BracketPushExample.h +8 -0
  19. data/tracks/objective-c/exercises/bracket-push/BracketPushExample.m +386 -0
  20. data/tracks/objective-c/exercises/bracket-push/BracketPushTest.m +84 -0
  21. data/tracks/objective-c/exercises/sublist/SublistExample.h +7 -0
  22. data/tracks/objective-c/exercises/sublist/SublistExample.m +67 -0
  23. data/tracks/objective-c/exercises/sublist/SublistTest.m +139 -0
  24. data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/project.pbxproj +55 -2
  25. data/tracks/ocaml/exercises/dominoes/test.ml +11 -5
  26. data/tracks/ocaml/exercises/luhn/test.ml +3 -3
  27. data/tracks/ocaml/tools/test-generator/templates/dominoes/template.ml +11 -5
  28. data/tracks/pascal/config.json +1 -1
  29. data/tracks/pascal/docs/INSTALLATION.md +52 -0
  30. data/tracks/pascal/docs/img/00delphiwelcomepage.png +0 -0
  31. data/tracks/pascal/docs/img/01delphiclicktools.png +0 -0
  32. data/tracks/pascal/docs/img/02delphiclickoptions.png +0 -0
  33. data/tracks/pascal/docs/img/03delphioptionsenvironmentvariables.png +0 -0
  34. data/tracks/pascal/docs/img/04delphioptionsenvironmentvariablesclicknew.png +0 -0
  35. data/tracks/pascal/docs/img/05delphinewuservariable.png +0 -0
  36. data/tracks/pascal/docs/img/06delphioptionslibrary.png +0 -0
  37. data/tracks/pascal/docs/img/07delphiclicklibrarypathbutton.png +0 -0
  38. data/tracks/pascal/docs/img/08delphidirectoriesinputvarnameclickadd.png +0 -0
  39. data/tracks/pascal/docs/img/09delphidirectoriesclickok.png +0 -0
  40. data/tracks/pascal/docs/img/10delphioptonsclickok.png +0 -0
  41. data/tracks/pascal/exercises/nucleotide-count/uNucleotideCountExample.pas +9 -18
  42. data/tracks/pascal/exercises/nucleotide-count/uNucleotideCountTest.pas +16 -16
  43. data/tracks/php/config.json +7 -0
  44. data/tracks/php/exercises/book-store/book-store_test.php +146 -0
  45. data/tracks/php/exercises/book-store/example.php +38 -0
  46. data/tracks/swift/docs/TESTS.md +40 -35
  47. data/tracks/swift/docs/img/tests-fail.png +0 -0
  48. data/tracks/swift/docs/img/tests-pass.png +0 -0
  49. data/tracks/swift/docs/img/tests.png +0 -0
  50. metadata +28 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8623ef341a6390932eb5e0f88373f12e87dddd8e
4
- data.tar.gz: 14daf2f37b0190a64c8edf17ffa28cf39a25d961
3
+ metadata.gz: a74906359ef6716f5ba79719f22de614e19f79a7
4
+ data.tar.gz: ae56be98e926ec4f4cf082af5c727a0f842b8eb0
5
5
  SHA512:
6
- metadata.gz: a01f8a0581847e5513dcd1f48ab9766b70753042174c717b97269da1af841184dbeb4ced3be2053ec2dae9376741a6e2c176bee7848160028f535b591941b8c2
7
- data.tar.gz: be768c3c71174ab29c6922f2f31c5fdf754616b0d58b69ae94b0ea7c6a92837c130184d41d72c5c5f842491f4d17b99eeaef4a42c2e633f57a2235143117b9c5
6
+ metadata.gz: 7b4bb7fc87665af298f845160c685eef1d49480443b61f4f98be954bcfda314cc145230bf62c0f7b16ab3cbcc5873ca0698f116a3c30379ef101ca3cec44a232
7
+ data.tar.gz: 3be91f09a9535cab6a09afa6911fdd262bcac4dc28b36cf1ff400a71b2a83f28888a08134c1a6653d5459b6311c18b10eb5be070621664fa131898339410d5d6
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.0.6.19"
2
+ VERSION = "2.0.6.20"
3
3
  end
@@ -831,6 +831,14 @@
831
831
  "Dictionaries"
832
832
  ]
833
833
  },
834
+ {
835
+ "slug": "forth",
836
+ "difficulty": 10,
837
+ "topics": [
838
+ "Parsing",
839
+ "Stacks"
840
+ ]
841
+ },
834
842
  {
835
843
  "slug": "pov",
836
844
  "difficulty": 10,
@@ -0,0 +1,257 @@
1
+ using System;
2
+ using System.Linq;
3
+ using System.Collections.Generic;
4
+ using Sprache;
5
+
6
+ public enum ForthError
7
+ {
8
+ DivisionByZero,
9
+ StackUnderflow,
10
+ InvalidWord,
11
+ UnknownWord
12
+ }
13
+
14
+ public class ForthException : Exception
15
+ {
16
+ public ForthException(ForthError error)
17
+ {
18
+ Error = error;
19
+ }
20
+
21
+ public ForthError Error { get; }
22
+ }
23
+
24
+ public class ForthState
25
+ {
26
+ public Stack<int> Stack { get; } = new Stack<int>();
27
+ public Dictionary<string, IEnumerable<ForthDefinition>> Mapping { get; } = new Dictionary<string, IEnumerable<ForthDefinition>>();
28
+
29
+ public override string ToString() => string.Join(" ", Stack.Reverse());
30
+ }
31
+
32
+ public abstract class ForthDefinition
33
+ {
34
+ public abstract void Evaluate(ForthState state);
35
+ }
36
+
37
+ public abstract class TermDefinition : ForthDefinition
38
+ {
39
+ public TermDefinition(string term)
40
+ {
41
+ Term = term;
42
+ }
43
+
44
+ public string Term { get; }
45
+
46
+ public override void Evaluate(ForthState state)
47
+ {
48
+ if (IsUserTerm(state))
49
+ EvaluateUserTerm(state);
50
+ else
51
+ EvaluateDefaultTerm(state);
52
+ }
53
+
54
+ private bool IsUserTerm(ForthState state) => state.Mapping.ContainsKey(Term);
55
+
56
+ public virtual void EvaluateUserTerm(ForthState state)
57
+ {
58
+ foreach (var definition in state.Mapping[Term])
59
+ definition.Evaluate(state);
60
+ }
61
+
62
+ public abstract void EvaluateDefaultTerm(ForthState state);
63
+ }
64
+
65
+ public abstract class UnaryOperation: TermDefinition
66
+ {
67
+ public UnaryOperation(string term) : base(term)
68
+ {
69
+ }
70
+
71
+ public override void EvaluateDefaultTerm(ForthState state)
72
+ {
73
+ if (state.Stack.Count < 1)
74
+ throw new ForthException(ForthError.StackUnderflow);
75
+
76
+ var operand = state.Stack.Pop();
77
+
78
+ foreach (var value in operation(operand))
79
+ state.Stack.Push(value);
80
+ }
81
+
82
+ public abstract List<int> operation(int x);
83
+ }
84
+
85
+ public abstract class BinaryOperation : TermDefinition
86
+ {
87
+ public BinaryOperation(string term) : base(term)
88
+ {
89
+ }
90
+
91
+ public override void EvaluateDefaultTerm(ForthState state)
92
+ {
93
+ if (state.Stack.Count <= 1)
94
+ throw new ForthException(ForthError.StackUnderflow);
95
+
96
+ var operand2 = state.Stack.Pop();
97
+ var operand1 = state.Stack.Pop();
98
+
99
+ foreach (var value in operation(operand1, operand2))
100
+ state.Stack.Push(value);
101
+ }
102
+
103
+ public abstract List<int> operation(int x, int y);
104
+ }
105
+
106
+ public class Constant : ForthDefinition
107
+ {
108
+ private readonly int n;
109
+
110
+ public Constant(int n)
111
+ {
112
+ this.n = n;
113
+ }
114
+
115
+ public override void Evaluate(ForthState state) => state.Stack.Push(n);
116
+ }
117
+
118
+ public class Word : TermDefinition
119
+ {
120
+ public Word(string str) : base(str)
121
+ {
122
+ }
123
+
124
+ public override void EvaluateDefaultTerm(ForthState state)
125
+ {
126
+ if (!state.Mapping.ContainsKey(Term))
127
+ throw new ForthException(ForthError.UnknownWord);
128
+ }
129
+ }
130
+
131
+ public class Dup: UnaryOperation
132
+ {
133
+ public Dup() : base("dup") {}
134
+ public override List<int> operation(int x) => new List<int> { x, x };
135
+ }
136
+
137
+ public class Drop : UnaryOperation
138
+ {
139
+ public Drop() : base("drop") {}
140
+ public override List<int> operation(int x) => new List<int>();
141
+ }
142
+
143
+ public class Swap : BinaryOperation
144
+ {
145
+ public Swap() : base("swap") {}
146
+ public override List<int> operation(int x, int y) => new List<int> { y, x };
147
+ }
148
+
149
+ public class Over : BinaryOperation
150
+ {
151
+ public Over() : base("over") {}
152
+ public override List<int> operation(int x, int y) => new List<int> { x, y, x };
153
+ }
154
+
155
+ public class Plus : BinaryOperation
156
+ {
157
+ public Plus() : base("+") {}
158
+ public override List<int> operation(int x, int y) => new List<int> { x + y };
159
+ }
160
+
161
+ public class Minus : BinaryOperation
162
+ {
163
+ public Minus() : base("-") {}
164
+ public override List<int> operation(int x, int y) => new List<int> { x - y };
165
+ }
166
+
167
+ public class Multiply : BinaryOperation
168
+ {
169
+ public Multiply() : base("*") {}
170
+ public override List<int> operation(int x, int y) => new List<int> { x * y };
171
+ }
172
+
173
+ public class Division : BinaryOperation
174
+ {
175
+ public Division() : base("/") {}
176
+
177
+ public override List<int> operation(int x, int y)
178
+ {
179
+ if (y == 0)
180
+ throw new ForthException(ForthError.DivisionByZero);
181
+
182
+ return new List<int> { x / y };
183
+ }
184
+ }
185
+
186
+ public class CustomTerm : ForthDefinition
187
+ {
188
+ private readonly string term;
189
+ private readonly IEnumerable<ForthDefinition> actions;
190
+
191
+ public CustomTerm(string term, IEnumerable<ForthDefinition> actions)
192
+ {
193
+ this.term = term;
194
+ this.actions = actions;
195
+ }
196
+
197
+ public override void Evaluate(ForthState state)
198
+ {
199
+ int result;
200
+ if (int.TryParse(term, out result))
201
+ throw new ForthException(ForthError.InvalidWord);
202
+
203
+ state.Mapping[term] = actions;
204
+ }
205
+ }
206
+
207
+ public static class Forth
208
+ {
209
+ public static string Eval(string input)
210
+ {
211
+ var expression = Expression.Parse(input);
212
+ var state = new ForthState();
213
+
214
+ foreach (var definition in expression)
215
+ definition.Evaluate(state);
216
+
217
+ return state.ToString();
218
+ }
219
+
220
+ private static readonly Parser<Constant> Constant =
221
+ from number in Parse.Number
222
+ from whitespace in Parse.WhiteSpace.Optional()
223
+ select new Constant(int.Parse(number));
224
+
225
+ private static readonly Parser<string> TermIdentifier =
226
+ from term in Parse.Regex(@"[^\s;]+")
227
+ from whitespace in Parse.WhiteSpace.Optional()
228
+ select term.ToLowerInvariant();
229
+
230
+ private static readonly Parser<ForthDefinition> Term = TermIdentifier.Select<string, ForthDefinition>(term =>
231
+ {
232
+ switch (term)
233
+ {
234
+ case "+": return new Plus();
235
+ case "-": return new Minus();
236
+ case "*": return new Multiply();
237
+ case "/": return new Division();
238
+ case "dup": return new Dup();
239
+ case "drop": return new Drop();
240
+ case "swap": return new Swap();
241
+ case "over": return new Over();
242
+ default: return new Word(term);
243
+ }
244
+ });
245
+
246
+ private static readonly Parser<ForthDefinition> CustomTerm =
247
+ from a in Parse.Char(':')
248
+ from b in Parse.WhiteSpace
249
+ from customTerm in TermIdentifier
250
+ from definitions in Constant.XOr(Term).AtLeastOnce()
251
+ from d in Parse.Char(';')
252
+ from e in Parse.WhiteSpace.Optional()
253
+ select new CustomTerm(customTerm, definitions);
254
+
255
+ private static readonly Parser<IEnumerable<ForthDefinition>> Expression =
256
+ (CustomTerm.XOr(Constant).XOr(Term)).Many();
257
+ }
@@ -0,0 +1,134 @@
1
+ using NUnit.Framework;
2
+
3
+ public class ForthTest
4
+ {
5
+ [Test]
6
+ public void No_input()
7
+ {
8
+ Assert.That(Forth.Eval(""), Is.EqualTo(""));
9
+ }
10
+
11
+ [Ignore("Remove to run test")]
12
+ [Test]
13
+ public void Numbers_just_get_pushed_onto_the_stack()
14
+ {
15
+ Assert.That(Forth.Eval("1 2 3 4 5"), Is.EqualTo("1 2 3 4 5"));
16
+ }
17
+
18
+ [Ignore("Remove to run test")]
19
+ [Test]
20
+ public void Non_word_characters_are_separators()
21
+ {
22
+ Assert.That(Forth.Eval("1\v2\t3\n4\r5 6\t7"), Is.EqualTo("1 2 3 4 5 6 7"));
23
+ }
24
+
25
+ [Ignore("Remove to run test")]
26
+ [Test]
27
+ public void Basic_arithmetic()
28
+ {
29
+ Assert.That(Forth.Eval("1 2 + 4 -"), Is.EqualTo("-1"));
30
+ Assert.That(Forth.Eval("2 4 * 3 /"), Is.EqualTo("2"));
31
+ }
32
+
33
+ [Ignore("Remove to run test")]
34
+ [Test]
35
+ public void Division_by_zero()
36
+ {
37
+ var exception = Assert.Throws<ForthException>(() => Forth.Eval("4 2 2 - /"));
38
+ Assert.That(exception.Error, Is.EqualTo(ForthError.DivisionByZero));
39
+ }
40
+
41
+ [Ignore("Remove to run test")]
42
+ [Test]
43
+ public void dup()
44
+ {
45
+ Assert.That(Forth.Eval("1 DUP"), Is.EqualTo("1 1"));
46
+ Assert.That(Forth.Eval("1 2 Dup"), Is.EqualTo("1 2 2"));
47
+
48
+ var exception = Assert.Throws<ForthException>(() => Forth.Eval("dup"));
49
+ Assert.That(exception.Error, Is.EqualTo(ForthError.StackUnderflow));
50
+ }
51
+
52
+ [Ignore("Remove to run test")]
53
+ [Test]
54
+ public void drop()
55
+ {
56
+ Assert.That(Forth.Eval("1 drop"), Is.EqualTo(""));
57
+ Assert.That(Forth.Eval("1 2 drop"), Is.EqualTo("1"));
58
+
59
+ var exception = Assert.Throws<ForthException>(() => Forth.Eval("drop"));
60
+ Assert.That(exception.Error, Is.EqualTo(ForthError.StackUnderflow));
61
+ }
62
+
63
+ [Ignore("Remove to run test")]
64
+ [Test]
65
+ public void swap()
66
+ {
67
+ Assert.That(Forth.Eval("1 2 swap"), Is.EqualTo("2 1"));
68
+ Assert.That(Forth.Eval("1 2 3 swap"), Is.EqualTo("1 3 2"));
69
+
70
+ var exception1 = Assert.Throws<ForthException>(() => Forth.Eval("1 swap"));
71
+ Assert.That(exception1.Error, Is.EqualTo(ForthError.StackUnderflow));
72
+
73
+ var exception2 = Assert.Throws<ForthException>(() => Forth.Eval("swap"));
74
+ Assert.That(exception2.Error, Is.EqualTo(ForthError.StackUnderflow));
75
+ }
76
+
77
+ [Ignore("Remove to run test")]
78
+ [Test]
79
+ public void over()
80
+ {
81
+ Assert.That(Forth.Eval("1 2 over"), Is.EqualTo("1 2 1"));
82
+ Assert.That(Forth.Eval("1 2 3 over"), Is.EqualTo("1 2 3 2"));
83
+
84
+ var exception1 = Assert.Throws<ForthException>(() => Forth.Eval("1 over"));
85
+ Assert.That(exception1.Error, Is.EqualTo(ForthError.StackUnderflow));
86
+
87
+ var exception2 = Assert.Throws<ForthException>(() => Forth.Eval("over"));
88
+ Assert.That(exception2.Error, Is.EqualTo(ForthError.StackUnderflow));
89
+ }
90
+
91
+ [Ignore("Remove to run test")]
92
+ [Test]
93
+ public void Defining_a_new_word()
94
+ {
95
+ Assert.That(Forth.Eval(": dup-twice dup dup ; 1 dup-twice"), Is.EqualTo("1 1 1"));
96
+ }
97
+
98
+ [Ignore("Remove to run test")]
99
+ [Test]
100
+ public void Redefining_an_existing_word()
101
+ {
102
+ Assert.That(Forth.Eval(": foo dup ; : foo dup dup ; 1 foo"), Is.EqualTo("1 1 1"));
103
+ }
104
+
105
+ [Ignore("Remove to run test")]
106
+ [Test]
107
+ public void Redefining_an_existing_built_in_word()
108
+ {
109
+ Assert.That(Forth.Eval(": swap dup ; 1 swap"), Is.EqualTo("1 1"));
110
+ }
111
+
112
+ [Ignore("Remove to run test")]
113
+ [Test]
114
+ public void Defining_words_with_odd_characters()
115
+ {
116
+ Assert.That(Forth.Eval(": € 220371 ; €"), Is.EqualTo("220371"));
117
+ }
118
+
119
+ [Ignore("Remove to run test")]
120
+ [Test]
121
+ public void Defining_a_number()
122
+ {
123
+ var exception = Assert.Throws<ForthException>(() => Forth.Eval(": 1 2 ;"));
124
+ Assert.That(exception.Error, Is.EqualTo(ForthError.InvalidWord));
125
+ }
126
+
127
+ [Ignore("Remove to run test")]
128
+ [Test]
129
+ public void Calling_a_non_existing_word()
130
+ {
131
+ var exception = Assert.Throws<ForthException>(() => Forth.Eval("1 foo"));
132
+ Assert.That(exception.Error, Is.EqualTo(ForthError.UnknownWord));
133
+ }
134
+ }
@@ -795,6 +795,13 @@
795
795
  "Optional values"
796
796
  ]
797
797
  },
798
+ {
799
+ "slug": "lens-person",
800
+ "difficulty": 9,
801
+ "topics": [
802
+ "Lenses"
803
+ ]
804
+ },
798
805
  {
799
806
  "slug": "sgf-parsing",
800
807
  "difficulty": 9,
@@ -850,7 +857,6 @@
850
857
  ],
851
858
  "foregone": [
852
859
  "flatten-array",
853
- "lens-person",
854
860
  "nucleotide-codons",
855
861
  "paasio",
856
862
  "point-mutations",