trackler 2.0.8.54 → 2.0.8.55
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/common/CONTRIBUTING.md +7 -6
- data/fixtures/tracks/animal/config.json +1 -0
- data/fixtures/tracks/animal/exercises/dog/a_test_example_for.animal +1 -0
- data/lib/trackler/implementation.rb +32 -38
- data/lib/trackler/implementations.rb +2 -2
- data/lib/trackler/track.rb +24 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/elixir/config.json +17 -0
- data/tracks/elixir/exercises/bracket-push/bracket_push_test.exs +34 -19
- data/tracks/elixir/exercises/saddle-points/example.exs +1 -1
- data/tracks/elixir/exercises/saddle-points/saddle_points.exs +1 -1
- data/tracks/elixir/exercises/saddle-points/saddle_points_test.exs +10 -10
- data/tracks/elixir/exercises/simple-cipher/example.exs +80 -0
- data/tracks/elixir/exercises/simple-cipher/simple_cipher.exs +49 -0
- data/tracks/elixir/exercises/simple-cipher/simple_cipher_test.exs +89 -0
- data/tracks/elixir/exercises/tournament/HINTS.md +3 -0
- data/tracks/elixir/exercises/tournament/example.exs +81 -0
- data/tracks/elixir/exercises/tournament/tournament.exs +17 -0
- data/tracks/elixir/exercises/tournament/tournament_test.exs +96 -0
- data/tracks/go/exercises/bob/bob.go +2 -2
- data/tracks/go/exercises/clock/clock.go +1 -8
- data/tracks/go/exercises/gigasecond/gigasecond.go +4 -6
- data/tracks/go/exercises/hamming/hamming.go +0 -1
- data/tracks/go/exercises/raindrops/raindrops.go +2 -1
- data/tracks/go/exercises/triangle/triangle.go +1 -2
- data/tracks/java/bin/journey-test.sh +6 -5
- data/tracks/java/exercises/nth-prime/src/example/java/PrimeCalculator.java +1 -5
- data/tracks/java/exercises/rna-transcription/src/test/java/RnaTranscriptionTest.java +5 -5
- data/tracks/pony/.github/stale.yml +0 -0
- data/tracks/pony/.travis.yml +2 -9
- data/tracks/pony/bin/install-deps +15 -8
- data/tracks/pony/bin/test-exercises +2 -0
- data/tracks/pony/config.json +2 -1
- data/tracks/pony/exercises/anagram/example.pony +1 -1
- data/tracks/pony/exercises/anagram/test.pony +2 -2
- data/tracks/pony/exercises/atbash-cipher/example.pony +6 -4
- data/tracks/pony/exercises/atbash-cipher/test.pony +24 -38
- data/tracks/pony/exercises/pascals-triangle/test.pony +3 -3
- data/tracks/pony/exercises/rna-transcription/test.pony +4 -4
- data/tracks/pony/exercises/roman-numerals/example.pony +12 -12
- data/tracks/pony/exercises/roman-numerals/test.pony +18 -18
- data/tracks/purescript/config.json +15 -0
- data/tracks/purescript/exercises/etl/bower.json +17 -0
- data/tracks/purescript/exercises/etl/examples/src/Etl.purs +20 -0
- data/tracks/purescript/exercises/etl/src/Etl.purs +3 -0
- data/tracks/purescript/exercises/etl/test/Main.purs +99 -0
- data/tracks/purescript/exercises/isogram/bower.json +18 -0
- data/tracks/purescript/exercises/isogram/examples/src/Isogram.purs +22 -0
- data/tracks/purescript/exercises/isogram/src/Isogram.purs +4 -0
- data/tracks/purescript/exercises/isogram/test/Main.purs +44 -0
- data/tracks/ruby/README.md +10 -9
- data/tracks/ruby/exercises/anagram/example.tt +1 -1
- data/tracks/ruby/exercises/bowling/example.tt +1 -1
- data/tracks/ruby/exercises/hamming/example.tt +2 -2
- data/tracks/ruby/exercises/luhn/.meta/.version +1 -0
- data/tracks/ruby/exercises/luhn/example.rb +18 -23
- data/tracks/ruby/exercises/luhn/example.tt +18 -0
- data/tracks/ruby/exercises/luhn/luhn_test.rb +60 -27
- data/tracks/ruby/exercises/pig-latin/.meta/.version +1 -0
- data/tracks/ruby/exercises/pig-latin/example.rb +4 -0
- data/tracks/ruby/exercises/pig-latin/example.tt +21 -0
- data/tracks/ruby/exercises/pig-latin/pig_latin_test.rb +73 -24
- data/tracks/ruby/exercises/rna-transcription/example.tt +1 -1
- data/tracks/ruby/lib/anagram_cases.rb +1 -1
- data/tracks/ruby/lib/binary_cases.rb +3 -3
- data/tracks/ruby/lib/bowling_cases.rb +1 -1
- data/tracks/ruby/lib/hamming_cases.rb +1 -1
- data/tracks/ruby/lib/luhn_cases.rb +27 -0
- data/tracks/ruby/lib/pig_latin_cases.rb +20 -0
- data/tracks/ruby/lib/rna_transcription_cases.rb +1 -1
- metadata +25 -3
- data/tracks/go/.github/stale.yml +0 -22
@@ -9,18 +9,18 @@ primitive RomanNumerals
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let numerals: Array[(USize, String)] = [
|
12
|
-
(1000, "M")
|
13
|
-
(900, "CM")
|
14
|
-
(500, "D")
|
15
|
-
(400, "CD")
|
16
|
-
(100, "C")
|
17
|
-
(90, "XC")
|
18
|
-
(50, "L")
|
19
|
-
(40, "XL")
|
20
|
-
(10, "X")
|
21
|
-
(9, "IX")
|
22
|
-
(5, "V")
|
23
|
-
(4, "IV")
|
12
|
+
(1000, "M")
|
13
|
+
(900, "CM")
|
14
|
+
(500, "D")
|
15
|
+
(400, "CD")
|
16
|
+
(100, "C")
|
17
|
+
(90, "XC")
|
18
|
+
(50, "L")
|
19
|
+
(40, "XL")
|
20
|
+
(10, "X")
|
21
|
+
(9, "IX")
|
22
|
+
(5, "V")
|
23
|
+
(4, "IV")
|
24
24
|
(1, "I")
|
25
25
|
]
|
26
26
|
|
@@ -12,24 +12,24 @@ class iso _TestRomanNumerals is UnitTest
|
|
12
12
|
|
13
13
|
fun apply(h: TestHelper) =>
|
14
14
|
let tests: Array[(USize, String)] = [
|
15
|
-
(0, "")
|
16
|
-
(1, "I")
|
17
|
-
(2, "II")
|
18
|
-
(3, "III")
|
19
|
-
(4, "IV")
|
20
|
-
(5, "V")
|
21
|
-
(6, "VI")
|
22
|
-
(9, "IX")
|
23
|
-
(27, "XXVII")
|
24
|
-
(48, "XLVIII")
|
25
|
-
(59, "LIX")
|
26
|
-
(93, "XCIII")
|
27
|
-
(141, "CXLI")
|
28
|
-
(163, "CLXIII")
|
29
|
-
(402, "CDII")
|
30
|
-
(575, "DLXXV")
|
31
|
-
(911, "CMXI")
|
32
|
-
(1024, "MXXIV")
|
15
|
+
(0, "")
|
16
|
+
(1, "I")
|
17
|
+
(2, "II")
|
18
|
+
(3, "III")
|
19
|
+
(4, "IV")
|
20
|
+
(5, "V")
|
21
|
+
(6, "VI")
|
22
|
+
(9, "IX")
|
23
|
+
(27, "XXVII")
|
24
|
+
(48, "XLVIII")
|
25
|
+
(59, "LIX")
|
26
|
+
(93, "XCIII")
|
27
|
+
(141, "CXLI")
|
28
|
+
(163, "CLXIII")
|
29
|
+
(402, "CDII")
|
30
|
+
(575, "DLXXV")
|
31
|
+
(911, "CMXI")
|
32
|
+
(1024, "MXXIV")
|
33
33
|
(3000, "MMM")
|
34
34
|
]
|
35
35
|
|
@@ -144,6 +144,21 @@
|
|
144
144
|
"strings",
|
145
145
|
"matrices"
|
146
146
|
]
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"slug": "isogram",
|
150
|
+
"difficulty": 1,
|
151
|
+
"topics": [
|
152
|
+
"strings",
|
153
|
+
"maps"
|
154
|
+
]
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"slug": "etl",
|
158
|
+
"difficulty": 1,
|
159
|
+
"topics": [
|
160
|
+
"maps"
|
161
|
+
]
|
147
162
|
}
|
148
163
|
],
|
149
164
|
"deprecated": [
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"name": "etl",
|
3
|
+
"ignore": [
|
4
|
+
"**/.*",
|
5
|
+
"node_modules",
|
6
|
+
"bower_components",
|
7
|
+
"output"
|
8
|
+
],
|
9
|
+
"dependencies": {
|
10
|
+
"purescript-prelude": "^3.0.0",
|
11
|
+
"purescript-maps": "^3.0.0"
|
12
|
+
},
|
13
|
+
"devDependencies": {
|
14
|
+
"purescript-psci-support": "^3.0.0",
|
15
|
+
"purescript-test-unit": "^11.0.0"
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Etl
|
2
|
+
( transform
|
3
|
+
) where
|
4
|
+
|
5
|
+
import Prelude
|
6
|
+
import Data.Array (foldl)
|
7
|
+
import Data.Char (toLower)
|
8
|
+
import Data.Map (Map, insert, empty, toUnfoldable)
|
9
|
+
import Data.Tuple (Tuple(..))
|
10
|
+
|
11
|
+
transform :: Map Int (Array Char) -> Map Char Int
|
12
|
+
transform = toUnfoldable
|
13
|
+
>>> expand
|
14
|
+
>>> foldl add empty
|
15
|
+
where expand xs = do
|
16
|
+
Tuple k ys <- xs
|
17
|
+
y <- ys
|
18
|
+
pure $ Tuple k y
|
19
|
+
add m (Tuple k v) = insert (toLower v) k m
|
20
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Test.Main where
|
2
|
+
|
3
|
+
import Prelude
|
4
|
+
import Control.Monad.Eff (Eff)
|
5
|
+
import Data.Map (fromFoldable)
|
6
|
+
import Data.Maybe (Maybe(..))
|
7
|
+
import Data.Tuple (Tuple(..))
|
8
|
+
import Test.Unit.Assert as Assert
|
9
|
+
import Test.Unit (suite, test)
|
10
|
+
import Test.Unit.Main (runTest)
|
11
|
+
import Etl (transform)
|
12
|
+
|
13
|
+
main :: Eff _ Unit
|
14
|
+
main = runTest do
|
15
|
+
suite "Etl.transform" do
|
16
|
+
|
17
|
+
test "a single letter" $
|
18
|
+
Assert.equal (fromFoldable
|
19
|
+
[Tuple 'a' 1]
|
20
|
+
)
|
21
|
+
(transform
|
22
|
+
(fromFoldable
|
23
|
+
[Tuple 1 ['A']]
|
24
|
+
)
|
25
|
+
)
|
26
|
+
|
27
|
+
test "single score with multiple letters" $
|
28
|
+
Assert.equal (fromFoldable
|
29
|
+
[ Tuple 'a' 1
|
30
|
+
, Tuple 'e' 1
|
31
|
+
, Tuple 'i' 1
|
32
|
+
, Tuple 'o' 1
|
33
|
+
, Tuple 'u' 1
|
34
|
+
]
|
35
|
+
)
|
36
|
+
(transform
|
37
|
+
(fromFoldable
|
38
|
+
[Tuple 1 ['A','E','I','O','U']]
|
39
|
+
)
|
40
|
+
)
|
41
|
+
|
42
|
+
test "multiple scores with multiple letters" $
|
43
|
+
Assert.equal (fromFoldable
|
44
|
+
[ Tuple 'a' 1
|
45
|
+
, Tuple 'd' 2
|
46
|
+
, Tuple 'e' 1
|
47
|
+
, Tuple 'g' 2
|
48
|
+
]
|
49
|
+
)
|
50
|
+
(transform
|
51
|
+
(fromFoldable
|
52
|
+
[ Tuple 1 ['A','E']
|
53
|
+
, Tuple 2 ['D','G']
|
54
|
+
]
|
55
|
+
)
|
56
|
+
)
|
57
|
+
|
58
|
+
test "multiple scores with differing numbers of letters" $
|
59
|
+
Assert.equal (fromFoldable
|
60
|
+
[ Tuple 'a' 1
|
61
|
+
, Tuple 'b' 3
|
62
|
+
, Tuple 'c' 3
|
63
|
+
, Tuple 'd' 2
|
64
|
+
, Tuple 'e' 1
|
65
|
+
, Tuple 'f' 4
|
66
|
+
, Tuple 'g' 2
|
67
|
+
, Tuple 'h' 4
|
68
|
+
, Tuple 'i' 1
|
69
|
+
, Tuple 'j' 8
|
70
|
+
, Tuple 'k' 5
|
71
|
+
, Tuple 'l' 1
|
72
|
+
, Tuple 'm' 3
|
73
|
+
, Tuple 'n' 1
|
74
|
+
, Tuple 'o' 1
|
75
|
+
, Tuple 'p' 3
|
76
|
+
, Tuple 'q' 10
|
77
|
+
, Tuple 'r' 1
|
78
|
+
, Tuple 's' 1
|
79
|
+
, Tuple 't' 1
|
80
|
+
, Tuple 'u' 1
|
81
|
+
, Tuple 'v' 4
|
82
|
+
, Tuple 'w' 4
|
83
|
+
, Tuple 'x' 8
|
84
|
+
, Tuple 'y' 4
|
85
|
+
, Tuple 'z' 10
|
86
|
+
]
|
87
|
+
)
|
88
|
+
(transform
|
89
|
+
(fromFoldable
|
90
|
+
[ Tuple 1 ['A','E','I','O','U','L','N','R','S','T']
|
91
|
+
, Tuple 10 ['Q','Z']
|
92
|
+
, Tuple 2 ['D','G']
|
93
|
+
, Tuple 3 ['B','C','M','P']
|
94
|
+
, Tuple 4 ['F','H','V','W','Y']
|
95
|
+
, Tuple 5 ['K']
|
96
|
+
, Tuple 8 ['J','X']
|
97
|
+
]
|
98
|
+
)
|
99
|
+
)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"name": "isogram",
|
3
|
+
"ignore": [
|
4
|
+
"**/.*",
|
5
|
+
"node_modules",
|
6
|
+
"bower_components",
|
7
|
+
"output"
|
8
|
+
],
|
9
|
+
"dependencies": {
|
10
|
+
"purescript-prelude": "^3.0.0",
|
11
|
+
"purescript-maps": "^3.0.0",
|
12
|
+
"purescript-strings": "^3.0.0"
|
13
|
+
},
|
14
|
+
"devDependencies": {
|
15
|
+
"purescript-psci-support": "^3.0.0",
|
16
|
+
"purescript-test-unit": "^11.0.0"
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Isogram
|
2
|
+
( isIsogram
|
3
|
+
) where
|
4
|
+
|
5
|
+
import Prelude
|
6
|
+
import Data.Array (filter, foldl)
|
7
|
+
import Data.Map (alter, empty, values)
|
8
|
+
import Data.Maybe (Maybe(..))
|
9
|
+
import Data.String (toCharArray, toLower)
|
10
|
+
import Data.Traversable (all)
|
11
|
+
|
12
|
+
isIsogram :: String -> Boolean
|
13
|
+
isIsogram = toLower
|
14
|
+
>>> toCharArray
|
15
|
+
>>> filter letter
|
16
|
+
>>> foldl toMap empty
|
17
|
+
>>> values
|
18
|
+
>>> all (_ <= 1)
|
19
|
+
where letter c = 'a' <= c && c <= 'z'
|
20
|
+
toMap m c = alter addChar c m
|
21
|
+
addChar Nothing = Just 1
|
22
|
+
addChar (Just c) = Just $ c + 1
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Test.Main where
|
2
|
+
|
3
|
+
import Prelude
|
4
|
+
import Control.Monad.Eff (Eff)
|
5
|
+
import Test.Unit.Assert as Assert
|
6
|
+
import Test.Unit (suite, test)
|
7
|
+
import Test.Unit.Main (runTest)
|
8
|
+
import Isogram (isIsogram)
|
9
|
+
|
10
|
+
main :: Eff _ Unit
|
11
|
+
main = runTest do
|
12
|
+
suite "Isogram.transform" do
|
13
|
+
|
14
|
+
test "empty string" $
|
15
|
+
Assert.equal true
|
16
|
+
(isIsogram "")
|
17
|
+
|
18
|
+
test "isogram with only lower case characters" $
|
19
|
+
Assert.equal true
|
20
|
+
(isIsogram "isogram")
|
21
|
+
|
22
|
+
test "word with one duplicated character" $
|
23
|
+
Assert.equal false
|
24
|
+
(isIsogram "eleven")
|
25
|
+
|
26
|
+
test "longest reported english isogram" $
|
27
|
+
Assert.equal true
|
28
|
+
(isIsogram "subdermatoglyphic")
|
29
|
+
|
30
|
+
test "word with duplicated character in mixed case" $
|
31
|
+
Assert.equal false
|
32
|
+
(isIsogram "Alphabet")
|
33
|
+
|
34
|
+
test "hypothetical isogrammic word with hyphen" $
|
35
|
+
Assert.equal true
|
36
|
+
(isIsogram "thumbscrew-japingly")
|
37
|
+
|
38
|
+
test "isogram with duplicated non letter character" $
|
39
|
+
Assert.equal true
|
40
|
+
(isIsogram "Hjelmqvist-Gryb-Zock-Pfund-Wax")
|
41
|
+
|
42
|
+
test "made-up name that is an isogram" $
|
43
|
+
Assert.equal true
|
44
|
+
(isIsogram "Emily Jung Schwartzkopf")
|
data/tracks/ruby/README.md
CHANGED
@@ -137,12 +137,13 @@ The `lib/$PROBLEM_cases.rb` file should contain a small class that wraps the JSO
|
|
137
137
|
require 'exercise_cases'
|
138
138
|
|
139
139
|
class ProblemNameCase < OpenStruct
|
140
|
-
def
|
140
|
+
def name
|
141
141
|
'test_%s' % description.gsub(/[ -]/, '_')
|
142
142
|
end
|
143
143
|
|
144
144
|
def workload
|
145
|
-
#
|
145
|
+
# Example workload:
|
146
|
+
"assert #{expected.inspect}, Problem.call(#{input.inspect})"
|
146
147
|
end
|
147
148
|
|
148
149
|
def skipped
|
@@ -156,8 +157,8 @@ the generator script will infer the name of the class from the argument that is
|
|
156
157
|
|
157
158
|
This class must implement the following methods:
|
158
159
|
|
159
|
-
- `
|
160
|
-
- `workload` - Returns the main syntax for the test. This will vary depending on the test generator and its underlying implementation
|
160
|
+
- `name` - Returns the name of the test (i.e `test_one_equals_one`)
|
161
|
+
- `workload` - Returns the main syntax for the test. This includes the assertion and any setup required for the test. This will vary depending on the test generator and its underlying implementation
|
161
162
|
- `skipped` - Returns skip syntax (i.e. `skip` or `# skip`)
|
162
163
|
|
163
164
|
Beyond that, you can implement any helper methods that you need.
|
@@ -183,14 +184,12 @@ loop through each of the cases in an inner loop:
|
|
183
184
|
|
184
185
|
```
|
185
186
|
ProblemNameCases = proc do |data|
|
186
|
-
i = 0
|
187
187
|
json = JSON.parse(data)
|
188
188
|
cases = []
|
189
189
|
%w(section1 section2 etc).each do |section|
|
190
190
|
json[section]['cases'].each do |row|
|
191
|
-
row = row.merge(row.merge('index' =>
|
191
|
+
row = row.merge(row.merge('index' => cases.size, 'section' => section))
|
192
192
|
cases << ProblemNameCase.new(row)
|
193
|
-
i += 1
|
194
193
|
end
|
195
194
|
end
|
196
195
|
cases
|
@@ -208,11 +207,13 @@ require 'minitest/autorun'
|
|
208
207
|
require_relative '$PROBLEM'
|
209
208
|
|
210
209
|
# Common test data version: <%= abbreviated_commit_hash %>
|
211
|
-
class ProblemNameTest < Minitest::Test
|
210
|
+
class ProblemNameTest < Minitest::Test
|
211
|
+
<% test_cases.each do |test_case| %>
|
212
212
|
def <%= test_case.name %>
|
213
213
|
<%= test_case.skipped %>
|
214
|
-
|
214
|
+
<%= test_case.workload %>
|
215
215
|
end
|
216
|
+
|
216
217
|
<% end %>
|
217
218
|
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
|
218
219
|
def test_bookkeeping
|
@@ -7,7 +7,7 @@ require_relative 'anagram'
|
|
7
7
|
class AnagramTest < Minitest::Test<% test_cases.each do |test_case| %>
|
8
8
|
def <%= test_case.test_name %>
|
9
9
|
<%= test_case.skipped %>
|
10
|
-
<%= test_case.
|
10
|
+
<%= test_case.workload %>
|
11
11
|
end
|
12
12
|
<% end %>
|
13
13
|
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
|
@@ -7,8 +7,8 @@ require_relative 'hamming'
|
|
7
7
|
class HammingTest < Minitest::Test<% test_cases.each do |test_case| %>
|
8
8
|
def <%= test_case.name %>
|
9
9
|
<%= test_case.skipped %><% if test_case.raises_error? %>
|
10
|
-
assert_raises(ArgumentError) { <%= test_case.
|
11
|
-
assert_equal <%= test_case.expected %>, <%= test_case.
|
10
|
+
assert_raises(ArgumentError) { <%= test_case.workload %> }<% else %>
|
11
|
+
assert_equal <%= test_case.expected %>, <%= test_case.workload %><% end %>
|
12
12
|
end
|
13
13
|
<% end %>
|
14
14
|
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
@@ -1,35 +1,30 @@
|
|
1
1
|
class Luhn
|
2
|
-
|
3
|
-
|
4
|
-
luhn = Luhn.new(test_number)
|
5
|
-
return test_number if luhn.valid?
|
6
|
-
test_number + 10 - (luhn.checksum % 10)
|
7
|
-
end
|
2
|
+
DOUBLE = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
|
3
|
+
DOUBLE.freeze
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
@number = number
|
5
|
+
def self.valid?(string)
|
6
|
+
Luhn.new(string).valid?
|
12
7
|
end
|
13
8
|
|
14
|
-
def
|
15
|
-
|
16
|
-
number.to_s.reverse.split('').map(&:to_i).each_with_index do |n, i|
|
17
|
-
if i % 2 == 0
|
18
|
-
numbers << n
|
19
|
-
else
|
20
|
-
value = n * 2
|
21
|
-
value -= 9 if value > 9
|
22
|
-
numbers << value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
numbers.reverse
|
9
|
+
def initialize(string)
|
10
|
+
@string = string.tr(' ', '')
|
26
11
|
end
|
27
12
|
|
28
13
|
def checksum
|
29
|
-
|
14
|
+
@string.
|
15
|
+
reverse.each_char.with_index.
|
16
|
+
reduce(0) {|sum, (c, i)| sum + (i.odd? ? DOUBLE[c.to_i] : c.to_i) }
|
30
17
|
end
|
31
18
|
|
32
19
|
def valid?
|
33
|
-
checksum % 10
|
20
|
+
clean? && (checksum % 10).zero?
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean?
|
24
|
+
@string.match(/^\d{2,}$/)
|
34
25
|
end
|
35
26
|
end
|
27
|
+
|
28
|
+
module BookKeeping
|
29
|
+
VERSION = 1
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
gem 'minitest', '>= 5.0.0'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative 'luhn'
|
5
|
+
|
6
|
+
# Common test data version: <%= abbreviated_commit_hash %>
|
7
|
+
class LuhnTest < Minitest::Test<% test_cases.each do |test_case| %>
|
8
|
+
def <%= test_case.name %>
|
9
|
+
<%= test_case.skipped %>
|
10
|
+
<%= test_case.workload %>
|
11
|
+
end
|
12
|
+
<% end %>
|
13
|
+
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
|
14
|
+
def test_bookkeeping
|
15
|
+
skip
|
16
|
+
assert_equal <%= version %>, BookKeeping::VERSION
|
17
|
+
end
|
18
|
+
end
|
@@ -3,57 +3,90 @@ gem 'minitest', '>= 5.0.0'
|
|
3
3
|
require 'minitest/autorun'
|
4
4
|
require_relative 'luhn'
|
5
5
|
|
6
|
+
# Common test data version: c826372
|
6
7
|
class LuhnTest < Minitest::Test
|
7
|
-
def
|
8
|
-
|
9
|
-
|
8
|
+
def test_single_digit_strings_can_not_be_valid
|
9
|
+
# skip
|
10
|
+
refute Luhn.valid?("1")
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
+
def test_A_single_zero_is_invalid
|
13
14
|
skip
|
14
|
-
|
15
|
-
assert_equal [7, 6, 6, 1], luhn.addends
|
15
|
+
refute Luhn.valid?("0")
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_a_simple_valid_SIN_that_remains_valid_if_reversed
|
19
19
|
skip
|
20
|
-
|
21
|
-
assert_equal 22, luhn.checksum
|
20
|
+
assert Luhn.valid?("059")
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
23
|
+
def test_a_simple_valid_SIN_that_becomes_invalid_if_reversed
|
25
24
|
skip
|
26
|
-
|
27
|
-
assert_equal 21, luhn.checksum
|
25
|
+
assert Luhn.valid?("59")
|
28
26
|
end
|
29
27
|
|
30
|
-
def
|
28
|
+
def test_a_valid_Canadian_SIN
|
31
29
|
skip
|
32
|
-
|
33
|
-
refute luhn.valid?
|
30
|
+
assert Luhn.valid?("055 444 285")
|
34
31
|
end
|
35
32
|
|
36
|
-
def
|
33
|
+
def test_invalid_Canadian_SIN
|
37
34
|
skip
|
38
|
-
|
39
|
-
assert luhn.valid?
|
35
|
+
refute Luhn.valid?("055 444 286")
|
40
36
|
end
|
41
37
|
|
42
|
-
def
|
38
|
+
def test_invalid_credit_card
|
43
39
|
skip
|
44
|
-
|
45
|
-
assert_equal 1230, number
|
40
|
+
refute Luhn.valid?("8273 1232 7352 0569")
|
46
41
|
end
|
47
42
|
|
48
|
-
def
|
43
|
+
def test_valid_strings_with_a_non_digit_included_become_invalid
|
49
44
|
skip
|
50
|
-
|
51
|
-
assert_equal 8_739_567, number
|
45
|
+
refute Luhn.valid?("055a 444 285")
|
52
46
|
end
|
53
47
|
|
54
|
-
def
|
48
|
+
def test_valid_strings_with_punctuation_included_become_invalid
|
55
49
|
skip
|
56
|
-
|
57
|
-
|
50
|
+
refute Luhn.valid?("055-444-285")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_valid_strings_with_symbols_included_become_invalid
|
54
|
+
skip
|
55
|
+
refute Luhn.valid?("055£ 444$ 285")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_single_zero_with_space_is_invalid
|
59
|
+
skip
|
60
|
+
refute Luhn.valid?(" 0")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_more_than_a_single_zero_is_valid
|
64
|
+
skip
|
65
|
+
assert Luhn.valid?("0000 0")
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_input_digit_9_is_correctly_converted_to_output_digit_9
|
69
|
+
skip
|
70
|
+
assert Luhn.valid?("091")
|
71
|
+
end
|
72
|
+
# Problems in exercism evolve over time, as we find better ways to ask
|
73
|
+
# questions.
|
74
|
+
# The version number refers to the version of the problem you solved,
|
75
|
+
# not your solution.
|
76
|
+
#
|
77
|
+
# Define a constant named VERSION inside of the top level BookKeeping
|
78
|
+
# module, which may be placed near the end of your file.
|
79
|
+
#
|
80
|
+
# In your file, it will look like this:
|
81
|
+
#
|
82
|
+
# module BookKeeping
|
83
|
+
# VERSION = 1 # Where the version number matches the one in the test.
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# If you are curious, read more about constants on RubyDoc:
|
87
|
+
# http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
|
88
|
+
def test_bookkeeping
|
89
|
+
skip
|
90
|
+
assert_equal 1, BookKeeping::VERSION
|
58
91
|
end
|
59
92
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
gem 'minitest', '>= 5.0.0'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative 'pig_latin'
|
5
|
+
|
6
|
+
# Common test data version: <%= abbreviated_commit_hash %>
|
7
|
+
class PigLatinTest < Minitest::Test
|
8
|
+
<% test_cases.each do |test_case| %>
|
9
|
+
def <%= test_case.name %>
|
10
|
+
<%= test_case.skipped %>
|
11
|
+
<%= test_case.workload %>
|
12
|
+
end
|
13
|
+
|
14
|
+
<% end %>
|
15
|
+
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
|
16
|
+
|
17
|
+
def test_bookkeeping
|
18
|
+
skip
|
19
|
+
assert_equal <%= version %>, BookKeeping::VERSION
|
20
|
+
end
|
21
|
+
end
|