trackler 2.0.6.41 → 2.0.6.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/common/CONTRIBUTING.md +15 -3
  3. data/common/README.md +7 -2
  4. data/common/exercises/binary/.deprecated +3 -0
  5. data/common/exercises/counter/.deprecated +2 -0
  6. data/common/exercises/hexadecimal/.deprecated +3 -0
  7. data/common/exercises/luhn/description.md +9 -31
  8. data/common/exercises/octal/.deprecated +3 -0
  9. data/common/exercises/point-mutations/.deprecated +2 -0
  10. data/common/exercises/trinary/.deprecated +3 -0
  11. data/lib/trackler/version.rb +1 -1
  12. data/tracks/c/exercises/rna-transcription/test/test_rna_transcription.c +2 -3
  13. data/tracks/ceylon/config.json +8 -0
  14. data/tracks/ceylon/docs/ABOUT.md +15 -0
  15. data/tracks/ceylon/docs/INSTALLATION.md +9 -0
  16. data/tracks/ceylon/docs/LEARNING.md +7 -0
  17. data/tracks/ceylon/docs/TESTS.md +11 -0
  18. data/tracks/ceylon/exercises/TRACK_HINTS.md +11 -0
  19. data/tracks/ceylon/exercises/hamming/example/Hamming.ceylon +8 -0
  20. data/tracks/ceylon/exercises/hamming/source/hamming/Hamming.ceylon +5 -0
  21. data/tracks/ceylon/exercises/hamming/source/hamming/HammingTest.ceylon +30 -0
  22. data/tracks/ceylon/exercises/hamming/source/hamming/module.ceylon +3 -0
  23. data/tracks/erlang/_test/check-exercises.escript +2 -2
  24. data/tracks/erlang/exercises/{circular-buffer/rebar.conf → accumulate/rebar.config} +1 -1
  25. data/tracks/erlang/exercises/allergies/{rebar.conf → rebar.config} +1 -1
  26. data/tracks/erlang/exercises/{accumulate/rebar.conf → anagram/rebar.config} +3 -1
  27. data/tracks/erlang/exercises/{bob/rebar.conf → atbash-cipher/rebar.config} +1 -1
  28. data/tracks/erlang/exercises/{binary/rebar.conf → bank-account/rebar.config} +1 -1
  29. data/tracks/erlang/exercises/beer-song/rebar.conf +1 -1
  30. data/tracks/erlang/exercises/binary/rebar.config +30 -0
  31. data/tracks/erlang/exercises/bob/rebar.config +30 -0
  32. data/tracks/erlang/exercises/circular-buffer/rebar.config +30 -0
  33. data/tracks/erlang/exercises/clock/rebar.config +30 -0
  34. data/tracks/erlang/exercises/difference-of-squares/rebar.config +30 -0
  35. data/tracks/erlang/exercises/etl/rebar.config +30 -0
  36. data/tracks/erlang/exercises/gigasecond/rebar.config +30 -0
  37. data/tracks/erlang/exercises/grade-school/rebar.config +30 -0
  38. data/tracks/erlang/exercises/grains/rebar.config +30 -0
  39. data/tracks/erlang/exercises/hamming/rebar.config +30 -0
  40. data/tracks/erlang/exercises/hello-world/rebar.config +30 -0
  41. data/tracks/erlang/exercises/largest-series-product/rebar.config +30 -0
  42. data/tracks/erlang/exercises/leap/rebar.config +30 -0
  43. data/tracks/erlang/exercises/luhn/rebar.config +30 -0
  44. data/tracks/erlang/exercises/meetup/rebar.config +30 -0
  45. data/tracks/erlang/exercises/nucleotide-count/rebar.config +30 -0
  46. data/tracks/erlang/exercises/parallel-letter-frequency/rebar.config +30 -0
  47. data/tracks/erlang/exercises/phone-number/rebar.config +30 -0
  48. data/tracks/erlang/exercises/rna-transcription/rebar.config +30 -0
  49. data/tracks/erlang/exercises/robot-simulator/HINTS.md +9 -0
  50. data/tracks/erlang/exercises/robot-simulator/rebar.config +30 -0
  51. data/tracks/erlang/exercises/roman-numerals/rebar.config +30 -0
  52. data/tracks/erlang/exercises/scrabble-score/rebar.config +30 -0
  53. data/tracks/erlang/exercises/series/rebar.config +30 -0
  54. data/tracks/erlang/exercises/space-age/rebar.config +30 -0
  55. data/tracks/erlang/exercises/strain/rebar.config +30 -0
  56. data/tracks/erlang/exercises/sum-of-multiples/rebar.config +30 -0
  57. data/tracks/erlang/exercises/triangle/rebar.config +30 -0
  58. data/tracks/erlang/exercises/trinary/rebar.config +30 -0
  59. data/tracks/erlang/exercises/word-count/rebar.config +30 -0
  60. data/tracks/erlang/exercises/zipper/rebar.config +30 -0
  61. data/tracks/go/README.md +2 -1
  62. data/tracks/go/exercises/diamond/diamond_test.go +8 -8
  63. data/tracks/go/exercises/difference-of-squares/difference_of_squares_test.go +8 -0
  64. data/tracks/go/exercises/difference-of-squares/example.go +2 -0
  65. data/tracks/go/exercises/diffie-hellman/diffie_hellman_test.go +8 -0
  66. data/tracks/go/exercises/diffie-hellman/example.go +2 -0
  67. data/tracks/go/exercises/error-handling/error_handling_test.go +8 -8
  68. data/tracks/go/exercises/etl/etl_test.go +8 -0
  69. data/tracks/go/exercises/etl/example.go +2 -0
  70. data/tracks/go/exercises/food-chain/food_chain_test.go +6 -6
  71. data/tracks/go/exercises/hello-world/hello_world.go +2 -2
  72. data/tracks/go/exercises/hexadecimal/hexadecimal_test.go +6 -6
  73. data/tracks/go/exercises/house/house_test.go +6 -6
  74. data/tracks/go/exercises/isogram/isogram_test.go +8 -8
  75. data/tracks/go/exercises/kindergarten-garden/kindergarten_garden_test.go +6 -6
  76. data/tracks/go/exercises/leap/leap_test.go +4 -1
  77. data/tracks/go/exercises/ledger/ledger_test.go +4 -1
  78. data/tracks/go/exercises/matrix/matrix_test.go +6 -6
  79. data/tracks/go/exercises/meetup/meetup_test.go +4 -1
  80. data/tracks/go/exercises/nth-prime/example.go +2 -0
  81. data/tracks/go/exercises/nth-prime/nth_prime_test.go +8 -0
  82. data/tracks/go/exercises/nucleotide-count/nucleotide_count_test.go +8 -8
  83. data/tracks/idris/.gitignore +2 -0
  84. data/tracks/idris/_src/Makefile.template +23 -0
  85. data/tracks/idris/config.json +9 -2
  86. data/tracks/idris/exercises/hello-world/HelloWorld.ipkg +5 -0
  87. data/tracks/idris/exercises/hello-world/Makefile +23 -0
  88. data/tracks/idris/exercises/hello-world/src/Test/HelloWorld.idr +25 -0
  89. data/tracks/idris/exercises/hello-world/src/example.idr +5 -0
  90. data/tracks/java/.travis.yml +5 -0
  91. data/tracks/java/bin/build-jq.sh +11 -0
  92. data/tracks/java/exercises/allergies/src/test/java/AllergiesTest.java +14 -13
  93. data/tracks/java/exercises/hamming/src/test/java/HammingTest.java +2 -2
  94. data/tracks/java/exercises/nth-prime/src/test/java/PrimeTest.java +8 -1
  95. data/tracks/java/exercises/nucleotide-count/src/test/java/NucleotideTest.java +12 -6
  96. data/tracks/java/exercises/pascals-triangle/src/test/java/PascalsTriangleTest.java +8 -2
  97. data/tracks/java/exercises/series/src/test/java/SeriesTest.java +10 -4
  98. data/tracks/java/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java +7 -2
  99. data/tracks/java/exercises/triangle/src/test/java/TriangleTest.java +29 -20
  100. data/tracks/kotlin/config.json +5 -0
  101. data/tracks/kotlin/exercises/build.gradle +17 -0
  102. data/tracks/kotlin/exercises/perfect-numbers/build.gradle +28 -0
  103. data/tracks/kotlin/exercises/perfect-numbers/src/example/kotlin/NaturalNumber.kt +17 -0
  104. data/tracks/kotlin/exercises/perfect-numbers/src/main/kotlin/NaturalNumber.kt +8 -0
  105. data/tracks/kotlin/exercises/perfect-numbers/src/test/kotlin/PerfectNumbersTest.kt +67 -0
  106. data/tracks/kotlin/exercises/settings.gradle +1 -0
  107. data/tracks/lua/exercises/hamming/example.lua +1 -0
  108. data/tracks/lua/exercises/hamming/hamming_spec.lua +19 -11
  109. data/tracks/ocaml/config.json +5 -0
  110. data/tracks/ocaml/exercises/beer-song/beer_song.mli +1 -1
  111. data/tracks/ocaml/exercises/beer-song/example.ml +3 -3
  112. data/tracks/ocaml/exercises/beer-song/test.ml +45 -22
  113. data/tracks/ocaml/exercises/run-length-encoding/.merlin +5 -0
  114. data/tracks/ocaml/exercises/run-length-encoding/Makefile +11 -0
  115. data/tracks/ocaml/exercises/run-length-encoding/example.ml +37 -0
  116. data/tracks/ocaml/exercises/run-length-encoding/run_length_encoding.mli +3 -0
  117. data/tracks/ocaml/exercises/run-length-encoding/test.ml +38 -0
  118. data/tracks/ocaml/tools/test-generator/src/template.ml +0 -2
  119. data/tracks/ocaml/tools/test-generator/templates/beer-song/template.ml +19 -0
  120. data/tracks/ocaml/tools/test-generator/templates/run-length-encoding/template.ml +19 -0
  121. data/tracks/php/config.json +17 -0
  122. data/tracks/php/exercises/queen-attack/example.php +86 -0
  123. data/tracks/php/exercises/queen-attack/queen-attack_test.php +125 -0
  124. data/tracks/php/exercises/scrabble-score/example.php +27 -0
  125. data/tracks/php/exercises/scrabble-score/scrabble-score_test.php +120 -0
  126. data/tracks/r/exercises/luhn/example.R +20 -32
  127. data/tracks/r/exercises/luhn/luhn.R +1 -22
  128. data/tracks/r/exercises/luhn/test_luhn.R +43 -55
  129. metadata +67 -37
  130. data/tracks/erlang/exercises/anagram/rebar.conf +0 -32
  131. data/tracks/erlang/exercises/atbash-cipher/rebar.conf +0 -30
  132. data/tracks/erlang/exercises/bank-account/rebar.conf +0 -30
  133. data/tracks/erlang/exercises/clock/rebar.conf +0 -30
  134. data/tracks/erlang/exercises/difference-of-squares/rebar.conf +0 -30
  135. data/tracks/erlang/exercises/etl/rebar.conf +0 -30
  136. data/tracks/erlang/exercises/gigasecond/rebar.conf +0 -30
  137. data/tracks/erlang/exercises/grade-school/rebar.conf +0 -30
  138. data/tracks/erlang/exercises/grains/rebar.conf +0 -30
  139. data/tracks/erlang/exercises/hamming/rebar.conf +0 -30
  140. data/tracks/erlang/exercises/hello-world/rebar.conf +0 -30
  141. data/tracks/erlang/exercises/largest-series-product/rebar.conf +0 -30
  142. data/tracks/erlang/exercises/leap/rebar.conf +0 -30
  143. data/tracks/erlang/exercises/luhn/rebar.conf +0 -30
  144. data/tracks/erlang/exercises/meetup/rebar.conf +0 -30
  145. data/tracks/erlang/exercises/nucleotide-count/rebar.conf +0 -30
  146. data/tracks/erlang/exercises/parallel-letter-frequency/rebar.conf +0 -30
  147. data/tracks/erlang/exercises/phone-number/rebar.conf +0 -30
  148. data/tracks/erlang/exercises/rna-transcription/rebar.conf +0 -30
  149. data/tracks/erlang/exercises/robot-simulator/rebar.conf +0 -30
  150. data/tracks/erlang/exercises/roman-numerals/rebar.conf +0 -30
  151. data/tracks/erlang/exercises/scrabble-score/rebar.conf +0 -30
  152. data/tracks/erlang/exercises/series/rebar.conf +0 -30
  153. data/tracks/erlang/exercises/space-age/rebar.conf +0 -30
  154. data/tracks/erlang/exercises/strain/rebar.conf +0 -30
  155. data/tracks/erlang/exercises/sum-of-multiples/rebar.conf +0 -30
  156. data/tracks/erlang/exercises/triangle/rebar.conf +0 -30
  157. data/tracks/erlang/exercises/trinary/rebar.conf +0 -30
  158. data/tracks/erlang/exercises/word-count/rebar.conf +0 -30
  159. data/tracks/erlang/exercises/zipper/rebar.conf +0 -30
@@ -0,0 +1,120 @@
1
+
2
+
3
+ <?php
4
+
5
+ include_once 'scrabble-score.php';
6
+
7
+ /**
8
+ * Calculate the value of scrabble score for a given word.
9
+ */
10
+ class ScrabbleScoreTest extends PHPUnit\Framework\TestCase
11
+ {
12
+ /**
13
+ * Test lowercase single letter word.
14
+ */
15
+ public function testLowercaseSingleLetter()
16
+ {
17
+ $word = 'a';
18
+ $this->assertEquals(1, score($word));
19
+ }
20
+
21
+ /**
22
+ * Test uppercase single letter word.
23
+ */
24
+ public function testUppercaseSingleLetter()
25
+ {
26
+ $this->markTestSkipped();
27
+ $word = 'A';
28
+ $this->assertEquals(1, score($word));
29
+ }
30
+
31
+ /**
32
+ * Test valuable single letter word.
33
+ */
34
+ public function testValuableSingleLetter()
35
+ {
36
+ $this->markTestSkipped();
37
+ $word = 'f';
38
+ $this->assertEquals(4, score($word));
39
+ }
40
+
41
+ /**
42
+ * Test short word.
43
+ */
44
+ public function testShortWord()
45
+ {
46
+ $this->markTestSkipped();
47
+ $word = 'at';
48
+ $this->assertEquals(2, score($word));
49
+ }
50
+
51
+ /**
52
+ * Test short valuable word.
53
+ */
54
+ public function testShortValuableWord()
55
+ {
56
+ $this->markTestSkipped();
57
+ $word = 'zoo';
58
+ $this->assertEquals(12, score($word));
59
+ }
60
+
61
+ /**
62
+ * Test medium word.
63
+ */
64
+ public function testMediumWord()
65
+ {
66
+ $this->markTestSkipped();
67
+ $word = 'street';
68
+ $this->assertEquals(6, score($word));
69
+ }
70
+
71
+ /**
72
+ * Test medium valuable word.
73
+ */
74
+ public function testMediumValuableWord()
75
+ {
76
+ $this->markTestSkipped();
77
+ $word = 'quirky';
78
+ $this->assertEquals(22, score($word));
79
+ }
80
+
81
+ /**
82
+ * Test long mixed-case word.
83
+ */
84
+ public function testLongMixedCaseWord()
85
+ {
86
+ $this->markTestSkipped();
87
+ $word = 'OxyphenButazone';
88
+ $this->assertEquals(41, score($word));
89
+ }
90
+
91
+ /**
92
+ * Test english-like word.
93
+ */
94
+ public function testEnglishLikeWord()
95
+ {
96
+ $this->markTestSkipped();
97
+ $word = 'pinata';
98
+ $this->assertEquals(8, score($word));
99
+ }
100
+
101
+ /**
102
+ * Test empty word score.
103
+ */
104
+ public function testEmptyWordScore()
105
+ {
106
+ $this->markTestSkipped();
107
+ $word = '';
108
+ $this->assertEquals(0, score($word));
109
+ }
110
+
111
+ /*
112
+ * Test entire alphabet word.
113
+ */
114
+ public function testEntireAlphabetWord()
115
+ {
116
+ $this->markTestSkipped();
117
+ $word = 'abcdefghijklmnopqrstuvwxyz';
118
+ $this->assertEquals(87, score($word));
119
+ }
120
+ }
@@ -1,35 +1,23 @@
1
- # Convert a number to a valid number, if it isn't already.
2
- luhn <- function(input) {
3
- if (is_valid(input)) {
4
- return(input)
5
- }
6
- diff <- (10 - checksum(10*input)) %% 10
7
- return(10 * input + diff)
8
- }
9
-
10
- # Get the check digit
11
- check_digit <- function(input) {
12
- as.numeric(substring(input,nchar(input)))
13
- }
14
-
15
- # Compute the checksum
16
- checksum <- function(input) {
17
- sum(addends(input))
18
- }
19
-
20
1
  # Determine whether the number is valid.
21
2
  is_valid <- function(input) {
22
- checksum(input) %% 10 == 0
23
- }
24
-
25
- # addends returns the vector of numbers that follow the luhn algorithm
26
- addends <- function(input) {
27
- check <- check_digit(input)
28
- v <- as.numeric(strsplit(as.character(input),"")[[1]])
29
- # counting from right double value of every second digit
30
- start_seq <- ifelse(length(v) %% 2 == 1, 0, 1)
31
- v2 <- replace(v,seq(start_seq,length(v),2),v[seq(start_seq,length(v),2)]*2)
32
- v2 <- ifelse(v2 > 9, v2 - 9, v2)
33
- replace_vals <- v2[seq(start_seq,length(v),2)]
34
- replace(v,seq(start_seq,length(v),2),replace_vals)
3
+
4
+ # Strip spaces, check length & check for invalid characters
5
+ input_vector <- strsplit(gsub(pattern = " ", replacement = "", input), "")[[1]]
6
+ if (length(input_vector) < 2 || any(grepl("[^[:digit:]]", input_vector))) {
7
+ return (FALSE)
8
+ }
9
+
10
+ # Convert to numeric
11
+ num_vector <- as.numeric(input_vector)
12
+
13
+ # Double every second digit starting from the right
14
+ num_vector <- rev(num_vector)
15
+ num_vector[seq(2,length(num_vector),2)] = num_vector[seq(2,length(num_vector),2)]*2
16
+
17
+ # Subtract 9 if > 9 (can apply to all since no digit can be greater than 9 before doubling)
18
+ num_vector <- ifelse(num_vector > 9, num_vector - 9, num_vector)
19
+
20
+ # Check checksum is divisible by 10
21
+ sum(num_vector) %% 10 == 0
22
+
35
23
  }
@@ -1,25 +1,4 @@
1
- # Convert a number to a valid number, if it isn't already.
2
- luhn <- function() {
3
-
4
- }
5
-
6
- # Get the check digit
7
- check_digit <- function() {
8
-
9
- }
10
-
11
- # Compute the checksum
12
- checksum <- function() {
13
-
14
- }
15
-
16
1
  # Determine whether the number is valid.
17
- is_valid <- function() {
2
+ is_valid <- function(input) {
18
3
 
19
4
  }
20
-
21
-
22
- # addends returns the vector of numbers that follow the luhn algorithm
23
- addends <- function(input) {
24
-
25
- }
@@ -1,81 +1,69 @@
1
1
  source('./luhn.R')
2
2
  suppressPackageStartupMessages({ require(testthat) })
3
3
 
4
- test_that("check digit", {
5
- input <- 34567
6
- expect_equal(check_digit(input),
7
- 7
8
- )
4
+ test_that("single digit strings can not be valid", {
5
+ input <- "1"
6
+ expect_equal(is_valid(input), FALSE)
9
7
  })
10
8
 
11
- test_that("check digit with input ending in zero", {
12
- input <- 91370
13
- expect_equal(check_digit(input),
14
- 0
15
- )
9
+ test_that("A single zero is invalid", {
10
+ input <- "0"
11
+ expect_equal(is_valid(input), FALSE)
16
12
  })
17
13
 
18
- test_that("check addends", {
19
- input <- 12121
20
- expect_equal(addends(input),
21
- c(1,4,1,4,1)
22
- )
14
+ test_that("simple valid sin", {
15
+ input <- " 5 9 "
16
+ expect_equal(is_valid(input), TRUE)
23
17
  })
24
18
 
25
- test_that("check too large addends", {
26
- input <- 8631
27
- expect_equal(addends(input),
28
- c(7,6,6,1)
29
- )
19
+ test_that("valid Canadian SIN", {
20
+ input <- "046 454 286"
21
+ expect_equal(is_valid(input), TRUE)
30
22
  })
31
23
 
32
- test_that("checksum", {
33
- input <- 4913
34
- expect_equal(checksum(input),
35
- 22
36
- )
24
+ test_that("invalid Canadian SIN", {
25
+ input <- "046 454 287"
26
+ expect_equal(is_valid(input), FALSE)
37
27
  })
38
28
 
39
- test_that("checksum of larger number", {
40
- input <- 201773
41
- expect_equal(checksum(input),
42
- 21
43
- )
29
+ test_that("invalid credit card", {
30
+ input <- "8273 1232 7352 0569"
31
+ expect_equal(is_valid(input), FALSE)
44
32
  })
45
33
 
46
- test_that("check invalid number", {
47
- input <- 738
48
- expect_equal(is_valid(input),
49
- FALSE
50
- )
34
+ test_that("valid strings with a non-digit added become invalid", {
35
+ input <- "046a 454 286"
36
+ expect_equal(is_valid(input), FALSE)
51
37
  })
52
38
 
53
- test_that("check valid number", {
54
- input <- 8739567
55
- expect_equal(is_valid(input),
56
- TRUE
57
- )
39
+ test_that("punctuation is not allowed", {
40
+ input <- "055-444-285"
41
+ expect_equal(is_valid(input), FALSE)
58
42
  })
59
43
 
60
- test_that("create valid number", {
61
- input <- 123
62
- expect_equal(luhn(input),
63
- 1230
64
- )
44
+ test_that("symbols are not allowed", {
45
+ input <- "055£ 444$ 285"
46
+ expect_equal(is_valid(input), FALSE)
65
47
  })
66
48
 
67
- test_that("create larger valid number", {
68
- input <- 873956
69
- expect_equal(luhn(input),
70
- 8739567
71
- )
49
+ test_that("single zero with space is invalid", {
50
+ input <- " 0"
51
+ expect_equal(is_valid(input), FALSE)
72
52
  })
73
53
 
74
- test_that("create even larger valid number", {
75
- input <- 837263756
76
- expect_equal(luhn(input),
77
- 8372637564
78
- )
54
+ test_that("lots of zeros are valid", {
55
+ input <- " 00000"
56
+ expect_equal(is_valid(input), TRUE)
57
+ })
58
+
59
+ test_that("another valid sin", {
60
+ input <- "055 444 285"
61
+ expect_equal(is_valid(input), TRUE)
62
+ })
63
+
64
+ test_that("nine doubled is nine", {
65
+ input <- "091"
66
+ expect_equal(is_valid(input), TRUE)
79
67
  })
80
68
 
81
69
  print("All tests passed!")