trackler 2.2.1.66 → 2.2.1.67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/README.md +1 -0
  4. data/tracks/bash/exercises/anagram/anagram_tests.sh +16 -0
  5. data/tracks/bash/exercises/bob/bob_test.sh +28 -0
  6. data/tracks/bash/exercises/difference-of-squares/difference_of_squares_test.sh +3 -0
  7. data/tracks/bash/exercises/error-handling/error_handling_test.sh +5 -0
  8. data/tracks/bash/exercises/gigasecond/gigasecond_test.sh +10 -0
  9. data/tracks/bash/exercises/hamming/hamming_test.sh +15 -0
  10. data/tracks/bash/exercises/leap/leap_test.sh +10 -0
  11. data/tracks/bash/exercises/nucleotide-count/nucleotide_count_test.sh +4 -0
  12. data/tracks/bash/exercises/pangram/pangram_tests.sh +9 -0
  13. data/tracks/bash/exercises/phone-number/phone_number_tests.sh +13 -1
  14. data/tracks/bash/exercises/raindrops/raindrops_test.sh +16 -0
  15. data/tracks/bash/exercises/rna-transcription/rna_transcription_test.sh +8 -0
  16. data/tracks/bash/exercises/two-fer/two_fer_test.sh +3 -0
  17. data/tracks/bash/exercises/word-count/word_count_test.sh +9 -1
  18. data/tracks/c/exercises/hello-world/src/hello_world.c +0 -2
  19. data/tracks/c/exercises/sieve/test/test_sieve.c +13 -16
  20. data/tracks/erlang/config.json +4 -4
  21. data/tracks/fsharp/config.json +12 -0
  22. data/tracks/fsharp/exercises/Exercises.sln +6 -0
  23. data/tracks/fsharp/exercises/rotational-cipher/Example.fs +29 -0
  24. data/tracks/fsharp/exercises/rotational-cipher/Program.fs +1 -0
  25. data/tracks/fsharp/exercises/rotational-cipher/README.md +29 -0
  26. data/tracks/fsharp/exercises/rotational-cipher/RotationalCipher.fs +3 -0
  27. data/tracks/fsharp/exercises/rotational-cipher/RotationalCipher.fsproj +23 -0
  28. data/tracks/fsharp/exercises/rotational-cipher/RotationalCipherTest.fs +49 -0
  29. data/tracks/fsharp/generators/Generators.fs +3 -0
  30. data/tracks/go/exercises/grains/.meta/gen.go +99 -0
  31. data/tracks/go/exercises/grains/cases_test.go +64 -0
  32. data/tracks/go/exercises/grains/grains_test.go +4 -20
  33. data/tracks/go/exercises/space-age/space_age_test.go +3 -1
  34. data/tracks/java/config.json +12 -0
  35. data/tracks/java/exercises/beer-song/.meta/src/reference/java/BeerSong.java +4 -4
  36. data/tracks/java/exercises/diamond/src/main/java/DiamondPrinter.java +9 -0
  37. data/tracks/java/exercises/isbn-verifier/.meta/src/reference/java/IsbnVerifier.java +35 -0
  38. data/tracks/java/exercises/isbn-verifier/.meta/version +1 -0
  39. data/tracks/java/exercises/isbn-verifier/README.md +53 -0
  40. data/tracks/java/exercises/isbn-verifier/build.gradle +18 -0
  41. data/tracks/java/exercises/isbn-verifier/src/main/java/IsbnVerifier.java +7 -0
  42. data/tracks/java/exercises/isbn-verifier/src/test/java/IsbnVerifierTest.java +94 -0
  43. data/tracks/java/exercises/isogram/src/main/java/IsogramChecker.java +7 -0
  44. data/tracks/java/exercises/saddle-points/src/main/java/Matrix.java +13 -0
  45. data/tracks/java/exercises/settings.gradle +1 -0
  46. data/tracks/kotlin/config.json +1 -1
  47. data/tracks/ocaml/exercises/all-your-base/example.ml +1 -1
  48. data/tracks/ocaml/exercises/all-your-base/test.ml +9 -9
  49. data/tracks/perl6/config.json +1 -1
  50. data/tracks/perl6/docs/SNIPPET.txt +2 -2
  51. data/tracks/perl6/exercises/anagram/Anagram.pm6 +4 -1
  52. data/tracks/perl6/exercises/anagram/Example.pm6 +4 -15
  53. data/tracks/perl6/exercises/anagram/anagram.t +2 -2
  54. data/tracks/perl6/exercises/anagram/example.yaml +7 -15
  55. data/tracks/php/config.json +12 -0
  56. data/tracks/php/exercises/run-length-encoding/README.md +42 -0
  57. data/tracks/php/exercises/run-length-encoding/example.php +60 -0
  58. data/tracks/php/exercises/run-length-encoding/run-length-encoding.php +20 -0
  59. data/tracks/php/exercises/run-length-encoding/run-length-encoding_test.php +65 -0
  60. data/tracks/purescript/.travis.yml +1 -1
  61. data/tracks/purescript/bin/test.sh +9 -2
  62. data/tracks/python/config.json +7 -16
  63. data/tracks/r/exercises/hello-world/test_hello-world.R +0 -8
  64. data/tracks/racket/config.json +1 -1
  65. data/tracks/swift/config.json +12 -2
  66. data/tracks/swift/exercises/diamond/Package.swift +5 -0
  67. data/tracks/swift/exercises/diamond/README.md +64 -0
  68. data/tracks/swift/exercises/diamond/Sources/Diamond.swift +1 -0
  69. data/tracks/swift/exercises/diamond/Sources/DiamondExample.swift +30 -0
  70. data/tracks/swift/exercises/diamond/Tests/DiamondTests/DiamondTests.swift +98 -0
  71. data/tracks/swift/exercises/diamond/Tests/LinuxMain.swift +6 -0
  72. metadata +29 -8
  73. data/tracks/java/exercises/diamond/src/main/java/.keep +0 -0
  74. data/tracks/java/exercises/isogram/src/main/java/.keep +0 -0
  75. data/tracks/python/exercises/parallel-letter-frequency/README.md +0 -24
  76. data/tracks/python/exercises/parallel-letter-frequency/example.py +0 -56
  77. data/tracks/python/exercises/parallel-letter-frequency/parallel_letter_frequency.py +0 -2
  78. data/tracks/python/exercises/parallel-letter-frequency/parallel_letter_frequency_test.py +0 -61
@@ -681,6 +681,9 @@ type RobotSimulator() =
681
681
  // because useFullMethodName leads to very long names
682
682
  sprintf "%s - %s" canonicalDataCase.Property (canonicalDataCase.Description |> String.upperCaseFirst)
683
683
 
684
+ type RotationalCipher() =
685
+ inherit Exercise()
686
+
684
687
  type RnaTranscription() =
685
688
  inherit Exercise()
686
689
 
@@ -0,0 +1,99 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "log"
6
+ "strings"
7
+ "text/template"
8
+
9
+ "../../../gen"
10
+ )
11
+
12
+ func main() {
13
+ t, err := template.New("").Parse(tmpl)
14
+ if err != nil {
15
+ log.Fatal(err)
16
+ }
17
+ var j js
18
+ if err := gen.Gen("grains", &j, t); err != nil {
19
+ log.Fatal(err)
20
+ }
21
+ }
22
+
23
+ // The JSON structure we expect to be able to unmarshal into
24
+ type js struct {
25
+ Groups []testGroup `json:"Cases"`
26
+ }
27
+
28
+ type testGroup struct {
29
+ Description string
30
+ Cases []json.RawMessage `property:"RAW"`
31
+ SquareCases []SquareCase `property:"square"`
32
+ // Note: canonical-data.json has a element of "cases"
33
+ // which includes a test for property 'total', but it is ignored here,
34
+ // since "expected" is a single known value.
35
+ }
36
+
37
+ type SquareCase struct {
38
+ Description string
39
+ Input int
40
+ Expected interface{}
41
+ }
42
+
43
+ func (c SquareCase) HasAnswer() bool {
44
+ hasAnswer, _ := determineExpected(c.Expected)
45
+ return hasAnswer
46
+ }
47
+
48
+ func (c SquareCase) Answer() uint64 {
49
+ _, answer := determineExpected(c.Expected)
50
+ return answer
51
+ }
52
+
53
+ func (c SquareCase) EditedDescription() string {
54
+ // Go doesn't raise exceptions, so replace the wording in .Description.
55
+ return strings.Replace(c.Description, "raises an exception", "returns an error", 1)
56
+ }
57
+
58
+ // determineExpected examines an .Expected interface{} object and determines
59
+ // whether a test case has an answer or expects an error.
60
+ // The return values are true and answer or false and zero.
61
+ func determineExpected(expected interface{}) (bool, uint64) {
62
+ ans, ok := expected.(float64)
63
+ if ok {
64
+ if ans == float64(-1) {
65
+ return false, 0
66
+ }
67
+ return true, uint64(ans)
68
+ }
69
+ return false, 0
70
+ }
71
+
72
+ var tmpl = `package grains
73
+
74
+ {{.Header}}
75
+
76
+ {{range .J.Groups}}
77
+ {{- if .SquareCases }}
78
+ // {{ .Description }}
79
+ var squareTests = []struct {
80
+ description string
81
+ input int
82
+ expectedVal uint64
83
+ expectError bool
84
+ }{
85
+ {{- range .SquareCases}}
86
+ {
87
+ description: "{{.EditedDescription}}",
88
+ input: {{.Input}},
89
+ {{- if .HasAnswer}}
90
+ expectedVal: {{.Answer}},
91
+ {{- else}}
92
+ expectError: true,
93
+ {{- end}}
94
+ },
95
+ {{- end }}
96
+ }
97
+ {{- end }}
98
+ {{end}}
99
+ `
@@ -0,0 +1,64 @@
1
+ package grains
2
+
3
+ // Source: exercism/problem-specifications
4
+ // Commit: d4554e6 grains: fix a typo in comments of canonical data
5
+ // Problem Specifications Version: 1.0.0
6
+
7
+ // returns the number of grains on the square
8
+ var squareTests = []struct {
9
+ description string
10
+ input int
11
+ expectedVal uint64
12
+ expectError bool
13
+ }{
14
+ {
15
+ description: "1",
16
+ input: 1,
17
+ expectedVal: 1,
18
+ },
19
+ {
20
+ description: "2",
21
+ input: 2,
22
+ expectedVal: 2,
23
+ },
24
+ {
25
+ description: "3",
26
+ input: 3,
27
+ expectedVal: 4,
28
+ },
29
+ {
30
+ description: "4",
31
+ input: 4,
32
+ expectedVal: 8,
33
+ },
34
+ {
35
+ description: "16",
36
+ input: 16,
37
+ expectedVal: 32768,
38
+ },
39
+ {
40
+ description: "32",
41
+ input: 32,
42
+ expectedVal: 2147483648,
43
+ },
44
+ {
45
+ description: "64",
46
+ input: 64,
47
+ expectedVal: 9223372036854775808,
48
+ },
49
+ {
50
+ description: "square 0 returns an error",
51
+ input: 0,
52
+ expectError: true,
53
+ },
54
+ {
55
+ description: "negative square returns an error",
56
+ input: -1,
57
+ expectError: true,
58
+ },
59
+ {
60
+ description: "square greater than 64 returns an error",
61
+ input: 65,
62
+ expectError: true,
63
+ },
64
+ }
@@ -4,41 +4,25 @@ import (
4
4
  "testing"
5
5
  )
6
6
 
7
- var squareTests = []struct {
8
- input int
9
- expectedVal uint64
10
- expectError bool
11
- }{
12
- {1, 1, false},
13
- {2, 2, false},
14
- {3, 4, false},
15
- {4, 8, false},
16
- {16, 32768, false},
17
- {32, 2147483648, false},
18
- {64, 9223372036854775808, false},
19
- {65, 0, true},
20
- {0, 0, true},
21
- {-1, 0, true},
22
- }
23
-
24
7
  func TestSquare(t *testing.T) {
25
8
  for _, test := range squareTests {
26
9
  actualVal, actualErr := Square(test.input)
27
10
 
28
11
  // check actualVal only if no error expected
29
12
  if !test.expectError && actualVal != test.expectedVal {
30
- t.Errorf("Square(%d) expected %d, Actual %d", test.input, test.expectedVal, actualVal)
13
+ t.Fatalf("FAIL: %s\nSquare(%d) expected %d, Actual %d", test.description, test.input, test.expectedVal, actualVal)
31
14
  }
32
15
 
33
16
  // if we expect an error and there isn't one
34
17
  if test.expectError && actualErr == nil {
35
- t.Errorf("Square(%d) expected an error, but error is nil", test.input)
18
+ t.Fatalf("FAIL: %s\nSquare(%d) expected an error, but error is nil", test.description, test.input)
36
19
  }
37
20
  // if we don't expect an error and there is one
38
21
  if !test.expectError && actualErr != nil {
39
22
  var _ error = actualErr
40
- t.Errorf("Square(%d) expected no error, but error is: %s", test.input, actualErr)
23
+ t.Fatalf("FAIL: %s\nSquare(%d) expected no error, but error is: %s", test.description, test.input, actualErr)
41
24
  }
25
+ t.Logf("PASS: %s", test.description)
42
26
  }
43
27
  }
44
28
 
@@ -1,12 +1,14 @@
1
1
  package space
2
2
 
3
3
  import (
4
+ "math"
4
5
  "testing"
5
6
  )
6
7
 
7
8
  func TestAge(t *testing.T) {
9
+ const precision = 0.01
8
10
  for _, tc := range testCases {
9
- if actual := Age(tc.seconds, tc.planet); actual != tc.expected {
11
+ if actual := Age(tc.seconds, tc.planet); math.Abs(actual-tc.expected) > precision {
10
12
  t.Fatalf("FAIL: %s\nExpected: %#v\nActual: %#v", tc.description, tc.expected, actual)
11
13
  }
12
14
  t.Logf("PASS: %s", tc.description)
@@ -179,6 +179,18 @@
179
179
  "unlocked_by": "rna-transcription",
180
180
  "uuid": "331073b3-bd1a-4868-b767-a64ce9fd9d97"
181
181
  },
182
+ {
183
+ "core": false,
184
+ "difficulty": 4,
185
+ "slug": "isbn-verifier",
186
+ "topics": [
187
+ "integers",
188
+ "loops",
189
+ "strings"
190
+ ],
191
+ "unlocked_by": "hamming",
192
+ "uuid": "838bc1d7-b2de-482a-9bfc-c881b4ccb04c"
193
+ },
182
194
  {
183
195
  "core": false,
184
196
  "difficulty": 4,
@@ -1,5 +1,5 @@
1
- public class BeerSong {
2
- public String verse(int number) {
1
+ class BeerSong {
2
+ String verse(int number) {
3
3
  switch (number) {
4
4
  case 0:
5
5
  return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n\n";
@@ -12,7 +12,7 @@ public class BeerSong {
12
12
  }
13
13
  }
14
14
 
15
- public String sing(int start, int stop) {
15
+ String sing(int start, int stop) {
16
16
  StringBuilder songOutput = new StringBuilder();
17
17
 
18
18
  for (int i=start; i>=stop; i--) {
@@ -22,7 +22,7 @@ public class BeerSong {
22
22
  return songOutput.toString();
23
23
  }
24
24
 
25
- public String singSong() {
25
+ String singSong() {
26
26
  return sing(99,0);
27
27
  }
28
28
  }
@@ -0,0 +1,9 @@
1
+ import java.util.List;
2
+
3
+ class DiamondPrinter {
4
+
5
+ List<String> printToList(char a) {
6
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
7
+ }
8
+
9
+ }
@@ -0,0 +1,35 @@
1
+ class IsbnVerifier {
2
+
3
+ boolean isValid(String stringToVerify) {
4
+
5
+ String isbn = stringToVerify.replace("-", "");
6
+ int total = 0;
7
+
8
+ if (isbn.length() != 10) {
9
+ return false;
10
+ }
11
+
12
+ for (int i = 0; i < isbn.length() - 1; i++) {
13
+ char currentChar = isbn.charAt(i);
14
+ if(Character.isDigit(currentChar)) {
15
+ int currentCharVal = Character.getNumericValue(currentChar);
16
+ total += currentCharVal * (10 - i);
17
+ } else {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ char finalChar = isbn.charAt(isbn.length() - 1);
23
+ if (Character.isDigit(finalChar)) {
24
+ total += Character.getNumericValue(finalChar);
25
+ } else if (finalChar == 'X') {
26
+ total += 10;
27
+ } else {
28
+ return false;
29
+ }
30
+
31
+ return total % 11 == 0;
32
+
33
+ }
34
+
35
+ }
@@ -0,0 +1,53 @@
1
+ Check if a given ISBN-10 is valid.
2
+
3
+ ## Functionality
4
+
5
+ Given an unknown string the program should check if the provided string is a valid ISBN-10.
6
+ Putting this into place requires some thinking about preprocessing/parsing of the string prior to calculating the check digit for the ISBN.
7
+
8
+ The program should allow for ISBN-10 without the separating dashes to be verified as well.
9
+
10
+ ## ISBN
11
+
12
+ Let's take a random ISBN-10 number, say `3-598-21508-8` for this.
13
+ The first digit block indicates the group where the ISBN belongs. Groups can consist of shared languages, geographic regions or countries. The leading '3' signals this ISBN is from a german speaking country.
14
+ The following number block is to identify the publisher. Since this is a three digit publisher number there is a 5 digit title number for this book.
15
+ The last digit in the ISBN is the check digit which is used to detect read errors.
16
+
17
+ The first 9 digits in the ISBN have to be between 0 and 9.
18
+ The check digit can additionally be an 'X' to allow 10 to be a valid check digit as well.
19
+
20
+ A valid ISBN-10 is calculated with this formula `(x1 * 10 + x2 * 9 + x3 * 8 + x4 * 7 + x5 * 6 + x6 * 5 + x7 * 4 + x8 * 3 + x9 * 2 + x10 * 1) mod 11 == 0`
21
+ So for our example ISBN this means:
22
+ (3 * 10 + 5 * 9 + 9 * 8 + 8 * 7 + 2 * 6 + 1 * 5 + 5 * 4 + 0 * 3 + 8 * 2 + 8 * 1) mod 11 = 0
23
+
24
+ Which proves that the ISBN is valid.
25
+
26
+ ## Caveats
27
+
28
+ Converting from string to number can be tricky in certain languages.
29
+ It's getting even trickier since the check-digit of an ISBN-10 can be 'X'.
30
+
31
+ ## Bonus tasks
32
+
33
+ * Generate a valid ISBN-13 from the input ISBN-10 (and maybe verify it again with a derived verifier)
34
+
35
+ * Generate valid ISBN, maybe even from a given starting ISBN
36
+
37
+ # Running the tests
38
+
39
+ You can run all the tests for an exercise by entering
40
+
41
+ ```sh
42
+ $ gradle test
43
+ ```
44
+
45
+ in your terminal.
46
+
47
+ ## Source
48
+
49
+ Converting a string into a number and some basic processing utilizing a relatable real world example. [https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation](https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation)
50
+
51
+ ## Submitting Incomplete Solutions
52
+
53
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,18 @@
1
+ apply plugin: "java"
2
+ apply plugin: "eclipse"
3
+ apply plugin: "idea"
4
+
5
+ repositories {
6
+ mavenCentral()
7
+ }
8
+
9
+ dependencies {
10
+ testCompile "junit:junit:4.12"
11
+ }
12
+
13
+ test {
14
+ testLogging {
15
+ exceptionFormat = 'full'
16
+ events = ["passed", "failed", "skipped"]
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ class IsbnVerifier {
2
+
3
+ boolean isValid(String stringToVerify) {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ }
@@ -0,0 +1,94 @@
1
+ import org.junit.Assert;
2
+ import org.junit.Before;
3
+ import org.junit.Ignore;
4
+ import org.junit.Test;
5
+
6
+ import static org.junit.Assert.assertTrue;
7
+ import static org.junit.Assert.assertFalse;
8
+
9
+ public class IsbnVerifierTest {
10
+ private IsbnVerifier isbnVerifier;
11
+
12
+ @Before
13
+ public void setUp() {
14
+ isbnVerifier = new IsbnVerifier();
15
+ }
16
+
17
+ @Test
18
+ public void validIsbnNumber() {
19
+ assertTrue(isbnVerifier.isValid("3-598-21508-8"));
20
+ }
21
+
22
+ @Ignore("Remove to run test")
23
+ @Test
24
+ public void invalidIsbnCheckDigit() {
25
+ assertFalse(isbnVerifier.isValid("3-598-21508-9"));
26
+ }
27
+
28
+ @Ignore("Remove to run test")
29
+ @Test
30
+ public void validIsbnNumberWithCheckDigitOfTen() {
31
+ assertTrue(isbnVerifier.isValid("3-598-21507-X"));
32
+ }
33
+
34
+ @Ignore("Remove to run test")
35
+ @Test
36
+ public void checkDigitIsACharacterOtherThanX() {
37
+ assertFalse(isbnVerifier.isValid("3-598-21507-A"));
38
+ }
39
+
40
+ @Ignore("Remove to run test")
41
+ @Test
42
+ public void invalidCharacterInIsbn() {
43
+ assertFalse(isbnVerifier.isValid("3-598-2K507-0"));
44
+ }
45
+
46
+ @Ignore("Remove to run test")
47
+ @Test
48
+ public void xIsOnlyValidAsACheckDigit() {
49
+ assertFalse(isbnVerifier.isValid("3-598-2X507-9"));
50
+ }
51
+
52
+ @Ignore("Remove to run test")
53
+ @Test
54
+ public void validIsbnWithoutSeparatingDashes() {
55
+ assertTrue(isbnVerifier.isValid("3598215088"));
56
+ }
57
+
58
+ @Ignore("Remove to run test")
59
+ @Test
60
+ public void isbnWithoutSeparatingDashesAndXAsCheckDigit() {
61
+ assertTrue(isbnVerifier.isValid("359821507X"));
62
+ }
63
+
64
+ @Ignore("Remove to run test")
65
+ @Test
66
+ public void isbnWithoutCheckDigitAndDashes() {
67
+ assertFalse(isbnVerifier.isValid("359821507"));
68
+ }
69
+
70
+ @Ignore("Remove to run test")
71
+ @Test
72
+ public void tooLongIsbnAndNoDashes() {
73
+ assertFalse(isbnVerifier.isValid("3598215078X"));
74
+ }
75
+
76
+ @Ignore("Remove to run test")
77
+ @Test
78
+ public void isbnWithoutCheckDigit() {
79
+ assertFalse(isbnVerifier.isValid("3-598-21507"));
80
+ }
81
+
82
+ @Ignore("Remove to run test")
83
+ @Test
84
+ public void tooLongIsbn() {
85
+ assertFalse(isbnVerifier.isValid("3-598-21507-XX"));
86
+ }
87
+
88
+ @Ignore("Remove to run test")
89
+ @Test
90
+ public void checkDigitOfXShouldNotBeUsedForZero() {
91
+ assertFalse(isbnVerifier.isValid("3-598-21515-X"));
92
+ }
93
+
94
+ }