trackler 2.1.0.36 → 2.1.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/CONTRIBUTING.md +1 -1
- data/lib/trackler/version.rb +1 -1
- data/lib/trackler.rb +0 -5
- data/tracks/c/config.json +0 -5
- data/tracks/clojure/config.json +177 -59
- data/tracks/clojure/exercises/kindergarten-garden/src/example.clj +10 -8
- data/tracks/elisp/config.json +60 -24
- data/tracks/elixir/exercises/poker/poker_test.exs +1 -1
- data/tracks/fortran/config.json +6 -0
- data/tracks/fortran/exercises/pangram/example.f90 +33 -0
- data/tracks/fortran/exercises/pangram/pangram.fun +42 -0
- data/tracks/go/config.json +10 -4
- data/tracks/go/exercises/acronym/acronym.go +1 -1
- data/tracks/groovy/{SETUP.md → docs/EXERCISE_README_INSERT.md} +0 -0
- data/tracks/haskell/config.json +1 -1
- data/tracks/java/bin/journey-test.sh +3 -0
- data/tracks/java/config.json +14 -14
- data/tracks/java/exercises/binary-search/src/test/java/BinarySearchTest.java +20 -20
- data/tracks/java/exercises/binary-search-tree/src/test/java/BSTTest.java +32 -32
- data/tracks/java/exercises/build.gradle +57 -31
- data/tracks/java/exercises/hello-world/GETTING_STARTED.md +4 -0
- data/tracks/java/exercises/pythagorean-triplet/src/test/java/PythagoreanTripletTest.java +8 -8
- data/tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java +1 -1
- data/tracks/java/exercises/scrabble-score/src/test/java/ScrabbleScoreTest.java +10 -5
- data/tracks/java/exercises/series/src/test/java/SeriesTest.java +20 -20
- data/tracks/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/tracks/java/gradle/wrapper/gradle-wrapper.properties +2 -2
- data/tracks/julia/runtests.jl +1 -6
- data/tracks/kotlin/.gitignore +0 -5
- data/tracks/kotlin/.travis.yml +21 -1
- data/tracks/kotlin/bin/build-jq.sh +11 -0
- data/tracks/kotlin/bin/fetch-configlet +1 -1
- data/tracks/kotlin/bin/journey-test.sh +34 -14
- data/tracks/kotlin/bin/unit-tests.sh +2 -2
- data/tracks/kotlin/config.json +230 -160
- data/tracks/kotlin/exercises/build.gradle +3 -0
- data/tracks/kotlin/exercises/collatz-conjecture/src/test/kotlin/CollatzCalculatorTest.kt +7 -1
- data/tracks/kotlin/exercises/gradle.properties +1 -0
- data/tracks/kotlin/exercises/list-ops/HINTS.md +5 -0
- data/tracks/kotlin/exercises/list-ops/build.gradle +28 -0
- data/tracks/kotlin/exercises/list-ops/src/example/kotlin/CustomListExtensions.kt +43 -0
- data/tracks/kotlin/exercises/list-ops/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/list-ops/src/test/kotlin/ListExtensionsTest.kt +157 -0
- data/tracks/kotlin/exercises/settings.gradle +13 -12
- data/tracks/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/tracks/kotlin/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/tracks/kotlin/gradlew +172 -0
- data/tracks/kotlin/gradlew.bat +84 -0
- data/tracks/lfe/config.json +90 -30
- data/tracks/ocaml/.travis-ci.sh +1 -1
- data/tracks/ocaml/.travis.yml +1 -1
- data/tracks/ocaml/README.md +1 -1
- data/tracks/perl5/.travis.yml +3 -2
- data/tracks/perl6/bin/exercise-gen.pl6 +6 -3
- data/tracks/racket/config.json +63 -21
- data/tracks/ruby/exercises/bob/bob_test.rb +0 -1
- data/tracks/ruby/lib/generator/command_line.rb +7 -3
- data/tracks/ruby/lib/generator/exercise.rb +19 -0
- data/tracks/ruby/lib/generator/files/generator_cases.rb +0 -4
- data/tracks/ruby/lib/generator/files/metadata_files.rb +1 -1
- data/tracks/ruby/lib/generator/files/track_files.rb +3 -3
- data/tracks/ruby/lib/generator/implementation.rb +7 -11
- data/tracks/ruby/lib/generator/template_values.rb +5 -9
- data/tracks/ruby/lib/generator/underscore.rb +4 -0
- data/tracks/ruby/lib/generator.rb +2 -2
- data/tracks/ruby/test/fixtures/xruby/lib/generator/test_template.erb +3 -3
- data/tracks/ruby/test/generator/exercise_test.rb +20 -0
- data/tracks/ruby/test/generator/files/generate_cases_test.rb +0 -4
- data/tracks/ruby/test/generator/files/metadata_files_test.rb +2 -2
- data/tracks/ruby/test/generator/files/track_files_test.rb +4 -5
- data/tracks/ruby/test/generator/implementation_test.rb +12 -20
- data/tracks/ruby/test/generator/template_values_test.rb +2 -33
- data/tracks/ruby/test/generator/underscore_test.rb +4 -0
- data/tracks/ruby/test/generator_test.rb +2 -2
- data/tracks/rust/exercises/gigasecond/Cargo.lock +58 -13
- data/tracks/rust/exercises/gigasecond/Cargo.toml +1 -1
- data/tracks/scala/exercises/acronym/src/test/scala/AcronymTest.scala +32 -12
- data/tracks/scala/exercises/hamming/example.scala +1 -1
- data/tracks/scala/exercises/hamming/src/test/scala/HammingTest.scala +55 -19
- data/tracks/scala/exercises/phone-number/example.scala +10 -20
- data/tracks/scala/exercises/phone-number/src/test/scala/PhoneNumberTest.scala +28 -81
- data/tracks/scala/testgen/src/main/scala/AcronymTestGenerator.scala +16 -0
- data/tracks/scala/testgen/src/main/scala/HammingTestGenerator.scala +34 -0
- data/tracks/scala/testgen/src/main/scala/PhoneNumberTestGenerator.scala +34 -0
- data/tracks/scheme/config.json +43 -16
- metadata +21 -5
- data/lib/trackler/problem.rb +0 -7
- data/lib/trackler/problems.rb +0 -7
@@ -15,7 +15,7 @@ module Generator
|
|
15
15
|
# Doesn't update the version information.
|
16
16
|
class GenerateTests < ImplementationDelegator
|
17
17
|
def call
|
18
|
-
|
18
|
+
build_tests
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,7 +24,7 @@ module Generator
|
|
24
24
|
def call
|
25
25
|
update_tests_version
|
26
26
|
update_example_solution
|
27
|
-
|
27
|
+
build_tests
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'minitest/autorun'
|
3
|
-
require_relative '
|
3
|
+
require_relative '<%= exercise_name %>'
|
4
4
|
|
5
|
-
# Common test data version: <%= abbreviated_commit_hash %>
|
6
|
-
class
|
5
|
+
# Common test data version: <%= canonical_data_version %> <%= abbreviated_commit_hash %>
|
6
|
+
class <%= exercise_name_camel %>Test < Minitest::Test
|
7
7
|
<% test_cases.each_with_index do |test_case, idx| %>
|
8
8
|
def <%= test_case.name %>
|
9
9
|
<%= test_case.skipped(idx) %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Generator
|
4
|
+
class ExerciseTest < Minitest::Test
|
5
|
+
def test_slug
|
6
|
+
exercise = Exercise.new(slug: 'alpha')
|
7
|
+
assert_equal 'alpha', exercise.slug
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_name
|
11
|
+
exercise = Exercise.new(slug: 'alpha-beta')
|
12
|
+
assert_equal 'alpha_beta', exercise.name
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_case_class
|
16
|
+
exercise = Exercise.new(slug: 'alpha-beta')
|
17
|
+
assert_equal 'AlphaBetaCase', exercise.case_class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -11,10 +11,9 @@ module Generator
|
|
11
11
|
class TestTrackFiles
|
12
12
|
def initialize
|
13
13
|
@paths = FixturePaths
|
14
|
-
@
|
15
|
-
@exercise_name = 'alpha_beta'
|
14
|
+
@exercise = Exercise.new(slug: 'alpha-beta')
|
16
15
|
end
|
17
|
-
|
16
|
+
attr_reader :paths, :exercise
|
18
17
|
include TrackFiles
|
19
18
|
end
|
20
19
|
|
@@ -44,9 +43,9 @@ module Generator
|
|
44
43
|
class TestTrackFilesUseDefault
|
45
44
|
def initialize
|
46
45
|
@paths = FixturePaths
|
47
|
-
@
|
46
|
+
@exercise = Exercise.new(slug: 'notemplate')
|
48
47
|
end
|
49
|
-
attr_reader :paths, :
|
48
|
+
attr_reader :paths, :exercise
|
50
49
|
include TrackFiles
|
51
50
|
end
|
52
51
|
|
@@ -8,18 +8,14 @@ module Generator
|
|
8
8
|
)
|
9
9
|
|
10
10
|
def test_version
|
11
|
-
|
11
|
+
exercise = Minitest::Mock.new.expect :slug, 'alpha'
|
12
|
+
subject = Implementation.new(paths: FixturePaths, exercise: exercise)
|
12
13
|
assert_equal 1, subject.version
|
13
14
|
end
|
14
15
|
|
15
|
-
def test_slug
|
16
|
-
subject = Implementation.new(paths: FixturePaths, slug: 'alpha')
|
17
|
-
assert_equal 'alpha', subject.slug
|
18
|
-
end
|
19
|
-
|
20
16
|
def test_update_tests_version
|
21
17
|
mock_file = Minitest::Mock.new.expect :write, '2'.length, [2]
|
22
|
-
subject = Implementation.new(paths: FixturePaths, slug: 'alpha')
|
18
|
+
subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(slug: 'alpha'))
|
23
19
|
# Verify iniital condition from fixture file
|
24
20
|
assert_equal 1, subject.tests_version.to_i
|
25
21
|
File.stub(:open, true, mock_file) do
|
@@ -31,14 +27,14 @@ module Generator
|
|
31
27
|
def test_update_example_solution
|
32
28
|
expected_content = "# This is the example\n\nclass BookKeeping\n VERSION = 1\nend\n"
|
33
29
|
mock_file = Minitest::Mock.new.expect :write, expected_content.length, [expected_content]
|
34
|
-
subject = Implementation.new(paths: FixturePaths, slug: 'alpha')
|
30
|
+
subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(slug: 'alpha'))
|
35
31
|
File.stub(:open, true, mock_file) do
|
36
32
|
assert_equal expected_content, subject.update_example_solution
|
37
33
|
end
|
38
34
|
mock_file.verify
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
37
|
+
def test_build_tests
|
42
38
|
# Q: Is the pain here caused by:
|
43
39
|
# a) Implementation `including` everything rather than using composition?
|
44
40
|
# b) Trying to verify the expected content.
|
@@ -84,34 +80,30 @@ class AlphaTest < Minitest::Test
|
|
84
80
|
end
|
85
81
|
TESTS_FILE
|
86
82
|
mock_file = Minitest::Mock.new.expect :write, expected_content.length, [expected_content]
|
87
|
-
subject = Implementation.new(paths: FixturePaths, slug: 'alpha')
|
83
|
+
subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(slug: 'alpha'))
|
88
84
|
GitCommand.stub(:abbreviated_commit_hash, '123456789') do
|
89
85
|
File.stub(:open, true, mock_file) do
|
90
|
-
assert_equal expected_content, subject.
|
86
|
+
assert_equal expected_content, subject.build_tests
|
91
87
|
end
|
92
88
|
end
|
93
89
|
mock_file.verify
|
94
90
|
# Don't pollute the namespace
|
95
91
|
Object.send(:remove_const, :AlphaCase)
|
96
92
|
end
|
97
|
-
|
98
|
-
def test_exercise_name
|
99
|
-
subject = Implementation.new(paths: FixturePaths, slug: 'alpha-beta')
|
100
|
-
assert_equal 'alpha_beta', subject.exercise_name
|
101
|
-
end
|
102
93
|
end
|
103
94
|
|
104
95
|
class LoggingImplementationTest < Minitest::Test
|
105
|
-
def
|
96
|
+
def test_build_tests
|
97
|
+
exercise = Exercise.new(slug: 'alpha')
|
106
98
|
mock_implementation = Minitest::Mock.new
|
107
|
-
mock_implementation.expect :
|
108
|
-
mock_implementation.expect :
|
99
|
+
mock_implementation.expect :build_tests, nil
|
100
|
+
mock_implementation.expect :exercise, exercise
|
109
101
|
mock_implementation.expect :version, 2
|
110
102
|
mock_logger = Minitest::Mock.new
|
111
103
|
mock_logger.expect :info, nil, ['Generated alpha tests version 2']
|
112
104
|
|
113
105
|
subject = LoggingImplementation.new(implementation: mock_implementation, logger: mock_logger)
|
114
|
-
subject.
|
106
|
+
subject.build_tests
|
115
107
|
|
116
108
|
mock_implementation.verify
|
117
109
|
end
|
@@ -46,8 +46,8 @@ module Generator
|
|
46
46
|
|
47
47
|
class TemplateValuesFactoryTest < Minitest::Test
|
48
48
|
class TestTemplateValuesFactory
|
49
|
-
def
|
50
|
-
'alpha'
|
49
|
+
def exercise
|
50
|
+
Exercise.new(slug: 'alpha')
|
51
51
|
end
|
52
52
|
|
53
53
|
def version
|
@@ -71,37 +71,6 @@ module Generator
|
|
71
71
|
include TemplateValuesFactory
|
72
72
|
end
|
73
73
|
|
74
|
-
class ClassBasedTestTemplateValuesFactory
|
75
|
-
def slug
|
76
|
-
'beta'
|
77
|
-
end
|
78
|
-
|
79
|
-
def version
|
80
|
-
2
|
81
|
-
end
|
82
|
-
|
83
|
-
def canonical_data
|
84
|
-
mock_canonical_data = Minitest::Mock.new
|
85
|
-
mock_canonical_data.expect :abbreviated_commit_hash, nil
|
86
|
-
mock_canonical_data.expect :version, '1.2.3'
|
87
|
-
mock_canonical_data.expect :to_s, '{"cases":[]}'
|
88
|
-
mock_canonical_data
|
89
|
-
end
|
90
|
-
|
91
|
-
def paths
|
92
|
-
mock_paths = Minitest::Mock.new
|
93
|
-
mock_paths.expect :track, 'test/fixtures/xruby'
|
94
|
-
mock_paths
|
95
|
-
end
|
96
|
-
|
97
|
-
include TemplateValuesFactory
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_template_values_from_class
|
101
|
-
subject = ClassBasedTestTemplateValuesFactory.new
|
102
|
-
assert_instance_of TemplateValues, subject.template_values
|
103
|
-
end
|
104
|
-
|
105
74
|
def test_template_values_loads_problem_case_classes
|
106
75
|
subject = TestTemplateValuesFactory.new
|
107
76
|
assert_instance_of TemplateValues, subject.template_values
|
@@ -6,7 +6,7 @@ module Generator
|
|
6
6
|
mock_exercise = Minitest::Mock.new
|
7
7
|
mock_exercise.expect :update_tests_version, nil
|
8
8
|
mock_exercise.expect :update_example_solution, nil
|
9
|
-
mock_exercise.expect :
|
9
|
+
mock_exercise.expect :build_tests, nil
|
10
10
|
|
11
11
|
subject = UpdateVersionAndGenerateTests.new(mock_exercise)
|
12
12
|
subject.call
|
@@ -18,7 +18,7 @@ module Generator
|
|
18
18
|
class UpdateVersionAndGenerateTestsFrozenVersionTest < Minitest::Test
|
19
19
|
def test_call
|
20
20
|
mock_exercise = Minitest::Mock.new
|
21
|
-
mock_exercise.expect :
|
21
|
+
mock_exercise.expect :build_tests, nil
|
22
22
|
|
23
23
|
subject = GenerateTests.new(mock_exercise)
|
24
24
|
subject.call
|
@@ -2,50 +2,83 @@
|
|
2
2
|
name = "gigasecond"
|
3
3
|
version = "1.0.0"
|
4
4
|
dependencies = [
|
5
|
-
"chrono 0.
|
5
|
+
"chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
6
6
|
]
|
7
7
|
|
8
8
|
[[package]]
|
9
9
|
name = "chrono"
|
10
|
-
version = "0.
|
10
|
+
version = "0.3.1"
|
11
11
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
12
12
|
dependencies = [
|
13
|
-
"num 0.1.
|
14
|
-
"time 0.1.
|
13
|
+
"num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
14
|
+
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
15
15
|
]
|
16
16
|
|
17
17
|
[[package]]
|
18
18
|
name = "kernel32-sys"
|
19
|
-
version = "0.2.
|
19
|
+
version = "0.2.2"
|
20
20
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
21
21
|
dependencies = [
|
22
|
-
"winapi 0.2.
|
22
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
23
23
|
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
24
24
|
]
|
25
25
|
|
26
26
|
[[package]]
|
27
27
|
name = "libc"
|
28
|
-
version = "0.2.
|
28
|
+
version = "0.2.23"
|
29
29
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
30
30
|
|
31
31
|
[[package]]
|
32
32
|
name = "num"
|
33
|
-
version = "0.1.
|
33
|
+
version = "0.1.39"
|
34
34
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
35
|
+
dependencies = [
|
36
|
+
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
37
|
+
"num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
38
|
+
"num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
39
|
+
]
|
35
40
|
|
36
41
|
[[package]]
|
37
|
-
name = "
|
42
|
+
name = "num-integer"
|
38
43
|
version = "0.1.34"
|
39
44
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
40
45
|
dependencies = [
|
41
|
-
"
|
42
|
-
|
43
|
-
|
46
|
+
"num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
47
|
+
]
|
48
|
+
|
49
|
+
[[package]]
|
50
|
+
name = "num-iter"
|
51
|
+
version = "0.1.33"
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
53
|
+
dependencies = [
|
54
|
+
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
55
|
+
"num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
56
|
+
]
|
57
|
+
|
58
|
+
[[package]]
|
59
|
+
name = "num-traits"
|
60
|
+
version = "0.1.39"
|
61
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
62
|
+
|
63
|
+
[[package]]
|
64
|
+
name = "redox_syscall"
|
65
|
+
version = "0.1.18"
|
66
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
67
|
+
|
68
|
+
[[package]]
|
69
|
+
name = "time"
|
70
|
+
version = "0.1.37"
|
71
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
72
|
+
dependencies = [
|
73
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
74
|
+
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
75
|
+
"redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
76
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
44
77
|
]
|
45
78
|
|
46
79
|
[[package]]
|
47
80
|
name = "winapi"
|
48
|
-
version = "0.2.
|
81
|
+
version = "0.2.8"
|
49
82
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
50
83
|
|
51
84
|
[[package]]
|
@@ -53,3 +86,15 @@ name = "winapi-build"
|
|
53
86
|
version = "0.1.1"
|
54
87
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
55
88
|
|
89
|
+
[metadata]
|
90
|
+
"checksum chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9123be86fd2a8f627836c235ecdf331fdd067ecf7ac05aa1a68fbcf2429f056"
|
91
|
+
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
92
|
+
"checksum libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e7eb6b826bfc1fdea7935d46556250d1799b7fe2d9f7951071f4291710665e3e"
|
93
|
+
"checksum num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "2c3a3dc9f30bf824141521b30c908a859ab190b76e20435fcd89f35eb6583887"
|
94
|
+
"checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37"
|
95
|
+
"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e"
|
96
|
+
"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6"
|
97
|
+
"checksum redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "3041aeb6000db123d2c9c751433f526e1f404b23213bd733167ab770c3989b4d"
|
98
|
+
"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3"
|
99
|
+
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
100
|
+
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
@@ -1,15 +1,35 @@
|
|
1
|
-
import org.scalatest.{FlatSpec, Matchers}
|
2
1
|
|
3
|
-
|
4
|
-
private val acronyms = List(
|
5
|
-
("Portable Network Graphics", "PNG"),
|
6
|
-
("Ruby on Rails", "ROR"),
|
7
|
-
("HyperText Markup Language", "HTML"),
|
8
|
-
("First In, First Out", "FIFO"),
|
9
|
-
("PHP: Hypertext Preprocessor", "PHP"),
|
10
|
-
("Complementary metal-oxide semiconductor", "CMOS"))
|
2
|
+
import org.scalatest.{Matchers, FunSuite}
|
11
3
|
|
12
|
-
|
13
|
-
|
4
|
+
/** @version 1.1.0 */
|
5
|
+
class AcronymTest extends FunSuite with Matchers {
|
6
|
+
|
7
|
+
test("basic") {
|
8
|
+
Acronym.abbreviate("Portable Network Graphics") should be ("PNG")
|
9
|
+
}
|
10
|
+
|
11
|
+
test("lowercase words") {
|
12
|
+
pending
|
13
|
+
Acronym.abbreviate("Ruby on Rails") should be ("ROR")
|
14
|
+
}
|
15
|
+
|
16
|
+
test("punctuation") {
|
17
|
+
pending
|
18
|
+
Acronym.abbreviate("First In, First Out") should be ("FIFO")
|
19
|
+
}
|
20
|
+
|
21
|
+
test("all caps words") {
|
22
|
+
pending
|
23
|
+
Acronym.abbreviate("PHP: Hypertext Preprocessor") should be ("PHP")
|
24
|
+
}
|
25
|
+
|
26
|
+
test("non-acronym all caps word") {
|
27
|
+
pending
|
28
|
+
Acronym.abbreviate("GNU Image Manipulation Program") should be ("GIMP")
|
29
|
+
}
|
30
|
+
|
31
|
+
test("hyphenated") {
|
32
|
+
pending
|
33
|
+
Acronym.abbreviate("Complementary metal-oxide semiconductor") should be ("CMOS")
|
14
34
|
}
|
15
|
-
}
|
35
|
+
}
|
@@ -1,43 +1,79 @@
|
|
1
|
-
import org.scalatest.
|
1
|
+
import org.scalatest.{Matchers, FunSuite}
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
/** @version 1.0.0 */
|
4
|
+
class HammingTest extends FunSuite with Matchers {
|
5
|
+
|
6
|
+
test("identical strands") {
|
7
|
+
Hamming.distance("A", "A") should be (Some(0))
|
8
|
+
}
|
9
|
+
|
10
|
+
test("long identical strands") {
|
11
|
+
pending
|
12
|
+
Hamming.distance("GGACTGA", "GGACTGA") should be (Some(0))
|
6
13
|
}
|
7
14
|
|
8
|
-
|
15
|
+
test("complete distance in single nucleotide strands") {
|
9
16
|
pending
|
10
|
-
Hamming.
|
17
|
+
Hamming.distance("A", "G") should be (Some(1))
|
11
18
|
}
|
12
19
|
|
13
|
-
|
20
|
+
test("complete distance in small strands") {
|
14
21
|
pending
|
15
|
-
Hamming.
|
22
|
+
Hamming.distance("AG", "CT") should be (Some(2))
|
16
23
|
}
|
17
24
|
|
18
|
-
|
25
|
+
test("small distance in small strands") {
|
19
26
|
pending
|
20
|
-
Hamming.
|
27
|
+
Hamming.distance("AT", "CT") should be (Some(1))
|
21
28
|
}
|
22
29
|
|
23
|
-
|
30
|
+
test("small distance") {
|
24
31
|
pending
|
25
|
-
Hamming.
|
32
|
+
Hamming.distance("GGACG", "GGTCG") should be (Some(1))
|
26
33
|
}
|
27
34
|
|
28
|
-
|
35
|
+
test("small distance in long strands") {
|
29
36
|
pending
|
30
|
-
Hamming.
|
37
|
+
Hamming.distance("ACCAGGG", "ACTATGG") should be (Some(2))
|
31
38
|
}
|
32
39
|
|
33
|
-
|
40
|
+
test("non-unique character in first strand") {
|
34
41
|
pending
|
35
|
-
Hamming.
|
42
|
+
Hamming.distance("AGA", "AGG") should be (Some(1))
|
36
43
|
}
|
37
44
|
|
38
|
-
|
45
|
+
test("non-unique character in second strand") {
|
39
46
|
pending
|
40
|
-
Hamming.
|
47
|
+
Hamming.distance("AGG", "AGA") should be (Some(1))
|
41
48
|
}
|
42
|
-
}
|
43
49
|
|
50
|
+
test("same nucleotides in different positions") {
|
51
|
+
pending
|
52
|
+
Hamming.distance("TAG", "GAT") should be (Some(2))
|
53
|
+
}
|
54
|
+
|
55
|
+
test("large distance") {
|
56
|
+
pending
|
57
|
+
Hamming.distance("GATACA", "GCATAA") should be (Some(4))
|
58
|
+
}
|
59
|
+
|
60
|
+
test("large distance in off-by-one strand") {
|
61
|
+
pending
|
62
|
+
Hamming.distance("GGACGGATTCTG", "AGGACGGATTCT") should be (Some(9))
|
63
|
+
}
|
64
|
+
|
65
|
+
test("empty strands") {
|
66
|
+
pending
|
67
|
+
Hamming.distance("", "") should be (Some(0))
|
68
|
+
}
|
69
|
+
|
70
|
+
test("disallow first strand longer") {
|
71
|
+
pending
|
72
|
+
Hamming.distance("AATG", "AAA") should be (None)
|
73
|
+
}
|
74
|
+
|
75
|
+
test("disallow second strand longer") {
|
76
|
+
pending
|
77
|
+
Hamming.distance("ATA", "AGTG") should be (None)
|
78
|
+
}
|
79
|
+
}
|
@@ -1,18 +1,3 @@
|
|
1
|
-
import PhoneNumber._
|
2
|
-
|
3
|
-
class PhoneNumber(phoneNumber: String) {
|
4
|
-
|
5
|
-
lazy val parts: Option[Parts] = parse(phoneNumber)
|
6
|
-
|
7
|
-
lazy val number: Option[String] =
|
8
|
-
parts map { case (areaCode, prefix, lineNumber) => s"$areaCode$prefix$lineNumber" }
|
9
|
-
|
10
|
-
lazy val areaCode: Option[String] = parts map (_._1)
|
11
|
-
|
12
|
-
lazy val prettyPrint: Option[String] =
|
13
|
-
parts map { case (areaCode, prefix, lineNumber) => s"($areaCode) $prefix-$lineNumber" }
|
14
|
-
}
|
15
|
-
|
16
1
|
object PhoneNumber {
|
17
2
|
type Parts = (String, String, String)
|
18
3
|
|
@@ -25,11 +10,16 @@ object PhoneNumber {
|
|
25
10
|
s"""1?${part(AreaCodeLength)}${part(PrefixLength)}${part(LineNumberLength)}""".r
|
26
11
|
}
|
27
12
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
def clean(phoneNumber: String): Option[String] = {
|
14
|
+
phoneNumber filter (_.isDigit) match {
|
15
|
+
case PhoneNumberPattern(areaCode, prefix, lineNumber) => {
|
16
|
+
val areaCodeFirst = areaCode.head.asDigit
|
17
|
+
val prefixFirst = prefix.head.asDigit
|
18
|
+
if (areaCodeFirst >= 2 && prefixFirst >= 2)
|
19
|
+
Option(areaCode + prefix + lineNumber)
|
20
|
+
else
|
21
|
+
None
|
22
|
+
}
|
33
23
|
case _ => None
|
34
24
|
}
|
35
25
|
}
|