trackler 2.0.7.0 → 2.0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/common/exercises/counter/metadata.yml +0 -4
  4. data/common/exercises/error-handling/metadata.yml +0 -4
  5. data/common/exercises/etl/canonical-data.json +1 -1
  6. data/common/exercises/hello-world/canonical-data.json +9 -21
  7. data/common/exercises/hello-world/description.md +7 -42
  8. data/common/exercises/hello-world/metadata.yml +1 -1
  9. data/common/exercises/lens-person/metadata.yml +0 -3
  10. data/common/exercises/luhn/canonical-data.json +17 -17
  11. data/common/exercises/nucleotide-codons/metadata.yml +0 -2
  12. data/common/exercises/react/metadata.yml +0 -2
  13. data/common/exercises/rectangles/metadata.yml +0 -3
  14. data/common/exercises/variable-length-quantity/metadata.yml +0 -2
  15. data/fixtures/tracks/snowflake/config.json +17 -0
  16. data/fixtures/tracks/snowflake/exercises/snowflake-only/description.md +1 -0
  17. data/fixtures/tracks/snowflake/exercises/snowflake-only/metadata.yml +4 -0
  18. data/lib/trackler/description.rb +27 -0
  19. data/lib/trackler/guaranteed_file.rb +77 -0
  20. data/lib/trackler/implementations.rb +5 -5
  21. data/lib/trackler/metadata.rb +27 -0
  22. data/lib/trackler/null_track.rb +22 -0
  23. data/lib/trackler/problem.rb +32 -34
  24. data/lib/trackler/track.rb +1 -1
  25. data/lib/trackler/version.rb +1 -1
  26. data/tracks/csharp/exercises/hello-world/Example.cs +2 -5
  27. data/tracks/csharp/exercises/hello-world/HelloWorldTest.cs +2 -16
  28. data/tracks/elixir/config.json +7 -0
  29. data/tracks/elixir/exercises/series/example.exs +13 -0
  30. data/tracks/elixir/exercises/series/series.exs +11 -0
  31. data/tracks/elixir/exercises/series/series_test.exs +53 -0
  32. data/tracks/erlang/README.md +3 -3
  33. data/tracks/erlang/config.json +15 -11
  34. data/tracks/erlang/exercises/{binary → all-your-base}/include/exercism.hrl +0 -0
  35. data/tracks/erlang/exercises/{binary → all-your-base}/rebar.config +0 -0
  36. data/tracks/erlang/exercises/{trinary/src/trinary.app.src → all-your-base/src/all_your_base.app.src} +2 -2
  37. data/tracks/erlang/exercises/all-your-base/src/example.erl +33 -0
  38. data/tracks/erlang/exercises/all-your-base/test/all_your_base_tests.erl +69 -0
  39. data/tracks/erlang/exercises/hello-world/src/example.erl +4 -4
  40. data/tracks/erlang/exercises/hello-world/test/hello_world_tests.erl +3 -12
  41. data/tracks/erlang/exercises/{trinary → rotational-cipher}/include/exercism.hrl +0 -0
  42. data/tracks/erlang/exercises/{trinary → rotational-cipher}/rebar.config +8 -1
  43. data/tracks/erlang/exercises/rotational-cipher/src/example.erl +19 -0
  44. data/tracks/erlang/exercises/{binary/src/binary.app.src → rotational-cipher/src/rotational_cipher.app.src} +2 -2
  45. data/tracks/erlang/exercises/rotational-cipher/test/rotational_cipher_tests.erl +98 -0
  46. data/tracks/fsharp/exercises/grep/GrepTest.fs +57 -0
  47. data/tracks/fsharp/exercises/hello-world/Example.fs +1 -1
  48. data/tracks/fsharp/exercises/hello-world/HelloWorldTest.fs +2 -12
  49. data/tracks/go/.travis.yml +7 -15
  50. data/tracks/go/exercises/hello-world/example.go +4 -8
  51. data/tracks/go/exercises/hello-world/hello_test.go +20 -16
  52. data/tracks/go/exercises/hello-world/hello_world.go +12 -2
  53. data/tracks/groovy/exercises/hello-world/Example.groovy +2 -2
  54. data/tracks/groovy/exercises/hello-world/HelloWorld.groovy +1 -1
  55. data/tracks/groovy/exercises/hello-world/HelloWorldSpec.groovy +1 -14
  56. data/tracks/haskell/config.json +6 -0
  57. data/tracks/haskell/exercises/hello-world/HINTS.md +6 -0
  58. data/tracks/haskell/exercises/hello-world/examples/success-standard/package.yaml +16 -0
  59. data/tracks/haskell/exercises/hello-world/examples/success-standard/src/HelloWorld.hs +4 -0
  60. data/tracks/haskell/exercises/hello-world/package.yaml +19 -0
  61. data/tracks/haskell/exercises/hello-world/src/HelloWorld.hs +4 -0
  62. data/tracks/haskell/exercises/hello-world/stack.yaml +1 -0
  63. data/tracks/haskell/exercises/hello-world/test/Tests.hs +13 -0
  64. data/tracks/idris/config.json +9 -0
  65. data/tracks/idris/exercises/leap/Leap.ipkg +5 -0
  66. data/tracks/idris/exercises/leap/Makefile +23 -0
  67. data/tracks/idris/exercises/leap/src/Leap.idr +5 -0
  68. data/tracks/idris/exercises/leap/src/Test/Leap.idr +37 -0
  69. data/tracks/idris/exercises/leap/src/example.idr +8 -0
  70. data/tracks/{typescript/exercises → java}/.keep +0 -0
  71. data/tracks/java/config.json +115 -172
  72. data/tracks/java/exercises/anagram/src/test/java/AnagramTest.java +41 -13
  73. data/tracks/java/exercises/list-ops/build.gradle +18 -0
  74. data/tracks/java/exercises/list-ops/src/example/java/ListOps.java +51 -0
  75. data/tracks/java/exercises/list-ops/src/main/java/.keep +0 -0
  76. data/tracks/java/exercises/list-ops/src/test/java/ListOpsTest.java +316 -0
  77. data/tracks/java/exercises/palindrome-products/src/example/java/Palindromes.java +28 -62
  78. data/tracks/java/exercises/palindrome-products/src/test/java/PalindromesTest.java +26 -83
  79. data/tracks/java/exercises/settings.gradle +1 -0
  80. data/tracks/julia/config.json +1 -2
  81. data/tracks/julia/exercises/hello-world/example.jl +2 -2
  82. data/tracks/julia/exercises/hello-world/runtests.jl +1 -6
  83. data/tracks/lua/exercises/TRACK_HINTS.md +8 -0
  84. data/tracks/lua/exercises/hello-world/example.lua +2 -3
  85. data/tracks/lua/exercises/hello-world/hello-world.lua +18 -0
  86. data/tracks/lua/exercises/hello-world/hello-world_spec.lua +6 -12
  87. data/tracks/ocaml/exercises/phone-number/example.ml +8 -18
  88. data/tracks/ocaml/exercises/phone-number/phone_number.mli +1 -7
  89. data/tracks/ocaml/exercises/phone-number/test.ml +24 -23
  90. data/tracks/ocaml/tools/test-generator/src/special_cases.ml +6 -0
  91. data/tracks/ocaml/tools/test-generator/templates/phone-number/template.ml +21 -0
  92. data/tracks/pony/config.json +2 -2
  93. data/tracks/pony/exercises/hello-world/example.pony +1 -2
  94. data/tracks/pony/exercises/hello-world/test.pony +0 -1
  95. data/tracks/rust/config.json +0 -1
  96. data/tracks/rust/exercises/hello-world/example.rs +2 -5
  97. data/tracks/rust/exercises/hello-world/tests/hello-world.rs +2 -14
  98. data/tracks/scala/config.json +11 -2
  99. data/tracks/scala/docs/LEARNING.md +10 -2
  100. data/tracks/scala/docs/RESOURCES.md +0 -1
  101. data/tracks/scala/docs/TESTS.md +10 -6
  102. data/tracks/scala/exercises/rail-fence-cipher/build.sbt +3 -0
  103. data/tracks/scala/exercises/rail-fence-cipher/example.scala +46 -0
  104. data/tracks/scala/exercises/rail-fence-cipher/src/main/scala/RailFenceCipher.scala +0 -0
  105. data/tracks/scala/exercises/rail-fence-cipher/src/test/scala/RailFenceCipherTest.scala +42 -0
  106. data/tracks/scala/testgen/src/main/scala/RailFenceCipherTestGenerator.scala +59 -0
  107. data/tracks/typescript/.gitignore +7 -0
  108. data/tracks/typescript/.travis.yml +18 -1
  109. data/tracks/typescript/Dangerfile +43 -0
  110. data/tracks/typescript/Makefile +57 -0
  111. data/tracks/typescript/README.md +38 -5
  112. data/tracks/typescript/SETUP.md +24 -0
  113. data/tracks/typescript/common/package.json +37 -0
  114. data/tracks/typescript/common/tsconfig.json +21 -0
  115. data/tracks/typescript/common/tslint.json +127 -0
  116. data/tracks/typescript/common/yarn.lock +2697 -0
  117. data/tracks/typescript/config.json +82 -2
  118. data/tracks/typescript/docs/ABOUT.md +1 -0
  119. data/tracks/typescript/docs/INSTALLATION.md +17 -0
  120. data/tracks/typescript/docs/LEARNING.md +8 -0
  121. data/tracks/typescript/docs/RESOURCES.md +7 -0
  122. data/tracks/typescript/docs/TESTS.md +36 -0
  123. data/tracks/typescript/exercises/anagram/anagram.example.ts +23 -0
  124. data/tracks/typescript/exercises/anagram/anagram.test.ts +82 -0
  125. data/tracks/typescript/exercises/anagram/package.json +37 -0
  126. data/tracks/typescript/exercises/anagram/tsconfig.json +21 -0
  127. data/tracks/typescript/exercises/anagram/tslint.json +127 -0
  128. data/tracks/typescript/exercises/anagram/yarn.lock +2697 -0
  129. data/tracks/typescript/exercises/beer-song/beer-song.example.ts +36 -0
  130. data/tracks/typescript/exercises/beer-song/beer-song.test.ts +360 -0
  131. data/tracks/typescript/exercises/beer-song/package.json +37 -0
  132. data/tracks/typescript/exercises/beer-song/tsconfig.json +21 -0
  133. data/tracks/typescript/exercises/beer-song/tslint.json +127 -0
  134. data/tracks/typescript/exercises/beer-song/yarn.lock +2697 -0
  135. data/tracks/typescript/exercises/bob/bob.example.ts +24 -0
  136. data/tracks/typescript/exercises/bob/bob.test.ts +92 -0
  137. data/tracks/typescript/exercises/bob/package.json +37 -0
  138. data/tracks/typescript/exercises/bob/tsconfig.json +21 -0
  139. data/tracks/typescript/exercises/bob/tslint.json +127 -0
  140. data/tracks/typescript/exercises/bob/yarn.lock +2697 -0
  141. data/tracks/typescript/exercises/gigasecond/gigasecond.example.ts +11 -0
  142. data/tracks/typescript/exercises/gigasecond/gigasecond.test.ts +29 -0
  143. data/tracks/typescript/exercises/gigasecond/package.json +37 -0
  144. data/tracks/typescript/exercises/gigasecond/tsconfig.json +21 -0
  145. data/tracks/typescript/exercises/gigasecond/tslint.json +127 -0
  146. data/tracks/typescript/exercises/gigasecond/yarn.lock +2697 -0
  147. data/tracks/typescript/exercises/hamming/hamming.example.ts +19 -0
  148. data/tracks/typescript/exercises/hamming/hamming.test.ts +39 -0
  149. data/tracks/typescript/exercises/hamming/package.json +37 -0
  150. data/tracks/typescript/exercises/hamming/tsconfig.json +21 -0
  151. data/tracks/typescript/exercises/hamming/tslint.json +127 -0
  152. data/tracks/typescript/exercises/hamming/yarn.lock +2697 -0
  153. data/tracks/typescript/exercises/hello-world/hello-world.example.ts +8 -0
  154. data/tracks/typescript/exercises/hello-world/hello-world.test.ts +17 -0
  155. data/tracks/typescript/exercises/hello-world/package.json +37 -0
  156. data/tracks/typescript/exercises/hello-world/tsconfig.json +21 -0
  157. data/tracks/typescript/exercises/hello-world/tslint.json +127 -0
  158. data/tracks/typescript/exercises/hello-world/yarn.lock +2697 -0
  159. data/tracks/typescript/exercises/leap/leap.example.ts +6 -0
  160. data/tracks/typescript/exercises/leap/leap.test.ts +39 -0
  161. data/tracks/typescript/exercises/leap/package.json +37 -0
  162. data/tracks/typescript/exercises/leap/tsconfig.json +21 -0
  163. data/tracks/typescript/exercises/leap/tslint.json +127 -0
  164. data/tracks/typescript/exercises/leap/yarn.lock +2697 -0
  165. data/tracks/typescript/exercises/pangram/package.json +37 -0
  166. data/tracks/typescript/exercises/pangram/pangram.example.ts +32 -0
  167. data/tracks/typescript/exercises/pangram/pangram.test.ts +50 -0
  168. data/tracks/typescript/exercises/pangram/tsconfig.json +21 -0
  169. data/tracks/typescript/exercises/pangram/tslint.json +127 -0
  170. data/tracks/typescript/exercises/pangram/yarn.lock +2697 -0
  171. data/tracks/typescript/exercises/phone-number/package.json +37 -0
  172. data/tracks/typescript/exercises/phone-number/phone-number.example.ts +21 -0
  173. data/tracks/typescript/exercises/phone-number/phone-number.test.ts +55 -0
  174. data/tracks/typescript/exercises/phone-number/tsconfig.json +21 -0
  175. data/tracks/typescript/exercises/phone-number/tslint.json +127 -0
  176. data/tracks/typescript/exercises/phone-number/yarn.lock +2697 -0
  177. data/tracks/typescript/exercises/rna-transcription/package.json +37 -0
  178. data/tracks/typescript/exercises/rna-transcription/rna-transcription.example.ts +13 -0
  179. data/tracks/typescript/exercises/rna-transcription/rna-transcription.test.ts +45 -0
  180. data/tracks/typescript/exercises/rna-transcription/tsconfig.json +21 -0
  181. data/tracks/typescript/exercises/rna-transcription/tslint.json +127 -0
  182. data/tracks/typescript/exercises/rna-transcription/yarn.lock +2697 -0
  183. data/tracks/typescript/exercises/say/package.json +37 -0
  184. data/tracks/typescript/exercises/say/say.example.ts +95 -0
  185. data/tracks/typescript/exercises/say/say.test.ts +78 -0
  186. data/tracks/typescript/exercises/say/tsconfig.json +21 -0
  187. data/tracks/typescript/exercises/say/tslint.json +127 -0
  188. data/tracks/typescript/exercises/say/yarn.lock +2697 -0
  189. data/tracks/typescript/exercises/word-count/package.json +37 -0
  190. data/tracks/typescript/exercises/word-count/tsconfig.json +21 -0
  191. data/tracks/typescript/exercises/word-count/tslint.json +127 -0
  192. data/tracks/typescript/exercises/word-count/word-count.example.ts +16 -0
  193. data/tracks/typescript/exercises/word-count/word-count.test.ts +65 -0
  194. data/tracks/typescript/exercises/word-count/yarn.lock +2697 -0
  195. data/tracks/typescript/exercises/wordy/package.json +37 -0
  196. data/tracks/typescript/exercises/wordy/tsconfig.json +21 -0
  197. data/tracks/typescript/exercises/wordy/tslint.json +127 -0
  198. data/tracks/typescript/exercises/wordy/wordy.example.ts +40 -0
  199. data/tracks/typescript/exercises/wordy/wordy.test.ts +89 -0
  200. data/tracks/typescript/exercises/wordy/yarn.lock +2697 -0
  201. data/tracks/typescript/img/icon.png +0 -0
  202. data/tracks/typescript/img/icon.svg +10 -0
  203. metadata +134 -15
  204. data/tracks/erlang/exercises/binary/src/example.erl +0 -20
  205. data/tracks/erlang/exercises/binary/test/binary_string_tests.erl +0 -26
  206. data/tracks/erlang/exercises/trinary/Makefile +0 -10
  207. data/tracks/erlang/exercises/trinary/src/example.erl +0 -66
  208. data/tracks/erlang/exercises/trinary/test/trinary_tests.erl +0 -36
  209. data/tracks/fsharp/exercises/hello-world/HINTS.md +0 -5
@@ -33,10 +33,16 @@ let optional_strings ~(f: string -> bool) (parameters: (string * json) list): (s
33
33
  else (k, json_to_string v) in
34
34
  List.map ~f:replace parameters
35
35
 
36
+ let option_of_null (value: json): string = match value with
37
+ | `Null -> "None"
38
+ | `String s -> "(Some \"" ^ s ^ "\")"
39
+ | _ -> failwith "cannot handle this type"
40
+
36
41
  let edit_expected ~(stringify: json -> string) ~(slug: string) ~(value: json) = match slug with
37
42
  | "hamming" -> optional_int ~none:(-1) value
38
43
  | "all-your-base" -> optional_int_list value
39
44
  | "say" -> optional_int_or_string ~none:(-1) value
45
+ | "phone-number" -> option_of_null value
40
46
  | _ -> stringify value
41
47
 
42
48
  let edit_say (ps: (string * json) list) =
@@ -0,0 +1,21 @@
1
+ open Core.Std
2
+ open OUnit2
3
+ open Phone_number
4
+
5
+ let option_to_string f = function
6
+ | None -> "None"
7
+ | Some x -> "Some " ^ f x
8
+
9
+ let ae exp got _test_ctxt =
10
+ assert_equal ~printer:(option_to_string String.to_string) exp got
11
+
12
+ let (* SUITE *)$(suite_name)_tests = [
13
+ (* TEST
14
+ "$description" >::
15
+ ae $expected (number $phrase);
16
+ END TEST *)
17
+ ]
18
+ (* END SUITE *)
19
+
20
+ let () =
21
+ run_test_tt_main ("phone-number tests" >::: number_tests)
@@ -13,8 +13,8 @@
13
13
  "slug": "hello-world",
14
14
  "difficulty": 1,
15
15
  "topics": [
16
- "strings",
17
- "default arguments"
16
+ "primitives",
17
+ "methods"
18
18
  ]
19
19
  },
20
20
  {
@@ -1,3 +1,2 @@
1
1
  primitive HelloWorld
2
- fun hello(name: String = "World"): String =>
3
- "Hello, " + name + "!"
2
+ fun hello(): String => "Hello, World!"
@@ -12,4 +12,3 @@ class iso _TestHelloWorld is UnitTest
12
12
 
13
13
  fun apply(h: TestHelper) =>
14
14
  h.assert_eq[String]("Hello, World!", HelloWorld.hello())
15
- h.assert_eq[String]("Hello, Exercism!", HelloWorld.hello("Exercism"))
@@ -8,7 +8,6 @@
8
8
  "slug": "hello-world",
9
9
  "difficulty": 1,
10
10
  "topics": [
11
- "Some/None",
12
11
  "println!"
13
12
  ]
14
13
  },
@@ -1,6 +1,3 @@
1
- pub fn hello(name: Option<&str>) -> String {
2
- match name {
3
- Some(n) => format!("Hello, {}!", n),
4
- None => "Hello, World!".to_string(),
5
- }
1
+ pub fn hello() -> &'static str {
2
+ "Hello, World!"
6
3
  }
@@ -1,18 +1,6 @@
1
1
  extern crate hello_world;
2
2
 
3
3
  #[test]
4
- fn test_no_name() {
5
- assert_eq!("Hello, World!", hello_world::hello(None));
6
- }
7
-
8
- #[test]
9
- #[ignore]
10
- fn test_sample_name() {
11
- assert_eq!("Hello, Alice!", hello_world::hello(Some("Alice")));
12
- }
13
-
14
- #[test]
15
- #[ignore]
16
- fn test_other_same_name() {
17
- assert_eq!("Hello, Bob!", hello_world::hello(Some("Bob")));
4
+ fn test_hello_world() {
5
+ assert_eq!("Hello, World!", hello_world::hello());
18
6
  }
@@ -593,6 +593,15 @@
593
593
  "Searching"
594
594
  ]
595
595
  },
596
+ {
597
+ "slug":"rail-fence-cipher",
598
+ "difficulty":1,
599
+ "topics":[
600
+ "Strings",
601
+ "Algorithms",
602
+ "Transforming"
603
+ ]
604
+ },
596
605
  {
597
606
  "slug":"dominoes",
598
607
  "difficulty":1,
@@ -653,7 +662,7 @@
653
662
  "slug":"lens-person",
654
663
  "difficulty":1,
655
664
  "topics":[
656
-
665
+
657
666
  ]
658
667
  },
659
668
  {
@@ -680,6 +689,6 @@
680
689
  "testgen"
681
690
  ],
682
691
  "foregone":[
683
-
692
+
684
693
  ]
685
694
  }
@@ -1,3 +1,11 @@
1
- The creator of the languague, Martin Odersky, teaches an online class that introduces the basics of Scala and requires previous knowledge of another programming language:
1
+ ## Books
2
2
 
3
- [Functional Programming Principles in Scala](https://www.coursera.org/learn/progfun1)
3
+ * [Programming Scala - Dean Wampler, Ph.D.](http://shop.oreilly.com/product/0636920033073.do)
4
+ * [Programming in Scala - Oderksy, Spoon, Venners](http://www.artima.com/shop/programming_in_scala_3ed)
5
+ * [Functional Programming in Scala - Chiusano, Bjarnason](https://www.manning.com/books/functional-programming-in-scala)
6
+ * [Scala for the Impatient - Cay S. Horstmann](http://horstmann.com/scala/)
7
+
8
+ ## Online Courses
9
+
10
+ * [Functional Programming Principles in Scala](https://www.coursera.org/learn/progfun1) - In this course you will discover the elements of the functional programming style and learn how to apply them usefully in your daily programming tasks. You will also develop a solid foundation for reasoning about functional programs, by touching upon proofs of invariants and the tracing of execution symbolically.
11
+ * [Functional Program Design in Scala](https://www.coursera.org/learn/progfun2) - In this course you will learn how to apply the functional programming style in the design of larger applications.
@@ -3,7 +3,6 @@
3
3
  Exercism provides exercises and feedback but can be difficult to jump into for those learning Scala for the first time. These resources can help you get started:
4
4
 
5
5
  * [Scala - Getting Started](http://www.scala-lang.org/documentation/getting-started.html)
6
- * [Programming Scala](http://www.oreilly.com/ofps/)
7
6
  * [StackOverflow](http://stackoverflow.com/)
8
7
  * [Scala Exercises](https://www.scala-exercises.org/std_lib)
9
8
  * [The Neophyte's Guide to Scala](http://danielwestheide.com/scala/neophytes.html)
@@ -1,20 +1,24 @@
1
1
  ## Running Tests
2
2
 
3
- Execute the tests with:
3
+ With `sbt` installed, the tests can be executed from the command line with:
4
4
 
5
5
  ```bash
6
6
  $ sbt test
7
7
  ```
8
8
 
9
- You can also use sbt to re-run your tests whenever the source files change:
9
+ You can also use `sbt` to re-run your tests whenever the source files change:
10
10
 
11
11
  ```bash
12
12
  $ sbt
13
13
  >~ test
14
14
  ```
15
15
 
16
- You should place your code in:
16
+ Note that all tests have been disabled except the first one for you to work on.
17
+ To continue, just remove the `pending` keyword from the beginning of each test case.
18
+
19
+ Tests can also be run within the following IDEs
20
+
21
+ * [IntelliJ IDEA with Scala Plugin](https://www.jetbrains.com/idea/)
22
+ * [ScalaIDE](http://scala-ide.org/index.html)
23
+ * [NetBeans with Scala Plugin](https://netbeans.org/)
17
24
 
18
- ```bash
19
- src/main/scala/bob.scala
20
- ```
@@ -0,0 +1,3 @@
1
+ scalaVersion := "2.12.1"
2
+
3
+ libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
@@ -0,0 +1,46 @@
1
+ case class RailFenceCipher(rails: Int) {
2
+ private val size = rails * 2 - 2
3
+
4
+ def encode(clearText: String): String =
5
+ clearText
6
+ .zipWithIndex
7
+ .map { case (c, i) => (track(i), c) }
8
+ .groupBy {_._1}
9
+ .toSeq
10
+ .sortBy { case (t, _) => t }
11
+ .flatMap { case (t, v) => v.map { case (_, c) => c }}
12
+ .mkString
13
+
14
+ def decode (encodedText: String): String =
15
+ Range.apply(0, encodedText.length)
16
+ .groupBy(i => track(i))
17
+ .toSeq
18
+ .sortBy{ case (i, _) => i}
19
+ .flatMap { case (_, v) => v }
20
+ .zip(encodedText)
21
+ .sortBy { case (i, _) => i }
22
+ .map { case (_, c) => c }
23
+ .mkString
24
+
25
+ private def track(i: Int): Int = {
26
+ if (isCorrectRail(i))
27
+ 0
28
+ else if (isCorrectRail(i - rails + 1)) {
29
+ rails - 1
30
+ } else
31
+ Range.inclusive(1, rails - 1)
32
+ .filter{j => isCorrectRail(i - j) || isCorrectRail(i - size + j)}
33
+ .head
34
+ }
35
+
36
+ private def isCorrectRail(i: Int) = i % size == 0
37
+ }
38
+
39
+ object RailFenceCipher {
40
+
41
+ def encode(clearText: String, rails: Int): String =
42
+ RailFenceCipher(rails).encode(clearText)
43
+
44
+ def decode(encodedText: String, rails: Int): String =
45
+ RailFenceCipher(rails).decode(encodedText)
46
+ }
@@ -0,0 +1,42 @@
1
+ import org.scalatest.{FunSuite, Matchers}
2
+
3
+ class RailFenceCipherTest extends FunSuite with Matchers {
4
+
5
+ // Encode test cases
6
+ test("test to encode with two rails") {
7
+ val encoded = RailFenceCipher.encode("XOXOXOXOXOXOXOXOXO", 2)
8
+ encoded should be ("XXXXXXXXXOOOOOOOOO")
9
+ }
10
+
11
+ test("test to encode with three rails") {
12
+ pending
13
+ val encoded = RailFenceCipher.encode("WEAREDISCOVEREDFLEEATONCE", 3)
14
+ encoded should be ("WECRLTEERDSOEEFEAOCAIVDEN")
15
+ }
16
+
17
+ test("test to encode with ending in the middle") {
18
+ pending
19
+ val encoded = RailFenceCipher.encode("EXERCISES", 4)
20
+ encoded should be ("ESXIEECSR")
21
+ }
22
+
23
+ // Decode test cases
24
+ test("test to decode with three rails") {
25
+ pending
26
+ val decoded = RailFenceCipher.decode("TEITELHDVLSNHDTISEIIEA", 3)
27
+ decoded should be ("THEDEVILISINTHEDETAILS")
28
+ }
29
+
30
+ test("test to decode with five rails") {
31
+ pending
32
+ val decoded = RailFenceCipher.decode("EIEXMSMESAORIWSCE", 5)
33
+ decoded should be ("EXERCISMISAWESOME")
34
+ }
35
+
36
+ test("test to decode with six rails") {
37
+ pending
38
+ val decoded = RailFenceCipher.decode("133714114238148966225439541018335470986172518171757571896261", 6)
39
+ decoded should be ("112358132134558914423337761098715972584418167651094617711286")
40
+ }
41
+
42
+ }
@@ -0,0 +1,59 @@
1
+ import play.api.libs.json.Json
2
+
3
+ import scala.io.Source
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)
54
+
55
+ object RailFenceCipherTestGenerator {
56
+ def main(args: Array[String]): Unit = {
57
+ new RailFenceCipherTestGenerator().write
58
+ }
59
+ }
@@ -1,4 +1,11 @@
1
1
  *.swp
2
2
  .DS_Store
3
+ npm-debug.log
4
+ tmp
3
5
  bin/configlet
4
6
  bin/configlet.exe
7
+ node_modules
8
+ .idea
9
+ .build
10
+ babel-output
11
+ lintreport.json
@@ -1,5 +1,22 @@
1
- language: bash
1
+ language: node_js
2
+ node_js:
3
+ - "node"
4
+
5
+ cache: yarn
6
+
7
+ sudo: true
8
+
9
+ before_install:
10
+ - gem install bundler
11
+ - gem install danger
12
+
13
+ before_script:
14
+ - npm install -g yarn
2
15
 
3
16
  script:
4
17
  - bin/fetch-configlet
5
18
  - bin/configlet .
19
+ - make test
20
+
21
+ after_success:
22
+ - danger
@@ -0,0 +1,43 @@
1
+ # Ensure a clean commits history
2
+ if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ }
3
+ fail('Please rebase to get rid of the merge commits in this PR')
4
+ end
5
+ can_merge = github.pr_json["mergeable"]
6
+ is_merged = github.pr_json["merged"]
7
+
8
+ if is_merged
9
+ warn("This PR was merged before CI was done.", sticky: false)
10
+ else
11
+ warn("This PR cannot be merged yet.", sticky: false) unless can_merge
12
+ end
13
+
14
+ # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
15
+ warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
16
+
17
+ # Warn when there is a big PR
18
+ warn("Big PR") if git.lines_of_code > 500
19
+
20
+ #ENSURE THERE IS A SUMMARY FOR A PR
21
+ warn("Please provide a summary in the Pull Request description. See more info <a href=\"http\://tinyletter.com/exercism/letters/exercism-pull-requests\">here.</a>") if github.pr_body.length < 5
22
+
23
+ # LINT Comments in for each Line
24
+ jsonpath = "lintreport.json"
25
+ contents = File.read jsonpath
26
+ require "json"
27
+ if contents.to_s == ''
28
+ contents = "[]"
29
+ end
30
+ json = JSON.parse contents
31
+ json.each do |object|
32
+ shortFile = object["name"]
33
+ shortFile = shortFile.to_s || ''
34
+ msg = object["failure"].to_s || ''
35
+ line = object["endPosition"]["line"] || 1
36
+ #only warn for files that were edited in this PR.
37
+ if git.modified_files.include? shortFile
38
+ shortFile.prepend("/") # get away from doing inline comments since they are buggy as of Sep-2016
39
+ warn(msg, file: shortFile, line: line)
40
+ else
41
+ message(msg, file: shortFile, line: line)
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ # assignments
2
+ ASSIGNMENT ?= ""
3
+ IGNOREDIRS := "^(\.git|bin|node_modules|docs|.idea|build)$$"
4
+ ASSIGNMENTS = $(shell find ./exercises -maxdepth 1 -mindepth 1 -type d | cut -d'/' -f3 | sort | grep -Ev $(IGNOREDIRS))
5
+
6
+ #intermediate directories
7
+ TMPDIR ?= "/tmp"
8
+ INTDIR := $(shell mktemp -d "$(TMPDIR)/$(ASSIGNMENT).XXXXXXXXXX")
9
+
10
+ # language specific config (tweakable per language)
11
+ FILEEXT := "ts"
12
+ EXAMPLE := "$(ASSIGNMENT).example.$(FILEEXT)"
13
+ TSTFILE := "$(ASSIGNMENT).test.$(FILEEXT)"
14
+
15
+ all: test
16
+
17
+ test-assignment:
18
+ @printf "\e[4mRunning tests for $(ASSIGNMENT) assignment\e[0m\n"
19
+ @cp -a common/. $(INTDIR)
20
+ @sed 's/xit/it/g; s/xdescribe/describe/g' exercises/$(ASSIGNMENT)/$(TSTFILE) > $(INTDIR)/$(TSTFILE)
21
+ @cp exercises/$(ASSIGNMENT)/$(EXAMPLE) $(INTDIR)/$(ASSIGNMENT).$(FILEEXT)
22
+ @cd $(INTDIR) && yarn install && yarn lint && yarn test
23
+
24
+ test:
25
+ @npm install tslint typescript -g
26
+ @tslint './**/*.ts?(x)' -c "./common/tslint.json" --format "json" >> lintreport.json ; exit 0
27
+ @for assignment in $(ASSIGNMENTS); do ASSIGNMENT=$$assignment $(MAKE) test-assignment || exit 1; done
28
+
29
+
30
+ all: moveAllIntoCommonDir
31
+ all: moveCommonIntoSubDir
32
+
33
+ moveAssigmentToSub:
34
+ @mv ./common/$(ASSIGNMENT).$(FILEEXT) exercises/$(ASSIGNMENT)/$(EXAMPLE)
35
+ @mv ./common/$(TSTFILE) exercises/$(ASSIGNMENT)/$(TSTFILE)
36
+
37
+ moveAssigmentToCommon:
38
+ @mv ./exercises/$(ASSIGNMENT)/$(EXAMPLE) common/$(ASSIGNMENT).$(FILEEXT)
39
+ @mv ./exercises/$(ASSIGNMENT)/$(TSTFILE) common/$(TSTFILE)
40
+
41
+ moveAllIntoCommonDir:
42
+ @for assignment in $(ASSIGNMENTS); do ASSIGNMENT=$$assignment $(MAKE) moveAssigmentToCommon || exit 1; done
43
+
44
+ moveCommonIntoSubDir:
45
+ @for assignment in $(ASSIGNMENTS); do ASSIGNMENT=$$assignment $(MAKE) moveAssigmentToSub || exit 1; done
46
+
47
+ all: replacePackageFileFromCommonToSubFolders
48
+
49
+ copyPackageFilesToSubFolder:
50
+ @cp ./common/package.json exercises/$(ASSIGNMENT)/package.json
51
+ @cp ./common/tsconfig.json exercises/$(ASSIGNMENT)/tsconfig.json
52
+ @cp ./common/tslint.json exercises/$(ASSIGNMENT)/tslint.json
53
+ @cp ./common/yarn.lock exercises/$(ASSIGNMENT)/yarn.lock
54
+
55
+ replacePackageFileFromCommonToSubFolders:
56
+ @for assignment in $(ASSIGNMENTS); do ASSIGNMENT=$$assignment $(MAKE) copyPackageFilesToSubFolder || exit 1; done
57
+