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.
- checksums.yaml +4 -4
- data/common/CONTRIBUTING.md +15 -3
- data/common/README.md +7 -2
- data/common/exercises/binary/.deprecated +3 -0
- data/common/exercises/counter/.deprecated +2 -0
- data/common/exercises/hexadecimal/.deprecated +3 -0
- data/common/exercises/luhn/description.md +9 -31
- data/common/exercises/octal/.deprecated +3 -0
- data/common/exercises/point-mutations/.deprecated +2 -0
- data/common/exercises/trinary/.deprecated +3 -0
- data/lib/trackler/version.rb +1 -1
- data/tracks/c/exercises/rna-transcription/test/test_rna_transcription.c +2 -3
- data/tracks/ceylon/config.json +8 -0
- data/tracks/ceylon/docs/ABOUT.md +15 -0
- data/tracks/ceylon/docs/INSTALLATION.md +9 -0
- data/tracks/ceylon/docs/LEARNING.md +7 -0
- data/tracks/ceylon/docs/TESTS.md +11 -0
- data/tracks/ceylon/exercises/TRACK_HINTS.md +11 -0
- data/tracks/ceylon/exercises/hamming/example/Hamming.ceylon +8 -0
- data/tracks/ceylon/exercises/hamming/source/hamming/Hamming.ceylon +5 -0
- data/tracks/ceylon/exercises/hamming/source/hamming/HammingTest.ceylon +30 -0
- data/tracks/ceylon/exercises/hamming/source/hamming/module.ceylon +3 -0
- data/tracks/erlang/_test/check-exercises.escript +2 -2
- data/tracks/erlang/exercises/{circular-buffer/rebar.conf → accumulate/rebar.config} +1 -1
- data/tracks/erlang/exercises/allergies/{rebar.conf → rebar.config} +1 -1
- data/tracks/erlang/exercises/{accumulate/rebar.conf → anagram/rebar.config} +3 -1
- data/tracks/erlang/exercises/{bob/rebar.conf → atbash-cipher/rebar.config} +1 -1
- data/tracks/erlang/exercises/{binary/rebar.conf → bank-account/rebar.config} +1 -1
- data/tracks/erlang/exercises/beer-song/rebar.conf +1 -1
- data/tracks/erlang/exercises/binary/rebar.config +30 -0
- data/tracks/erlang/exercises/bob/rebar.config +30 -0
- data/tracks/erlang/exercises/circular-buffer/rebar.config +30 -0
- data/tracks/erlang/exercises/clock/rebar.config +30 -0
- data/tracks/erlang/exercises/difference-of-squares/rebar.config +30 -0
- data/tracks/erlang/exercises/etl/rebar.config +30 -0
- data/tracks/erlang/exercises/gigasecond/rebar.config +30 -0
- data/tracks/erlang/exercises/grade-school/rebar.config +30 -0
- data/tracks/erlang/exercises/grains/rebar.config +30 -0
- data/tracks/erlang/exercises/hamming/rebar.config +30 -0
- data/tracks/erlang/exercises/hello-world/rebar.config +30 -0
- data/tracks/erlang/exercises/largest-series-product/rebar.config +30 -0
- data/tracks/erlang/exercises/leap/rebar.config +30 -0
- data/tracks/erlang/exercises/luhn/rebar.config +30 -0
- data/tracks/erlang/exercises/meetup/rebar.config +30 -0
- data/tracks/erlang/exercises/nucleotide-count/rebar.config +30 -0
- data/tracks/erlang/exercises/parallel-letter-frequency/rebar.config +30 -0
- data/tracks/erlang/exercises/phone-number/rebar.config +30 -0
- data/tracks/erlang/exercises/rna-transcription/rebar.config +30 -0
- data/tracks/erlang/exercises/robot-simulator/HINTS.md +9 -0
- data/tracks/erlang/exercises/robot-simulator/rebar.config +30 -0
- data/tracks/erlang/exercises/roman-numerals/rebar.config +30 -0
- data/tracks/erlang/exercises/scrabble-score/rebar.config +30 -0
- data/tracks/erlang/exercises/series/rebar.config +30 -0
- data/tracks/erlang/exercises/space-age/rebar.config +30 -0
- data/tracks/erlang/exercises/strain/rebar.config +30 -0
- data/tracks/erlang/exercises/sum-of-multiples/rebar.config +30 -0
- data/tracks/erlang/exercises/triangle/rebar.config +30 -0
- data/tracks/erlang/exercises/trinary/rebar.config +30 -0
- data/tracks/erlang/exercises/word-count/rebar.config +30 -0
- data/tracks/erlang/exercises/zipper/rebar.config +30 -0
- data/tracks/go/README.md +2 -1
- data/tracks/go/exercises/diamond/diamond_test.go +8 -8
- data/tracks/go/exercises/difference-of-squares/difference_of_squares_test.go +8 -0
- data/tracks/go/exercises/difference-of-squares/example.go +2 -0
- data/tracks/go/exercises/diffie-hellman/diffie_hellman_test.go +8 -0
- data/tracks/go/exercises/diffie-hellman/example.go +2 -0
- data/tracks/go/exercises/error-handling/error_handling_test.go +8 -8
- data/tracks/go/exercises/etl/etl_test.go +8 -0
- data/tracks/go/exercises/etl/example.go +2 -0
- data/tracks/go/exercises/food-chain/food_chain_test.go +6 -6
- data/tracks/go/exercises/hello-world/hello_world.go +2 -2
- data/tracks/go/exercises/hexadecimal/hexadecimal_test.go +6 -6
- data/tracks/go/exercises/house/house_test.go +6 -6
- data/tracks/go/exercises/isogram/isogram_test.go +8 -8
- data/tracks/go/exercises/kindergarten-garden/kindergarten_garden_test.go +6 -6
- data/tracks/go/exercises/leap/leap_test.go +4 -1
- data/tracks/go/exercises/ledger/ledger_test.go +4 -1
- data/tracks/go/exercises/matrix/matrix_test.go +6 -6
- data/tracks/go/exercises/meetup/meetup_test.go +4 -1
- data/tracks/go/exercises/nth-prime/example.go +2 -0
- data/tracks/go/exercises/nth-prime/nth_prime_test.go +8 -0
- data/tracks/go/exercises/nucleotide-count/nucleotide_count_test.go +8 -8
- data/tracks/idris/.gitignore +2 -0
- data/tracks/idris/_src/Makefile.template +23 -0
- data/tracks/idris/config.json +9 -2
- data/tracks/idris/exercises/hello-world/HelloWorld.ipkg +5 -0
- data/tracks/idris/exercises/hello-world/Makefile +23 -0
- data/tracks/idris/exercises/hello-world/src/Test/HelloWorld.idr +25 -0
- data/tracks/idris/exercises/hello-world/src/example.idr +5 -0
- data/tracks/java/.travis.yml +5 -0
- data/tracks/java/bin/build-jq.sh +11 -0
- data/tracks/java/exercises/allergies/src/test/java/AllergiesTest.java +14 -13
- data/tracks/java/exercises/hamming/src/test/java/HammingTest.java +2 -2
- data/tracks/java/exercises/nth-prime/src/test/java/PrimeTest.java +8 -1
- data/tracks/java/exercises/nucleotide-count/src/test/java/NucleotideTest.java +12 -6
- data/tracks/java/exercises/pascals-triangle/src/test/java/PascalsTriangleTest.java +8 -2
- data/tracks/java/exercises/series/src/test/java/SeriesTest.java +10 -4
- data/tracks/java/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java +7 -2
- data/tracks/java/exercises/triangle/src/test/java/TriangleTest.java +29 -20
- data/tracks/kotlin/config.json +5 -0
- data/tracks/kotlin/exercises/build.gradle +17 -0
- data/tracks/kotlin/exercises/perfect-numbers/build.gradle +28 -0
- data/tracks/kotlin/exercises/perfect-numbers/src/example/kotlin/NaturalNumber.kt +17 -0
- data/tracks/kotlin/exercises/perfect-numbers/src/main/kotlin/NaturalNumber.kt +8 -0
- data/tracks/kotlin/exercises/perfect-numbers/src/test/kotlin/PerfectNumbersTest.kt +67 -0
- data/tracks/kotlin/exercises/settings.gradle +1 -0
- data/tracks/lua/exercises/hamming/example.lua +1 -0
- data/tracks/lua/exercises/hamming/hamming_spec.lua +19 -11
- data/tracks/ocaml/config.json +5 -0
- data/tracks/ocaml/exercises/beer-song/beer_song.mli +1 -1
- data/tracks/ocaml/exercises/beer-song/example.ml +3 -3
- data/tracks/ocaml/exercises/beer-song/test.ml +45 -22
- data/tracks/ocaml/exercises/run-length-encoding/.merlin +5 -0
- data/tracks/ocaml/exercises/run-length-encoding/Makefile +11 -0
- data/tracks/ocaml/exercises/run-length-encoding/example.ml +37 -0
- data/tracks/ocaml/exercises/run-length-encoding/run_length_encoding.mli +3 -0
- data/tracks/ocaml/exercises/run-length-encoding/test.ml +38 -0
- data/tracks/ocaml/tools/test-generator/src/template.ml +0 -2
- data/tracks/ocaml/tools/test-generator/templates/beer-song/template.ml +19 -0
- data/tracks/ocaml/tools/test-generator/templates/run-length-encoding/template.ml +19 -0
- data/tracks/php/config.json +17 -0
- data/tracks/php/exercises/queen-attack/example.php +86 -0
- data/tracks/php/exercises/queen-attack/queen-attack_test.php +125 -0
- data/tracks/php/exercises/scrabble-score/example.php +27 -0
- data/tracks/php/exercises/scrabble-score/scrabble-score_test.php +120 -0
- data/tracks/r/exercises/luhn/example.R +20 -32
- data/tracks/r/exercises/luhn/luhn.R +1 -22
- data/tracks/r/exercises/luhn/test_luhn.R +43 -55
- metadata +67 -37
- data/tracks/erlang/exercises/anagram/rebar.conf +0 -32
- data/tracks/erlang/exercises/atbash-cipher/rebar.conf +0 -30
- data/tracks/erlang/exercises/bank-account/rebar.conf +0 -30
- data/tracks/erlang/exercises/clock/rebar.conf +0 -30
- data/tracks/erlang/exercises/difference-of-squares/rebar.conf +0 -30
- data/tracks/erlang/exercises/etl/rebar.conf +0 -30
- data/tracks/erlang/exercises/gigasecond/rebar.conf +0 -30
- data/tracks/erlang/exercises/grade-school/rebar.conf +0 -30
- data/tracks/erlang/exercises/grains/rebar.conf +0 -30
- data/tracks/erlang/exercises/hamming/rebar.conf +0 -30
- data/tracks/erlang/exercises/hello-world/rebar.conf +0 -30
- data/tracks/erlang/exercises/largest-series-product/rebar.conf +0 -30
- data/tracks/erlang/exercises/leap/rebar.conf +0 -30
- data/tracks/erlang/exercises/luhn/rebar.conf +0 -30
- data/tracks/erlang/exercises/meetup/rebar.conf +0 -30
- data/tracks/erlang/exercises/nucleotide-count/rebar.conf +0 -30
- data/tracks/erlang/exercises/parallel-letter-frequency/rebar.conf +0 -30
- data/tracks/erlang/exercises/phone-number/rebar.conf +0 -30
- data/tracks/erlang/exercises/rna-transcription/rebar.conf +0 -30
- data/tracks/erlang/exercises/robot-simulator/rebar.conf +0 -30
- data/tracks/erlang/exercises/roman-numerals/rebar.conf +0 -30
- data/tracks/erlang/exercises/scrabble-score/rebar.conf +0 -30
- data/tracks/erlang/exercises/series/rebar.conf +0 -30
- data/tracks/erlang/exercises/space-age/rebar.conf +0 -30
- data/tracks/erlang/exercises/strain/rebar.conf +0 -30
- data/tracks/erlang/exercises/sum-of-multiples/rebar.conf +0 -30
- data/tracks/erlang/exercises/triangle/rebar.conf +0 -30
- data/tracks/erlang/exercises/trinary/rebar.conf +0 -30
- data/tracks/erlang/exercises/word-count/rebar.conf +0 -30
- 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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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("
|
5
|
-
input <-
|
6
|
-
expect_equal(
|
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("
|
12
|
-
input <-
|
13
|
-
expect_equal(
|
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("
|
19
|
-
input <-
|
20
|
-
expect_equal(
|
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("
|
26
|
-
input <-
|
27
|
-
expect_equal(
|
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("
|
33
|
-
input <-
|
34
|
-
expect_equal(
|
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("
|
40
|
-
input <-
|
41
|
-
expect_equal(
|
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("
|
47
|
-
input <-
|
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("
|
54
|
-
input <-
|
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("
|
61
|
-
input <-
|
62
|
-
expect_equal(
|
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("
|
68
|
-
input <-
|
69
|
-
expect_equal(
|
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("
|
75
|
-
input <-
|
76
|
-
expect_equal(
|
77
|
-
|
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!")
|