trackler 2.0.8.43 → 2.0.8.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/ceylon/exercises/anagram/source/anagram/AnagramTest.ceylon +3 -2
  4. data/tracks/ceylon/exercises/bracket-push/source/bracketpush/BracketsTest.ceylon +3 -0
  5. data/tracks/ceylon/exercises/hamming/source/hamming/HammingTest.ceylon +16 -0
  6. data/tracks/ceylon/exercises/largest-series-product/source/largestseriesproduct/SeriesTest.ceylon +16 -0
  7. data/tracks/ceylon/exercises/leap/source/leap/LeapTest.ceylon +1 -0
  8. data/tracks/ceylon/exercises/react/source/react/ReactorTest.ceylon +2 -0
  9. data/tracks/ceylon/exercises/sieve/source/sieve/SieveTest.ceylon +1 -0
  10. data/tracks/crystal/exercises/sieve/src/example.cr +3 -2
  11. data/tracks/csharp/.github/stale.yml +0 -0
  12. data/tracks/csharp/exercises/house/HINTS.md +3 -0
  13. data/tracks/csharp/exercises/saddle-points/HINTS.md +4 -0
  14. data/tracks/fsharp/.github/stale.yml +0 -0
  15. data/tracks/go/.github/stale.yml +22 -0
  16. data/tracks/go/README.md +26 -15
  17. data/tracks/go/exercises/bob/{example_gen.go → .meta/gen.go} +1 -1
  18. data/tracks/go/exercises/bowling/{example_gen.go → .meta/gen.go} +1 -1
  19. data/tracks/go/exercises/change/{example_gen.go → .meta/gen.go} +1 -1
  20. data/tracks/go/exercises/clock/{example_gen.go → .meta/gen.go} +1 -1
  21. data/tracks/go/exercises/connect/{example_gen.go → .meta/gen.go} +1 -1
  22. data/tracks/go/exercises/custom-set/{example_gen.go → .meta/gen.go} +1 -1
  23. data/tracks/go/exercises/forth/.meta/gen.go +71 -0
  24. data/tracks/go/exercises/forth/cases_test.go +259 -236
  25. data/tracks/go/exercises/forth/forth_test.go +19 -34
  26. data/tracks/go/exercises/gigasecond/{example_gen.go → .meta/gen.go} +1 -1
  27. data/tracks/go/exercises/hamming/{example_gen.go → .meta/gen.go} +1 -1
  28. data/tracks/go/exercises/largest-series-product/{example_gen.go → .meta/gen.go} +1 -1
  29. data/tracks/go/exercises/leap/{example_gen.go → .meta/gen.go} +1 -1
  30. data/tracks/go/exercises/luhn/{example_gen.go → .meta/gen.go} +1 -1
  31. data/tracks/go/exercises/meetup/{example_gen.go → .meta/gen.go} +1 -1
  32. data/tracks/go/exercises/raindrops/{example_gen.go → .meta/gen.go} +1 -1
  33. data/tracks/go/exercises/rna-transcription/{example_gen.go → .meta/gen.go} +1 -1
  34. data/tracks/go/exercises/roman-numerals/{example_gen.go → .meta/gen.go} +1 -1
  35. data/tracks/go/exercises/transpose/{example_gen.go → .meta/gen.go} +1 -1
  36. data/tracks/go/exercises/word-count/{example_gen.go → .meta/gen.go} +1 -1
  37. data/tracks/go/gen/gen.go +9 -9
  38. data/tracks/purescript/config.json +7 -0
  39. data/tracks/purescript/exercises/binary-search/bower.json +16 -0
  40. data/tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs +19 -0
  41. data/tracks/purescript/exercises/binary-search/src/BinarySearch.purs +3 -0
  42. data/tracks/purescript/exercises/binary-search/test/Main.purs +53 -0
  43. data/tracks/python/config.json +6 -0
  44. data/tracks/python/exercises/rectangles/rectangles_test.py +68 -41
  45. data/tracks/python/exercises/transpose/example.py +6 -0
  46. data/tracks/python/exercises/transpose/transpose.py +2 -0
  47. data/tracks/python/exercises/transpose/transpose_test.py +264 -0
  48. metadata +32 -20
  49. data/tracks/go/exercises/forth/example_gen.go +0 -99
data/tracks/go/gen/gen.go CHANGED
@@ -26,11 +26,10 @@ import (
26
26
  // └── xgo
27
27
  var dirMetadata string
28
28
 
29
- // dirProblem is the location that the test cases should be generated to.
30
- // This assumes that the generator script lives in the same directory as
31
- // the problem.
32
- // Falls back to the present working directory.
33
- var dirProblem string
29
+ // dirExercise is the location that the test cases should be generated to.
30
+ // This assumes that the generator script lives in the .meta directory within
31
+ // the exercise directory. Falls back to the present working directory.
32
+ var dirExercise string
34
33
 
35
34
  // Header tells how the test data was generated, for display in the header of cases_test.go
36
35
  type Header struct {
@@ -58,13 +57,14 @@ func init() {
58
57
  dirMetadata = filepath.Join(path, "..", "..", "..", "x-common")
59
58
  }
60
59
  if _, path, _, ok := runtime.Caller(2); ok {
61
- dirProblem = filepath.Join(path, "..")
60
+ dirExercise = filepath.Join(path, "..", "..")
62
61
  }
63
- if dirProblem == "" {
64
- dirProblem = "."
62
+ if dirExercise == "" {
63
+ dirExercise = "."
65
64
  }
66
65
  }
67
66
 
67
+ // Gen generates the exercise cases_test.go file from the relevant canonical-data.json
68
68
  func Gen(exercise string, j interface{}, t *template.Template) error {
69
69
  if dirMetadata == "" {
70
70
  return errors.New("unable to determine current path")
@@ -116,7 +116,7 @@ func Gen(exercise string, j interface{}, t *template.Template) error {
116
116
  return err
117
117
  }
118
118
  // write output file for the Go test cases.
119
- return ioutil.WriteFile(filepath.Join(dirProblem, "cases_test.go"), src, 0666)
119
+ return ioutil.WriteFile(filepath.Join(dirExercise, "cases_test.go"), src, 0666)
120
120
  }
121
121
 
122
122
  func getPath(jFile string) (jPath, jOrigin, jCommit string) {
@@ -115,6 +115,13 @@
115
115
  "topics": [
116
116
  "base conversion"
117
117
  ]
118
+ },
119
+ {
120
+ "slug": "binary-search",
121
+ "difficulty": 1,
122
+ "topics": [
123
+ "binary search"
124
+ ]
118
125
  }
119
126
  ],
120
127
  "deprecated": [
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "binary-search",
3
+ "ignore": [
4
+ "**/.*",
5
+ "node_modules",
6
+ "bower_components",
7
+ "output"
8
+ ],
9
+ "dependencies": {
10
+ "purescript-prelude": "^2.5.0"
11
+ },
12
+ "devDependencies": {
13
+ "purescript-psci-support": "^2.0.0",
14
+ "purescript-test-unit": "^10.1.0"
15
+ }
16
+ }
@@ -0,0 +1,19 @@
1
+ module BinarySearch
2
+ ( find
3
+ ) where
4
+
5
+ import Prelude
6
+ import Data.Array (length, (!!))
7
+ import Data.Maybe (Maybe(Just, Nothing))
8
+
9
+ find :: Int -> Array Int -> Maybe Int
10
+ find i a = go 0 (length a - 1)
11
+ where go l h | l > h = Nothing
12
+ go l h =
13
+ let m = l + (h - l) / 2
14
+ in case a !! m of
15
+ Nothing -> Nothing
16
+ Just j | j == i -> Just m
17
+ | j < i -> go (m + 1) h
18
+ | otherwise -> go l (m - 1)
19
+
@@ -0,0 +1,3 @@
1
+ module BinarySearch
2
+ ( find
3
+ ) where
@@ -0,0 +1,53 @@
1
+ module Test.Main where
2
+
3
+ import Prelude
4
+ import Control.Monad.Eff (Eff)
5
+ import Data.Maybe (Maybe(..))
6
+ import Test.Unit.Assert as Assert
7
+ import Test.Unit (suite, test)
8
+ import Test.Unit.Main (runTest)
9
+ import BinarySearch (find)
10
+
11
+ main :: Eff _ Unit
12
+ main = runTest do
13
+ suite "BinarySearch.find" do
14
+
15
+ test "finds a value in an array with one element" $
16
+ Assert.equal (Just 0)
17
+ (find 6 [6])
18
+
19
+ test "finds a value in the middle of an array" $
20
+ Assert.equal (Just 3)
21
+ (find 6 [1,3,4,6,8,9,11])
22
+
23
+ test "finds a value at the beginning of an array" $
24
+ Assert.equal (Just 0)
25
+ (find 1 [1,3,4,6,8,9,11])
26
+
27
+ test "finds a value at the end of an array" $
28
+ Assert.equal (Just 6)
29
+ (find 11 [1,3,4,6,8,9,11])
30
+
31
+ test "finds a value in an array of odd length" $
32
+ Assert.equal (Just 9)
33
+ (find 144 [1,3,5,8,13,21,34,55,89,144,233,377,634])
34
+
35
+ test "finds a value in an array of even length" $
36
+ Assert.equal (Just 5)
37
+ (find 21 [1,3,5,8,13,21,34,55,89,144,233,377])
38
+
39
+ test "identifies that a value is not included in the array" $
40
+ Assert.equal Nothing
41
+ (find 7 [1,3,4,6,8,9,11])
42
+
43
+ test "a value smaller than the array's smallest value is not included" $
44
+ Assert.equal Nothing
45
+ (find 0 [1,3,4,6,8,9,11])
46
+
47
+ test "a value larger than the array's largest value is not included" $
48
+ Assert.equal Nothing
49
+ (find 13 [1,3,4,6,8,9,11])
50
+
51
+ test "nothing is included in an empty array" $
52
+ Assert.equal Nothing
53
+ (find 1 [])
@@ -380,6 +380,12 @@
380
380
  "topics": [
381
381
  ]
382
382
  },
383
+ {
384
+ "slug": "transpose",
385
+ "difficulty": 1,
386
+ "topics": [
387
+ ]
388
+ },
383
389
  {
384
390
  "slug": "poker",
385
391
  "difficulty": 1,
@@ -3,64 +3,91 @@ import unittest
3
3
  from rectangles import count
4
4
 
5
5
 
6
+ # test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
7
+
6
8
  class WordTest(unittest.TestCase):
7
- def test_zero_area_1(self):
8
- self.assertEqual(count(), 0)
9
+ def test_no_rows(self):
10
+ self.assertEqual(count([]), 0)
9
11
 
10
- def test_zero_area_2(self):
11
- lines = ""
12
- self.assertEqual(count(lines), 0)
12
+ def test_no_columns(self):
13
+ self.assertEqual(count(['']), 0)
13
14
 
14
- def test_empty_area(self):
15
- lines = " "
16
- self.assertEqual(count(lines), 0)
15
+ def test_no_rectangles(self):
16
+ self.assertEqual(count([' ']), 0)
17
17
 
18
18
  def test_one_rectangle(self):
19
- lines = ["+-+",
20
- "| |",
21
- "+-+"]
19
+ lines = ['+-+',
20
+ '| |',
21
+ '+-+']
22
22
  self.assertEqual(count(lines), 1)
23
23
 
24
- def test_two_rectangles_no_shared_parts(self):
25
- lines = [" +-+",
26
- " | |",
27
- "+-+-+",
28
- "| | ",
29
- "+-+ "]
24
+ def test_two_rectangles_without_shared_parts(self):
25
+ lines = [' +-+',
26
+ ' | |',
27
+ '+-+-+',
28
+ '| | ',
29
+ '+-+ ']
30
30
  self.assertEqual(count(lines), 2)
31
31
 
32
- def test_five_rectangles_three_regions(self):
33
- lines = [" +-+",
34
- " | |",
35
- "+-+-+",
36
- "| | |",
37
- "+-+-+"]
32
+ def test_five_rectangles_with_shared_parts(self):
33
+ lines = [' +-+',
34
+ ' | |',
35
+ '+-+-+',
36
+ '| | |',
37
+ '+-+-+']
38
38
  self.assertEqual(count(lines), 5)
39
39
 
40
- def test_incomplete_rectangles(self):
41
- lines = [" +-+",
42
- " |",
43
- "+-+-+",
44
- "| | -",
45
- "+-+-+"]
40
+ def test_rectangle_of_height_1_is_counted(self):
41
+ lines = ['+--+',
42
+ '+--+']
43
+ self.assertEqual(count(lines), 1)
44
+
45
+ def test_rectangle_of_width_1_is_counted(self):
46
+ lines = ['++',
47
+ '||',
48
+ '++']
49
+ self.assertEqual(count(lines), 1)
50
+
51
+ def test_1x1_square_is_counted(self):
52
+ lines = ['++',
53
+ '++']
54
+ self.assertEqual(count(lines), 1)
55
+
56
+ def test_only_complete_rectangles_are_counted(self):
57
+ lines = [' +-+',
58
+ ' |',
59
+ '+-+-+',
60
+ '| | -',
61
+ '+-+-+']
46
62
  self.assertEqual(count(lines), 1)
47
63
 
48
- def test_complicated(self):
49
- lines = ["+------+----+",
50
- "| | |",
51
- "+---+--+ |",
52
- "| | |",
53
- "+---+-------+"]
64
+ def test_rectangles_can_be_of_different_sizes(self):
65
+ lines = ['+------+----+',
66
+ '| | |',
67
+ '+---+--+ |',
68
+ '| | |',
69
+ '+---+-------+']
54
70
  self.assertEqual(count(lines), 3)
55
71
 
56
- def test_not_so_complicated(self):
57
- lines = ["+------+----+",
58
- "| | |",
59
- "+------+ |",
60
- "| | |",
61
- "+---+-------+"]
72
+ def test_corner_is_required_for_a_rectangle_to_be_complete(self):
73
+ lines = ['+------+----+',
74
+ '| | |',
75
+ '+------+ |',
76
+ '| | |',
77
+ '+---+-------+']
62
78
  self.assertEqual(count(lines), 2)
63
79
 
80
+ def test_large_input_with_many_rectangles(self):
81
+ lines = ['+---+--+----+',
82
+ '| +--+----+',
83
+ '+---+--+ |',
84
+ '| +--+----+',
85
+ '+---+--+--+-+',
86
+ '+---+--+--+-+',
87
+ '+------+ | |',
88
+ ' +-+']
89
+ self.assertEqual(count(lines), 60)
90
+
64
91
 
65
92
  if __name__ == '__main__':
66
93
  unittest.main()
@@ -0,0 +1,6 @@
1
+ def transpose(input_lines):
2
+ lines = input_lines.split("\n")
3
+ zipped = map(list,
4
+ [line.ljust(len(max(lines, key=len)))
5
+ for line in lines])
6
+ return "\n".join("".join(line) for line in zip(*zipped)).strip()
@@ -0,0 +1,2 @@
1
+ def transpose():
2
+ pass
@@ -0,0 +1,264 @@
1
+ import unittest
2
+ from transpose import transpose
3
+
4
+
5
+ # test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
6
+
7
+ class TransposeTests(unittest.TestCase):
8
+ def test_empty_string(self):
9
+ input_line = ""
10
+ expected = ""
11
+ self.assertEqual(
12
+ transpose(input_line),
13
+ expected
14
+ )
15
+
16
+ def test_two_characters_in_a_row(self):
17
+ self.assertEqual(
18
+ transpose("A1"),
19
+ "\n".join(["A", "1"])
20
+ )
21
+
22
+ def test_two_characters_in_a_column(self):
23
+ self.assertEqual(
24
+ transpose("\n".join(["A", "1"])),
25
+ "A1"
26
+ )
27
+
28
+ def test_simple(self):
29
+ input_line = [
30
+ "ABC",
31
+ "123"
32
+ ]
33
+ expected = [
34
+ "A1",
35
+ "B2",
36
+ "C3"
37
+ ]
38
+
39
+ self.assertEqual(
40
+ transpose("\n".join(input_line)),
41
+ "\n".join(expected)
42
+ )
43
+
44
+ def test_single_line(self):
45
+ input_line = ["Single line."]
46
+ expected = [
47
+ "S",
48
+ "i",
49
+ "n",
50
+ "g",
51
+ "l",
52
+ "e",
53
+ " ",
54
+ "l",
55
+ "i",
56
+ "n",
57
+ "e",
58
+ "."
59
+ ]
60
+ self.assertEqual(
61
+ transpose("\n".join(input_line)),
62
+ "\n".join(expected)
63
+ )
64
+
65
+ def test_first_line_longer_than_second_line(self):
66
+ input_line = [
67
+ "The fourth line.",
68
+ "The fifth line."
69
+ ]
70
+ expected = [
71
+ "TT",
72
+ "hh",
73
+ "ee",
74
+ " ",
75
+ "ff",
76
+ "oi",
77
+ "uf",
78
+ "rt",
79
+ "th",
80
+ "h ",
81
+ " l",
82
+ "li",
83
+ "in",
84
+ "ne",
85
+ "e.",
86
+ "."
87
+ ]
88
+ self.assertEqual(
89
+ transpose("\n".join(input_line)),
90
+ "\n".join(expected)
91
+ )
92
+
93
+ def test_second_line_longer_than_first_line(self):
94
+ input_line = [
95
+ "The first line.",
96
+ "The second line."
97
+ ]
98
+ expected = [
99
+ "TT",
100
+ "hh",
101
+ "ee",
102
+ " ",
103
+ "fs",
104
+ "ie",
105
+ "rc",
106
+ "so",
107
+ "tn",
108
+ " d",
109
+ "l ",
110
+ "il",
111
+ "ni",
112
+ "en",
113
+ ".e",
114
+ " ."
115
+ ]
116
+ self.assertEqual(
117
+ transpose("\n".join(input_line)),
118
+ "\n".join(expected)
119
+ )
120
+
121
+ def test_square(self):
122
+ input_line = [
123
+ "HEART",
124
+ "EMBER",
125
+ "ABUSE",
126
+ "RESIN",
127
+ "TREND"
128
+ ]
129
+ expected = [
130
+ "HEART",
131
+ "EMBER",
132
+ "ABUSE",
133
+ "RESIN",
134
+ "TREND"
135
+ ]
136
+ self.assertEqual(
137
+ transpose("\n".join(input_line)),
138
+ "\n".join(expected)
139
+ )
140
+
141
+ def test_rectangle(self):
142
+ input_line = [
143
+ "FRACTURE",
144
+ "OUTLINED",
145
+ "BLOOMING",
146
+ "SEPTETTE"
147
+ ]
148
+ expected = [
149
+ "FOBS",
150
+ "RULE",
151
+ "ATOP",
152
+ "CLOT",
153
+ "TIME",
154
+ "UNIT",
155
+ "RENT",
156
+ "EDGE"
157
+ ]
158
+ self.assertEqual(
159
+ transpose("\n".join(input_line)),
160
+ "\n".join(expected)
161
+ )
162
+
163
+ def test_triangle(self):
164
+ input_line = [
165
+ "T",
166
+ "EE",
167
+ "AAA",
168
+ "SSSS",
169
+ "EEEEE",
170
+ "RRRRRR"
171
+ ]
172
+ expected = [
173
+ "TEASER",
174
+ " EASER",
175
+ " ASER",
176
+ " SER",
177
+ " ER",
178
+ " R"
179
+ ]
180
+ self.assertEqual(
181
+ transpose("\n".join(input_line)),
182
+ "\n".join(expected)
183
+ )
184
+
185
+ def test_many_lines(self):
186
+ input_line = [
187
+ "Chor. Two households, both alike in dignity,",
188
+ "In fair Verona, where we lay our scene,",
189
+ "From ancient grudge break to new mutiny,",
190
+ "Where civil blood makes civil hands unclean.",
191
+ "From forth the fatal loins of these two foes",
192
+ "A pair of star-cross'd lovers take their life;",
193
+ "Whose misadventur'd piteous overthrows",
194
+ "Doth with their death bury their parents' strife.",
195
+ "The fearful passage of their death-mark'd love,",
196
+ "And the continuance of their parents' rage,",
197
+ "Which, but their children's end, naught could remove,",
198
+ "Is now the two hours' traffic of our stage;",
199
+ "The which if you with patient ears attend,",
200
+ "What here shall miss, our toil shall strive to mend."
201
+ ]
202
+ expected = [
203
+ "CIFWFAWDTAWITW",
204
+ "hnrhr hohnhshh",
205
+ "o oeopotedi ea",
206
+ "rfmrmash cn t",
207
+ ".a e ie fthow ",
208
+ " ia fr weh,whh",
209
+ "Trnco miae ie",
210
+ "w ciroitr btcr",
211
+ "oVivtfshfcuhhe",
212
+ " eeih a uote ",
213
+ "hrnl sdtln is",
214
+ "oot ttvh tttfh",
215
+ "un bhaeepihw a",
216
+ "saglernianeoyl",
217
+ "e,ro -trsui ol",
218
+ "h uofcu sarhu ",
219
+ "owddarrdan o m",
220
+ "lhg to'egccuwi",
221
+ "deemasdaeehris",
222
+ "sr als t ists",
223
+ ",ebk 'phool'h,",
224
+ " reldi ffd ",
225
+ "bweso tb rtpo",
226
+ "oea ileutterau",
227
+ "t kcnoorhhnatr",
228
+ "hl isvuyee'fi ",
229
+ " atv es iisfet",
230
+ "ayoior trr ino",
231
+ "l lfsoh ecti",
232
+ "ion vedpn l",
233
+ "kuehtteieadoe ",
234
+ "erwaharrar,fas",
235
+ " nekt te rh",
236
+ "ismdsehphnnosa",
237
+ "ncuse ra-tau l",
238
+ " et tormsural",
239
+ "dniuthwea'g t ",
240
+ "iennwesnr hsts",
241
+ "g,ycoi tkrttet",
242
+ "n ,l r s'a anr",
243
+ "i ef 'dgcgdi",
244
+ "t aol eoe,v",
245
+ "y nei sl,u; e",
246
+ ", .sf to l ",
247
+ " e rv d t",
248
+ " ; ie o",
249
+ " f, r ",
250
+ " e e m",
251
+ " . m e",
252
+ " o n",
253
+ " v d",
254
+ " e .",
255
+ " ,"
256
+ ]
257
+ self.assertEqual(
258
+ transpose("\n".join(input_line)),
259
+ "\n".join(expected)
260
+ )
261
+
262
+
263
+ if __name__ == '__main__':
264
+ unittest.main()