trackler 2.2.1.19 → 2.2.1.20
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.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/bash/config.json +11 -0
- data/tracks/bash/docs/ABOUT.md +5 -0
- data/tracks/bash/exercises/word-count/README.md +24 -0
- data/tracks/bash/exercises/word-count/example.awk +12 -0
- data/tracks/bash/exercises/word-count/example.sh +21 -0
- data/tracks/bash/exercises/word-count/word_count_test.sh +84 -0
- data/tracks/coffeescript/config/maintainers.json +5 -11
- data/tracks/csharp/.travis.yml +3 -0
- data/tracks/delphi/config/maintainers.json +1 -1
- data/tracks/ecmascript/config.json +108 -108
- data/tracks/elixir/exercises/phone-number/phone_number_test.exs +21 -1
- data/tracks/factor/docs/SNIPPET.txt +5 -0
- data/tracks/idris/docs/TESTS.md +7 -0
- data/tracks/java/config.json +47 -47
- data/tracks/javascript/config.json +103 -103
- data/tracks/julia/config.json +121 -121
- data/tracks/julia/docs/RESOURCES.md +1 -1
- data/tracks/julia/docs/SNIPPET.txt +8 -0
- data/tracks/objective-c/config.json +2 -3
- data/tracks/objective-c/exercises/rna-transcription/RNATranscriptionExample.m +11 -32
- data/tracks/ocaml/.travis-ci.sh +1 -1
- data/tracks/ocaml/.travis.yml +1 -1
- data/tracks/ocaml/README.md +1 -1
- data/tracks/ocaml/exercises/change/test.ml +24 -21
- data/tracks/ocaml/tools/test-generator/src/codegen.ml +3 -7
- data/tracks/ocaml/tools/test-generator/src/controller.ml +4 -5
- data/tracks/ocaml/tools/test-generator/src/languages.ml +4 -3
- data/tracks/ocaml/tools/test-generator/src/model.ml +1 -2
- data/tracks/ocaml/tools/test-generator/src/ocaml_special_cases.ml +19 -18
- data/tracks/ocaml/tools/test-generator/src/parser.ml +12 -17
- data/tracks/ocaml/tools/test-generator/src/purescript_special_cases.ml +11 -3
- data/tracks/ocaml/tools/test-generator/test/codegen_test.ml +2 -3
- data/tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml +12 -4
- data/tracks/ocaml/tools/test-generator/test/parser_test.ml +10 -10
- data/tracks/purescript/exercises/bob/test/Main.purs +5 -5
- data/tracks/ruby/bin/generate +1 -1
- data/tracks/ruby/docs/24pullrequests.md +1 -1
- data/tracks/ruby/exercises/all-your-base/all_your_base_test.rb +24 -24
- data/tracks/ruby/exercises/alphametics/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/exercises/bowling/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/exercises/bowling/bowling_test.rb +10 -10
- data/tracks/ruby/exercises/change/.meta/.version +1 -1
- data/tracks/ruby/exercises/change/.meta/solutions/change.rb +1 -1
- data/tracks/ruby/exercises/change/change_test.rb +7 -2
- data/tracks/ruby/exercises/collatz-conjecture/.meta/generator/collatz_conjecture_case.rb +1 -1
- data/tracks/ruby/exercises/connect/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/exercises/dominoes/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/exercises/hamming/.meta/generator/hamming_case.rb +5 -1
- data/tracks/ruby/exercises/hamming/hamming_test.rb +7 -7
- data/tracks/ruby/exercises/leap/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/exercises/pangram/.meta/.version +1 -1
- data/tracks/ruby/exercises/pangram/.meta/solutions/pangram.rb +1 -1
- data/tracks/ruby/exercises/pangram/pangram_test.rb +3 -3
- data/tracks/ruby/exercises/rna-transcription/rna_transcription_test.rb +4 -4
- data/tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb +1 -1
- data/tracks/ruby/exercises/space-age/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/lib/generator/test_template.erb +1 -1
- data/tracks/ruby/lib/generator/underscore.rb +1 -1
- data/tracks/ruby/lib/helper.rb +4 -4
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/alpha-beta/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/alpha/.meta/.version +0 -0
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/alpha/.meta/generator/alpha_case.rb +0 -0
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/alpha/.meta/generator/test_template.erb +1 -1
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/alpha/.meta/solutions/alpha.rb +0 -0
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/beta/.meta/.version +0 -0
- data/tracks/ruby/test/fixtures/{xruby → ruby}/exercises/beta/.meta/generator/beta_case.rb +0 -0
- data/tracks/ruby/test/fixtures/{xruby → ruby}/lib/generator/test_template.erb +1 -1
- data/tracks/ruby/test/generator/files/track_files_test.rb +4 -4
- data/tracks/ruby/test/generator/implementation_test.rb +1 -1
- data/tracks/ruby/test/generator/template_values_test.rb +1 -1
- data/tracks/scala/exercises/rail-fence-cipher/src/main/scala/{RailFenceCipher.scala → .keep} +0 -0
- data/tracks/scala/exercises/rail-fence-cipher/src/test/scala/RailFenceCipherTest.scala +16 -23
- data/tracks/scala/exercises/say/src/test/scala/SayTest.scala +20 -33
- data/tracks/scala/testgen/src/main/scala/RailFenceCipherTestGenerator.scala +9 -53
- data/tracks/scala/testgen/src/main/scala/SayTestGenerator.scala +50 -0
- data/tracks/sml/bin/generate +1 -1
- data/tracks/sml/config.json +30 -0
- data/tracks/sml/exercises/all-your-base/README.md +61 -0
- data/tracks/sml/exercises/all-your-base/all-your-base.sml +2 -0
- data/tracks/sml/exercises/all-your-base/example.sml +36 -0
- data/tracks/sml/exercises/all-your-base/test.sml +75 -0
- data/tracks/sml/exercises/all-your-base/testlib.sml +159 -0
- data/tracks/sml/exercises/difference-of-squares/example.sml +3 -6
- data/tracks/sml/exercises/list-ops/README.md +40 -0
- data/tracks/sml/exercises/list-ops/example.sml +34 -0
- data/tracks/sml/exercises/list-ops/list-ops.sml +23 -0
- data/tracks/sml/exercises/list-ops/test.sml +85 -0
- data/tracks/sml/exercises/list-ops/testlib.sml +159 -0
- data/tracks/sml/exercises/prime-factors/README.md +66 -0
- data/tracks/sml/exercises/prime-factors/example.sml +15 -0
- data/tracks/sml/exercises/prime-factors/prime-factors.sml +2 -0
- data/tracks/sml/exercises/prime-factors/test.sml +35 -0
- data/tracks/sml/exercises/prime-factors/testlib.sml +159 -0
- metadata +34 -11
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
require_relative 'hamming'
|
|
3
3
|
|
|
4
|
-
# Common test data version:
|
|
4
|
+
# Common test data version: 2.0.0 a2aff5b
|
|
5
5
|
class HammingTest < Minitest::Test
|
|
6
|
-
def
|
|
6
|
+
def test_empty_strands
|
|
7
7
|
# skip
|
|
8
|
+
assert_equal 0, Hamming.compute('', '')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_identical_strands
|
|
12
|
+
skip
|
|
8
13
|
assert_equal 0, Hamming.compute('A', 'A')
|
|
9
14
|
end
|
|
10
15
|
|
|
@@ -63,11 +68,6 @@ class HammingTest < Minitest::Test
|
|
|
63
68
|
assert_equal 9, Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT')
|
|
64
69
|
end
|
|
65
70
|
|
|
66
|
-
def test_empty_strands
|
|
67
|
-
skip
|
|
68
|
-
assert_equal 0, Hamming.compute('', '')
|
|
69
|
-
end
|
|
70
|
-
|
|
71
71
|
def test_disallow_first_strand_longer
|
|
72
72
|
skip
|
|
73
73
|
assert_raises(ArgumentError) { Hamming.compute('AATG', 'AAA') }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
5
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
require_relative 'pangram'
|
|
3
3
|
|
|
4
|
-
# Common test data version: 1.
|
|
4
|
+
# Common test data version: 1.1.0 fba1aef
|
|
5
5
|
class PangramTest < Minitest::Test
|
|
6
6
|
def test_sentence_empty
|
|
7
7
|
# skip
|
|
@@ -61,7 +61,7 @@ class PangramTest < Minitest::Test
|
|
|
61
61
|
|
|
62
62
|
def test_upper_and_lower_case_versions_of_the_same_character_should_not_be_counted_separately
|
|
63
63
|
skip
|
|
64
|
-
phrase = 'the quick brown fox
|
|
64
|
+
phrase = 'the quick brown fox jumps over with lazy FX'
|
|
65
65
|
result = Pangram.pangram?(phrase)
|
|
66
66
|
refute result, "Expected false, got: #{result.inspect}. #{phrase.inspect} is NOT a pangram"
|
|
67
67
|
end
|
|
@@ -85,6 +85,6 @@ class PangramTest < Minitest::Test
|
|
|
85
85
|
|
|
86
86
|
def test_bookkeeping
|
|
87
87
|
skip
|
|
88
|
-
assert_equal
|
|
88
|
+
assert_equal 5, BookKeeping::VERSION
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
require_relative 'rna_transcription'
|
|
3
3
|
|
|
4
|
-
# Common test data version: 1.0.
|
|
4
|
+
# Common test data version: 1.0.1 cb1fd3a
|
|
5
5
|
class RnaTranscriptionTest < Minitest::Test
|
|
6
6
|
def test_rna_complement_of_cytosine_is_guanine
|
|
7
7
|
# skip
|
|
@@ -28,17 +28,17 @@ class RnaTranscriptionTest < Minitest::Test
|
|
|
28
28
|
assert_equal 'UGCACCAGAAUU', Complement.of_dna('ACGTGGTCTTAA')
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def
|
|
31
|
+
def test_correctly_handles_invalid_input_rna_instead_of_dna
|
|
32
32
|
skip
|
|
33
33
|
assert_equal '', Complement.of_dna('U')
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def
|
|
36
|
+
def test_correctly_handles_completely_invalid_dna_input
|
|
37
37
|
skip
|
|
38
38
|
assert_equal '', Complement.of_dna('XXX')
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def
|
|
41
|
+
def test_correctly_handles_partially_invalid_dna_input
|
|
42
42
|
skip
|
|
43
43
|
assert_equal '', Complement.of_dna('ACGTXXXCTTAA')
|
|
44
44
|
end
|
data/tracks/ruby/lib/helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
METADATA_REPOSITORY_PATH = File.join(
|
|
1
|
+
EXERCISM_RUBY_ROOT = File.join(File.dirname(__FILE__), '..').freeze
|
|
2
|
+
EXERCISM_RUBY_LIB = File.join(EXERCISM_RUBY_ROOT, 'lib').freeze
|
|
3
|
+
METADATA_REPOSITORY_PATH = File.join(EXERCISM_RUBY_ROOT, '..', 'problem-specifications').freeze
|
|
4
4
|
|
|
5
|
-
$LOAD_PATH.unshift(
|
|
5
|
+
$LOAD_PATH.unshift(EXERCISM_RUBY_LIB)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -5,7 +5,7 @@ module Generator
|
|
|
5
5
|
class TrackFilesTest < Minitest::Test
|
|
6
6
|
FixturePaths = Paths.new(
|
|
7
7
|
metadata: 'test/fixtures/metadata',
|
|
8
|
-
track: 'test/fixtures/
|
|
8
|
+
track: 'test/fixtures/ruby'
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
class TestTrackFiles
|
|
@@ -69,7 +69,7 @@ module Generator
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def test_increment
|
|
72
|
-
subject = TestTestsVersionFile.new(filename: 'test/fixtures/
|
|
72
|
+
subject = TestTestsVersionFile.new(filename: 'test/fixtures/ruby/exercises/alpha/.meta/.version')
|
|
73
73
|
assert_equal 2, subject.increment
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -83,7 +83,7 @@ module Generator
|
|
|
83
83
|
|
|
84
84
|
def test_update_version
|
|
85
85
|
subject = TestExampleSolutionFile.new(
|
|
86
|
-
filename: 'test/fixtures/
|
|
86
|
+
filename: 'test/fixtures/ruby/exercises/alpha/.meta/solutions/alpha.rb'
|
|
87
87
|
)
|
|
88
88
|
assert_match(/VERSION = 2/, subject.update_version(2))
|
|
89
89
|
end
|
|
@@ -103,7 +103,7 @@ module Generator
|
|
|
103
103
|
mock_erb = Minitest::Mock.new
|
|
104
104
|
mock_erb.expect :result, 'new content', ['mock binding']
|
|
105
105
|
|
|
106
|
-
subject = TestMinitestTestsFile.new(filename: 'test/fixtures/
|
|
106
|
+
subject = TestMinitestTestsFile.new(filename: 'test/fixtures/ruby/exercises/alpha/alpha_tests.rb')
|
|
107
107
|
ERB.stub :new, mock_erb do
|
|
108
108
|
assert_equal 'new content', subject.generate(template: mock_template, values: mock_values)
|
|
109
109
|
end
|
|
@@ -63,7 +63,7 @@ module Generator
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def test_case
|
|
66
|
-
Files::TestCaseFile.new(filename: 'test/fixtures/
|
|
66
|
+
Files::TestCaseFile.new(filename: 'test/fixtures/ruby/exercises/alpha/.meta/generator/alpha_case.rb')
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
include TemplateValuesFactory
|
data/tracks/scala/exercises/rail-fence-cipher/src/main/scala/{RailFenceCipher.scala → .keep}
RENAMED
|
File without changes
|
|
@@ -1,42 +1,35 @@
|
|
|
1
|
-
import org.scalatest.{
|
|
1
|
+
import org.scalatest.{Matchers, FunSuite}
|
|
2
2
|
|
|
3
|
+
/** @version 1.0.1 */
|
|
3
4
|
class RailFenceCipherTest extends FunSuite with Matchers {
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
val encoded = RailFenceCipher.encode("XOXOXOXOXOXOXOXOXO", 2)
|
|
8
|
-
encoded should be ("XXXXXXXXXOOOOOOOOO")
|
|
6
|
+
test("encode with two rails") {
|
|
7
|
+
RailFenceCipher.encode("XOXOXOXOXOXOXOXOXO", 2) should be ("XXXXXXXXXOOOOOOOOO")
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
test("
|
|
10
|
+
test("encode with three rails") {
|
|
12
11
|
pending
|
|
13
|
-
|
|
14
|
-
encoded should be ("WECRLTEERDSOEEFEAOCAIVDEN")
|
|
12
|
+
RailFenceCipher.encode("WEAREDISCOVEREDFLEEATONCE", 3) should be ("WECRLTEERDSOEEFEAOCAIVDEN")
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
test("
|
|
15
|
+
test("encode with ending in the middle") {
|
|
18
16
|
pending
|
|
19
|
-
|
|
20
|
-
encoded should be ("ESXIEECSR")
|
|
17
|
+
RailFenceCipher.encode("EXERCISES", 4) should be ("ESXIEECSR")
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
test("test to decode with three rails") {
|
|
20
|
+
test("decode with three rails") {
|
|
25
21
|
pending
|
|
26
|
-
|
|
27
|
-
decoded should be ("THEDEVILISINTHEDETAILS")
|
|
22
|
+
RailFenceCipher.decode("TEITELHDVLSNHDTISEIIEA", 3) should be ("THEDEVILISINTHEDETAILS")
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
test("
|
|
25
|
+
test("decode with five rails") {
|
|
31
26
|
pending
|
|
32
|
-
|
|
33
|
-
decoded should be ("EXERCISMISAWESOME")
|
|
27
|
+
RailFenceCipher.decode("EIEXMSMESAORIWSCE", 5) should be ("EXERCISMISAWESOME")
|
|
34
28
|
}
|
|
35
29
|
|
|
36
|
-
test("
|
|
30
|
+
test("decode with six rails") {
|
|
37
31
|
pending
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
RailFenceCipher.decode("133714114238148966225439541018335470986172518171757571896261", 6) should
|
|
33
|
+
be ("112358132134558914423337761098715972584418167651094617711286")
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
35
|
+
}
|
|
@@ -1,93 +1,80 @@
|
|
|
1
1
|
import org.scalatest.{Matchers, FunSuite}
|
|
2
2
|
|
|
3
|
+
/** @version 1.0.0 */
|
|
3
4
|
class SayTest extends FunSuite with Matchers {
|
|
5
|
+
|
|
4
6
|
test("zero") {
|
|
5
7
|
Say.inEnglish(0) should be (Some("zero"))
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
test("one") {
|
|
10
|
+
test("one") {
|
|
9
11
|
pending
|
|
10
12
|
Say.inEnglish(1) should be (Some("one"))
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
test("fourteen") {
|
|
15
|
+
test("fourteen") {
|
|
14
16
|
pending
|
|
15
17
|
Say.inEnglish(14) should be (Some("fourteen"))
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
test("twenty") {
|
|
20
|
+
test("twenty") {
|
|
19
21
|
pending
|
|
20
22
|
Say.inEnglish(20) should be (Some("twenty"))
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
test("twenty-two") {
|
|
25
|
+
test("twenty-two") {
|
|
24
26
|
pending
|
|
25
27
|
Say.inEnglish(22) should be (Some("twenty-two"))
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
test("
|
|
29
|
-
pending
|
|
30
|
-
Say.inEnglish(50) should be (Some("fifty"))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test("ninety-eight") {
|
|
34
|
-
pending
|
|
35
|
-
Say.inEnglish(98) should be (Some("ninety-eight"))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
test("one hundred") {
|
|
30
|
+
test("one hundred") {
|
|
39
31
|
pending
|
|
40
32
|
Say.inEnglish(100) should be (Some("one hundred"))
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
test("one hundred twenty-three") {
|
|
35
|
+
test("one hundred twenty-three") {
|
|
44
36
|
pending
|
|
45
37
|
Say.inEnglish(123) should be (Some("one hundred twenty-three"))
|
|
46
38
|
}
|
|
47
39
|
|
|
48
|
-
test("one thousand") {
|
|
40
|
+
test("one thousand") {
|
|
49
41
|
pending
|
|
50
42
|
Say.inEnglish(1000) should be (Some("one thousand"))
|
|
51
43
|
}
|
|
52
44
|
|
|
53
|
-
test("one thousand two hundred thirty-four") {
|
|
45
|
+
test("one thousand two hundred thirty-four") {
|
|
54
46
|
pending
|
|
55
47
|
Say.inEnglish(1234) should be (Some("one thousand two hundred thirty-four"))
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
test("one million") {
|
|
50
|
+
test("one million") {
|
|
59
51
|
pending
|
|
60
52
|
Say.inEnglish(1000000) should be (Some("one million"))
|
|
61
53
|
}
|
|
62
54
|
|
|
63
|
-
test("one million two") {
|
|
64
|
-
pending
|
|
65
|
-
Say.inEnglish(1000002) should be (Some("one million two"))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
test("one million two thousand three hundred forty-five") {
|
|
55
|
+
test("one million two thousand three hundred forty-five") {
|
|
69
56
|
pending
|
|
70
57
|
Say.inEnglish(1002345) should be (Some("one million two thousand three hundred forty-five"))
|
|
71
58
|
}
|
|
72
59
|
|
|
73
|
-
test("one billion") {
|
|
60
|
+
test("one billion") {
|
|
74
61
|
pending
|
|
75
62
|
Say.inEnglish(1000000000) should be (Some("one billion"))
|
|
76
63
|
}
|
|
77
64
|
|
|
78
|
-
test("
|
|
65
|
+
test("a big number") {
|
|
79
66
|
pending
|
|
80
|
-
Say.inEnglish(
|
|
81
|
-
"six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three"))
|
|
67
|
+
Say.inEnglish(987654321123l) should
|
|
68
|
+
be (Some("nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three"))
|
|
82
69
|
}
|
|
83
70
|
|
|
84
|
-
test("
|
|
71
|
+
test("numbers below zero are out of range") {
|
|
85
72
|
pending
|
|
86
73
|
Say.inEnglish(-1) should be (None)
|
|
87
74
|
}
|
|
88
75
|
|
|
89
|
-
test("
|
|
76
|
+
test("numbers above 999,999,999,999 are out of range") {
|
|
90
77
|
pending
|
|
91
|
-
Say.inEnglish(
|
|
78
|
+
Say.inEnglish(1000000000000l) should be (None)
|
|
92
79
|
}
|
|
93
|
-
}
|
|
80
|
+
}
|
|
@@ -1,59 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import java.io.File
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
// Generates test suite from json test definition for the RailFenceCipher exercise.
|
|
6
|
-
class RailFenceCipherTestGenerator {
|
|
7
|
-
implicit val railFenceTestCaseReader = Json.reads[RailFenceTestCase]
|
|
8
|
-
|
|
9
|
-
private val filename = "rail-fence.json"
|
|
10
|
-
private val fileContents = Source.fromFile(filename).getLines.mkString
|
|
11
|
-
private val json = Json.parse(fileContents)
|
|
12
|
-
|
|
13
|
-
def write {
|
|
14
|
-
val testBuilder = new TestBuilder("RailFenceCipherTest")
|
|
15
|
-
addEncodeTests(testBuilder)
|
|
16
|
-
addDecodeTests(testBuilder)
|
|
17
|
-
testBuilder.toFile
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private def addEncodeTests(testBuilder: TestBuilder): Unit = {
|
|
21
|
-
val description = "Encode test cases"
|
|
22
|
-
val encodeTestCases = (json \ "encode" \ "cases").get.as[List[RailFenceTestCase]]
|
|
23
|
-
|
|
24
|
-
implicit def testCaseToGen(tc: RailFenceTestCase): TestCaseGen = {
|
|
25
|
-
val callSUT = s"""RailFenceCipher.encode("${tc.msg}", ${tc.rails})"""
|
|
26
|
-
val expected = tc.expected
|
|
27
|
-
val result = s"val encoded = $callSUT"
|
|
28
|
-
val checkResult = s"""encoded should be ("$expected")"""
|
|
29
|
-
|
|
30
|
-
TestCaseGen(tc.description, callSUT, expected, result, checkResult)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
testBuilder.addTestCases(encodeTestCases, Some(description))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private def addDecodeTests(testBuilder: TestBuilder): Unit = {
|
|
37
|
-
val description = "Decode test cases"
|
|
38
|
-
val encodeTestCases = (json \ "decode" \ "cases").get.as[List[RailFenceTestCase]]
|
|
39
|
-
|
|
40
|
-
implicit def testCaseToGen(tc: RailFenceTestCase): TestCaseGen = {
|
|
41
|
-
val callSUT = s"""RailFenceCipher.decode("${tc.msg}", ${tc.rails})"""
|
|
42
|
-
val expected = tc.expected
|
|
43
|
-
val result = s"val decoded = $callSUT"
|
|
44
|
-
val checkResult = s"""decoded should be ("$expected")"""
|
|
45
|
-
|
|
46
|
-
TestCaseGen(tc.description, callSUT, expected, result, checkResult)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
testBuilder.addTestCases(encodeTestCases, Some(description))
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
case class RailFenceTestCase(description: String, msg: String, rails: Int, expected: String)
|
|
3
|
+
import testgen.TestSuiteBuilder._
|
|
4
|
+
import testgen._
|
|
54
5
|
|
|
55
6
|
object RailFenceCipherTestGenerator {
|
|
56
7
|
def main(args: Array[String]): Unit = {
|
|
57
|
-
new
|
|
8
|
+
val file = new File("src/main/resources/rail-fence-cipher.json")
|
|
9
|
+
|
|
10
|
+
val code = TestSuiteBuilder.build(file, fromLabeledTest("msg", "rails"))
|
|
11
|
+
println(s"-------------")
|
|
12
|
+
println(code)
|
|
13
|
+
println(s"-------------")
|
|
58
14
|
}
|
|
59
15
|
}
|