trackler 2.2.1.6 → 2.2.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/c/README.md +27 -0
- data/tracks/coffeescript/config.json +1 -0
- data/tracks/coldfusion/config.json +1 -1
- data/tracks/crystal/README.md +27 -7
- data/tracks/crystal/config/maintainers.json +25 -0
- data/tracks/crystal/generator/spec/remote_data_file_spec.cr +1 -1
- data/tracks/crystal/generator/src/exercise_generator.cr +1 -1
- data/tracks/crystal/generator/src/remote_data_file.cr +2 -2
- data/tracks/csharp/config.json +1 -2
- data/tracks/csharp/config/maintainers.json +55 -0
- data/tracks/csharp/docs/EXERCISE_README_INSERT.md +1 -1
- data/tracks/csharp/exercises/accumulate/README.md +1 -1
- data/tracks/csharp/exercises/acronym/README.md +1 -1
- data/tracks/csharp/exercises/all-your-base/README.md +1 -1
- data/tracks/csharp/exercises/allergies/README.md +1 -1
- data/tracks/csharp/exercises/alphametics/README.md +1 -1
- data/tracks/csharp/exercises/anagram/README.md +1 -1
- data/tracks/csharp/exercises/atbash-cipher/README.md +1 -1
- data/tracks/csharp/exercises/bank-account/README.md +1 -1
- data/tracks/csharp/exercises/beer-song/README.md +1 -1
- data/tracks/csharp/exercises/binary-search-tree/README.md +1 -1
- data/tracks/csharp/exercises/binary-search/README.md +1 -1
- data/tracks/csharp/exercises/bob/README.md +1 -1
- data/tracks/csharp/exercises/book-store/README.md +1 -1
- data/tracks/csharp/exercises/bowling/README.md +1 -1
- data/tracks/csharp/exercises/bracket-push/README.md +1 -1
- data/tracks/csharp/exercises/change/README.md +1 -1
- data/tracks/csharp/exercises/circular-buffer/README.md +1 -1
- data/tracks/csharp/exercises/clock/README.md +1 -1
- data/tracks/csharp/exercises/connect/README.md +1 -1
- data/tracks/csharp/exercises/crypto-square/README.md +1 -1
- data/tracks/csharp/exercises/custom-set/README.md +1 -1
- data/tracks/csharp/exercises/diamond/README.md +1 -1
- data/tracks/csharp/exercises/difference-of-squares/README.md +1 -1
- data/tracks/csharp/exercises/diffie-hellman/README.md +1 -1
- data/tracks/csharp/exercises/dominoes/README.md +1 -1
- data/tracks/csharp/exercises/dot-dsl/README.md +1 -1
- data/tracks/csharp/exercises/error-handling/README.md +1 -1
- data/tracks/csharp/exercises/etl/README.md +1 -1
- data/tracks/csharp/exercises/flatten-array/README.md +1 -1
- data/tracks/csharp/exercises/food-chain/README.md +1 -1
- data/tracks/csharp/exercises/forth/README.md +1 -1
- data/tracks/csharp/exercises/gigasecond/README.md +1 -1
- data/tracks/csharp/exercises/go-counting/README.md +1 -1
- data/tracks/csharp/exercises/grade-school/README.md +1 -1
- data/tracks/csharp/exercises/grains/README.md +1 -1
- data/tracks/csharp/exercises/grep/README.md +1 -1
- data/tracks/csharp/exercises/hamming/README.md +1 -1
- data/tracks/csharp/exercises/hangman/README.md +1 -1
- data/tracks/csharp/exercises/hello-world/README.md +1 -1
- data/tracks/csharp/exercises/house/README.md +1 -1
- data/tracks/csharp/exercises/isogram/README.md +1 -1
- data/tracks/csharp/exercises/kindergarten-garden/README.md +1 -1
- data/tracks/csharp/exercises/largest-series-product/README.md +1 -1
- data/tracks/csharp/exercises/leap/README.md +1 -1
- data/tracks/csharp/exercises/ledger/README.md +1 -1
- data/tracks/csharp/exercises/linked-list/README.md +1 -1
- data/tracks/csharp/exercises/list-ops/README.md +1 -1
- data/tracks/csharp/exercises/luhn/README.md +1 -1
- data/tracks/csharp/exercises/markdown/README.md +1 -1
- data/tracks/csharp/exercises/matrix/README.md +1 -1
- data/tracks/csharp/exercises/meetup/README.md +1 -1
- data/tracks/csharp/exercises/minesweeper/README.md +1 -1
- data/tracks/csharp/exercises/nth-prime/README.md +1 -1
- data/tracks/csharp/exercises/nucleotide-count/README.md +1 -1
- data/tracks/csharp/exercises/ocr-numbers/README.md +1 -1
- data/tracks/csharp/exercises/palindrome-products/README.md +1 -1
- data/tracks/csharp/exercises/pangram/README.md +1 -1
- data/tracks/csharp/exercises/parallel-letter-frequency/README.md +1 -1
- data/tracks/csharp/exercises/pascals-triangle/README.md +1 -1
- data/tracks/csharp/exercises/perfect-numbers/README.md +1 -1
- data/tracks/csharp/exercises/phone-number/README.md +1 -1
- data/tracks/csharp/exercises/pig-latin/README.md +1 -1
- data/tracks/csharp/exercises/poker/README.md +1 -1
- data/tracks/csharp/exercises/pov/README.md +1 -1
- data/tracks/csharp/exercises/prime-factors/README.md +1 -1
- data/tracks/csharp/exercises/protein-translation/README.md +1 -1
- data/tracks/csharp/exercises/proverb/README.md +1 -1
- data/tracks/csharp/exercises/pythagorean-triplet/README.md +1 -1
- data/tracks/csharp/exercises/queen-attack/README.md +1 -1
- data/tracks/csharp/exercises/rail-fence-cipher/README.md +1 -1
- data/tracks/csharp/exercises/raindrops/README.md +1 -1
- data/tracks/csharp/exercises/react/README.md +1 -1
- data/tracks/csharp/exercises/rectangles/README.md +1 -1
- data/tracks/csharp/exercises/rna-transcription/README.md +1 -1
- data/tracks/csharp/exercises/robot-name/README.md +1 -1
- data/tracks/csharp/exercises/robot-simulator/README.md +1 -1
- data/tracks/csharp/exercises/roman-numerals/README.md +1 -1
- data/tracks/csharp/exercises/rotational-cipher/README.md +1 -1
- data/tracks/csharp/exercises/run-length-encoding/README.md +1 -1
- data/tracks/csharp/exercises/saddle-points/README.md +1 -1
- data/tracks/csharp/exercises/say/README.md +1 -1
- data/tracks/csharp/exercises/scale-generator/README.md +1 -1
- data/tracks/csharp/exercises/scrabble-score/README.md +1 -1
- data/tracks/csharp/exercises/secret-handshake/README.md +1 -1
- data/tracks/csharp/exercises/series/README.md +1 -1
- data/tracks/csharp/exercises/sgf-parsing/README.md +1 -1
- data/tracks/csharp/exercises/sieve/README.md +1 -1
- data/tracks/csharp/exercises/simple-cipher/README.md +1 -1
- data/tracks/csharp/exercises/simple-linked-list/README.md +1 -1
- data/tracks/csharp/exercises/space-age/README.md +1 -1
- data/tracks/csharp/exercises/strain/README.md +1 -1
- data/tracks/csharp/exercises/sublist/README.md +1 -1
- data/tracks/csharp/exercises/sum-of-multiples/README.md +1 -1
- data/tracks/csharp/exercises/tournament/README.md +1 -1
- data/tracks/csharp/exercises/transpose/README.md +1 -1
- data/tracks/csharp/exercises/tree-building/README.md +1 -1
- data/tracks/csharp/exercises/triangle/README.md +1 -1
- data/tracks/csharp/exercises/twelve-days/README.md +1 -1
- data/tracks/csharp/exercises/two-bucket/README.md +1 -1
- data/tracks/csharp/exercises/variable-length-quantity/README.md +1 -1
- data/tracks/csharp/exercises/word-count/README.md +1 -1
- data/tracks/csharp/exercises/word-search/README.md +1 -1
- data/tracks/csharp/exercises/wordy/README.md +1 -1
- data/tracks/csharp/exercises/zebra-puzzle/README.md +1 -1
- data/tracks/csharp/exercises/zipper/README.md +1 -1
- data/tracks/d/config.json +1 -0
- data/tracks/dart/config/maintainers.json +15 -0
- data/tracks/ecmascript/config.json +76 -193
- data/tracks/ecmascript/exercises/twelve-days/README.md +66 -0
- data/tracks/ecmascript/exercises/twelve-days/example.js +53 -0
- data/tracks/ecmascript/exercises/twelve-days/package.json +68 -0
- data/tracks/ecmascript/exercises/twelve-days/twelve-days.spec.js +106 -0
- data/tracks/factor/config.json +1 -1
- data/tracks/fsharp/config/maintainers.json +35 -0
- data/tracks/go/config.json +82 -38
- data/tracks/go/config/maintainers.json +13 -22
- data/tracks/go/exercises/bowling/cases_test.go +11 -11
- data/tracks/go/exercises/forth/cases_test.go +7 -7
- data/tracks/go/exercises/forth/example.go +1 -1
- data/tracks/go/exercises/forth/forth_test.go +1 -1
- data/tracks/go/exercises/hamming/cases_test.go +7 -7
- data/tracks/go/exercises/hamming/hamming.go +1 -1
- data/tracks/go/exercises/phone-number/cases_test.go +2 -7
- data/tracks/go/exercises/phone-number/example.go +1 -1
- data/tracks/go/exercises/phone-number/phone_number_test.go +1 -1
- data/tracks/go/exercises/rna-transcription/cases_test.go +7 -7
- data/tracks/go/exercises/secret-handshake/cases_test.go +1 -1
- data/tracks/groovy/config.json +1 -0
- data/tracks/haxe/config.json +1 -1
- data/tracks/java/.travis.yml +1 -1
- data/tracks/java/config/maintainers.json +20 -0
- data/tracks/java/exercises/custom-set/src/test/java/CustomSetTest.java +1 -1
- data/tracks/java/exercises/word-count/src/test/java/WordCountTest.java +1 -1
- data/tracks/javascript/config.json +229 -247
- data/tracks/kotlin/config/maintainers.json +35 -0
- data/tracks/lfe/config/maintainers.json +15 -0
- data/tracks/lisp/config/maintainers.json +55 -0
- data/tracks/ocaml/config.json +0 -5
- data/tracks/ocaml/config/maintainers.json +25 -0
- data/tracks/perl5/config/maintainers.json +25 -0
- data/tracks/perl6/config/maintainers.json +25 -0
- data/tracks/pony/config/maintainers.json +15 -0
- data/tracks/pony/exercises/atbash-cipher/example.pony +2 -2
- data/tracks/pony/exercises/beer-song/example.pony +1 -1
- data/tracks/pony/exercises/bob/example.pony +1 -1
- data/tracks/pony/exercises/difference-of-squares/example.pony +1 -1
- data/tracks/pony/exercises/hamming/test.pony +12 -12
- data/tracks/pony/exercises/pascals-triangle/example.pony +1 -1
- data/tracks/pony/exercises/pascals-triangle/test.pony +6 -6
- data/tracks/pony/exercises/rna-transcription/test.pony +3 -3
- data/tracks/pony/exercises/roman-numerals/test.pony +3 -3
- data/tracks/purescript/config/maintainers.json +35 -0
- data/tracks/r/config.json +140 -81
- data/tracks/r/exercises/collatz-conjecture/README.md +43 -0
- data/tracks/r/exercises/collatz-conjecture/collatz-conjecture.R +3 -0
- data/tracks/r/exercises/collatz-conjecture/example.R +13 -0
- data/tracks/r/exercises/collatz-conjecture/test_collatz-conjecture.R +28 -0
- data/tracks/r/exercises/nucleotide-count/README.md +43 -0
- data/tracks/r/exercises/nucleotide-count/example.R +17 -0
- data/tracks/r/exercises/nucleotide-count/nucleotide-count.R +3 -0
- data/tracks/r/exercises/nucleotide-count/test_nucleotide-count.R +51 -0
- data/tracks/r/exercises/pangram/README.md +25 -0
- data/tracks/r/exercises/pangram/example.R +14 -0
- data/tracks/r/exercises/pangram/pangram.R +3 -0
- data/tracks/r/exercises/pangram/test_pangram.R +42 -0
- data/tracks/r/exercises/triangle/.meta/hints.md +4 -0
- data/tracks/r/exercises/triangle/README.md +41 -0
- data/tracks/r/exercises/triangle/example.R +23 -0
- data/tracks/r/exercises/triangle/test_triangle.R +72 -0
- data/tracks/r/exercises/triangle/triangle.R +3 -0
- data/tracks/rust/config.json +32 -1
- data/tracks/rust/config/maintainers.json +1 -6
- data/tracks/rust/exercises/acronym/tests/acronym.rs +1 -1
- data/tracks/rust/exercises/beer-song/example.rs +1 -1
- data/tracks/rust/exercises/circular-buffer/example.rs +8 -10
- data/tracks/rust/exercises/circular-buffer/tests/circular-buffer.rs +2 -2
- data/tracks/rust/exercises/clock/.meta/hints.md +10 -0
- data/tracks/rust/exercises/clock/Cargo.lock +4 -0
- data/tracks/rust/exercises/clock/Cargo.toml +6 -0
- data/tracks/rust/exercises/clock/README.md +57 -0
- data/tracks/rust/exercises/clock/example.rs +32 -0
- data/tracks/{ocaml/exercises/point-mutations/example.ml → rust/exercises/clock/src/lib.rs} +0 -0
- data/tracks/rust/exercises/clock/tests/clock.rs +331 -0
- data/tracks/rust/exercises/custom-set/tests/custom-set.rs +3 -3
- data/tracks/rust/exercises/dominoes/example.rs +1 -1
- data/tracks/rust/exercises/grade-school/example.rs +1 -1
- data/tracks/rust/exercises/hamming/example.rs +1 -1
- data/tracks/rust/exercises/nth-prime/Cargo.lock +4 -0
- data/tracks/rust/exercises/nth-prime/Cargo.toml +6 -0
- data/tracks/rust/exercises/nth-prime/README.md +47 -0
- data/tracks/rust/exercises/nth-prime/example.rs +28 -0
- data/tracks/rust/exercises/nth-prime/src/lib.rs +0 -0
- data/tracks/rust/exercises/nth-prime/tests/nth-prime.rs +30 -0
- data/tracks/rust/exercises/parallel-letter-frequency/example.rs +1 -1
- data/tracks/rust/exercises/phone-number/example.rs +1 -1
- data/tracks/rust/exercises/pythagorean-triplet/Cargo.lock +4 -0
- data/tracks/rust/exercises/pythagorean-triplet/Cargo.toml +6 -0
- data/tracks/rust/exercises/pythagorean-triplet/README.md +56 -0
- data/tracks/rust/exercises/pythagorean-triplet/example.rs +11 -0
- data/tracks/rust/exercises/pythagorean-triplet/src/lib.rs +0 -0
- data/tracks/rust/exercises/pythagorean-triplet/tests/pythagorean-triplet.rs +6 -0
- data/tracks/rust/exercises/rna-transcription/tests/rna-transcription.rs +1 -1
- data/tracks/rust/exercises/robot-name/tests/robot-name.rs +2 -2
- data/tracks/rust/exercises/say/example.rs +4 -4
- data/tracks/rust/exercises/say/tests/say.rs +4 -4
- data/tracks/rust/exercises/tournament/example.rs +2 -2
- data/tracks/scala/config/maintainers.json +10 -6
- data/tracks/scala/exercises/bracket-push/example.scala +2 -2
- data/tracks/scala/exercises/bracket-push/src/test/scala/BracketPushTest.scala +74 -0
- data/tracks/scala/exercises/crypto-square/example.scala +9 -9
- data/tracks/scala/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala +33 -41
- data/tracks/scala/testgen/src/main/scala/BracketPushTestGenerator.scala +9 -38
- data/tracks/scala/testgen/src/main/scala/CryptoSquareTestGenerator.scala +17 -0
- data/tracks/sml/config.json +1 -1
- data/tracks/swift/config/maintainers.json +35 -0
- data/tracks/swift/docs/ABOUT.md +15 -5
- data/tracks/vimscript/config/maintainers.json +35 -0
- metadata +58 -8
- data/tracks/ocaml/exercises/point-mutations/Makefile +0 -8
- data/tracks/ocaml/exercises/point-mutations/README.md +0 -81
- data/tracks/ocaml/exercises/point-mutations/dna.mli +0 -6
- data/tracks/scala/exercises/bracket-push/src/test/scala/BracketsTest.scala +0 -68
- data/tracks/scala/exercises/crypto-square/src/main/scala/CryptoSquare.scala +0 -11
data/tracks/rust/config.json
CHANGED
@@ -46,6 +46,15 @@
|
|
46
46
|
"Mutable string"
|
47
47
|
]
|
48
48
|
},
|
49
|
+
{
|
50
|
+
"uuid": "ee5048a7-c625-434d-a0a2-4fd54757ee02",
|
51
|
+
"slug": "nth-prime",
|
52
|
+
"core": false,
|
53
|
+
"unlocked_by": null,
|
54
|
+
"difficulty": 1,
|
55
|
+
"topics": [
|
56
|
+
]
|
57
|
+
},
|
49
58
|
{
|
50
59
|
"uuid": "38ef1802-2730-4f94-bafe-d2cd6b3e7f95",
|
51
60
|
"slug": "bob",
|
@@ -113,6 +122,16 @@
|
|
113
122
|
"panic"
|
114
123
|
]
|
115
124
|
},
|
125
|
+
{
|
126
|
+
"uuid": "6e7cac84-99d1-4f9f-b7d6-48ea43024bc0",
|
127
|
+
"slug": "pythagorean-triplet",
|
128
|
+
"core": false,
|
129
|
+
"unlocked_by": null,
|
130
|
+
"difficulty": 1,
|
131
|
+
"topics": [
|
132
|
+
"option"
|
133
|
+
]
|
134
|
+
},
|
116
135
|
{
|
117
136
|
"uuid": "9f649818-0c82-4b79-b912-4d65b9f60e10",
|
118
137
|
"slug": "prime-factors",
|
@@ -133,7 +152,7 @@
|
|
133
152
|
"string concatenation",
|
134
153
|
"modulus"
|
135
154
|
]
|
136
|
-
},
|
155
|
+
},
|
137
156
|
{
|
138
157
|
"uuid": "4dc9b165-792a-4438-be80-df9aab6f6a9c",
|
139
158
|
"slug": "run-length-encoding",
|
@@ -147,6 +166,18 @@
|
|
147
166
|
"loop"
|
148
167
|
]
|
149
168
|
},
|
169
|
+
{
|
170
|
+
"uuid": "543a3ca2-fb9b-4f20-a873-ff23595d41df",
|
171
|
+
"slug": "clock",
|
172
|
+
"core": false,
|
173
|
+
"unlocked_by": null,
|
174
|
+
"difficulty": 4,
|
175
|
+
"topics": [
|
176
|
+
"traits",
|
177
|
+
"derive",
|
178
|
+
"struct"
|
179
|
+
]
|
180
|
+
},
|
150
181
|
{
|
151
182
|
"uuid": "2874216a-0822-4ec2-892e-d451fd89646a",
|
152
183
|
"slug": "hamming",
|
@@ -13,13 +13,13 @@ pub struct CircularBuffer<T: Default + Clone> {
|
|
13
13
|
|
14
14
|
impl<T: Default + Clone> CircularBuffer<T> {
|
15
15
|
// this circular buffer keeps an unallocated slot between the start and the end
|
16
|
-
// when the buffer is full.
|
16
|
+
// when the buffer is full.
|
17
17
|
pub fn new(size: usize) -> CircularBuffer<T> {
|
18
|
-
CircularBuffer {
|
19
|
-
buffer: vec![T::default(); size + 1],
|
20
|
-
size: size + 1,
|
21
|
-
start: 0,
|
22
|
-
end: 0
|
18
|
+
CircularBuffer {
|
19
|
+
buffer: vec![T::default(); size + 1],
|
20
|
+
size: size + 1,
|
21
|
+
start: 0,
|
22
|
+
end: 0
|
23
23
|
}
|
24
24
|
}
|
25
25
|
|
@@ -36,12 +36,11 @@ impl<T: Default + Clone> CircularBuffer<T> {
|
|
36
36
|
pub fn write(&mut self, byte: T) -> Result<(), Error> {
|
37
37
|
if self.is_full() {
|
38
38
|
return Err(Error::FullBuffer);
|
39
|
-
}
|
40
|
-
|
39
|
+
}
|
40
|
+
|
41
41
|
self.buffer[self.end] = byte;
|
42
42
|
self.advance_end();
|
43
43
|
Ok(())
|
44
|
-
|
45
44
|
}
|
46
45
|
|
47
46
|
pub fn overwrite(&mut self, byte: T) {
|
@@ -73,5 +72,4 @@ impl<T: Default + Clone> CircularBuffer<T> {
|
|
73
72
|
fn advance_end(&mut self) {
|
74
73
|
self.end = (self.end + 1) % self.size;
|
75
74
|
}
|
76
|
-
|
77
75
|
}
|
@@ -65,7 +65,7 @@ mod tests {
|
|
65
65
|
buffer.write('2');
|
66
66
|
assert_eq!(Err(Error::FullBuffer), buffer.write('3'));
|
67
67
|
}
|
68
|
-
|
68
|
+
|
69
69
|
#[test]
|
70
70
|
#[ignore]
|
71
71
|
fn overwrite_item_in_non_full_buffer() {
|
@@ -100,7 +100,7 @@ mod tests {
|
|
100
100
|
assert_eq!(-1,buffer.read().unwrap());
|
101
101
|
assert_eq!(Err(Error::EmptyBuffer), buffer.read());
|
102
102
|
}
|
103
|
-
|
103
|
+
|
104
104
|
#[test]
|
105
105
|
#[ignore]
|
106
106
|
fn string_buffer() {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
## Rust Traits for .to_string()
|
2
|
+
|
3
|
+
Did you implement .to_string() for the Clock struct?
|
4
|
+
|
5
|
+
If so, try implementing the
|
6
|
+
[Display trait](https://doc.rust-lang.org/std/fmt/trait.Display.html) for Clock instead.
|
7
|
+
|
8
|
+
Traits allow for a common way to implement functionality for various types.
|
9
|
+
|
10
|
+
For additional learning, how would you implement String::from for the Clock type?
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Clock
|
2
|
+
|
3
|
+
Implement a clock that handles times without dates.
|
4
|
+
|
5
|
+
You should be able to add and subtract minutes to it.
|
6
|
+
|
7
|
+
Two clocks that represent the same time should be equal to each other.
|
8
|
+
|
9
|
+
## Rust Traits for .to_string()
|
10
|
+
|
11
|
+
Did you implement .to_string() for the Clock struct?
|
12
|
+
|
13
|
+
If so, try implementing the
|
14
|
+
[Display trait](https://doc.rust-lang.org/std/fmt/trait.Display.html) for Clock instead.
|
15
|
+
|
16
|
+
Traits allow for a common way to implement functionality for various types.
|
17
|
+
|
18
|
+
For additional learning, how would you implement String::from for the Clock type?
|
19
|
+
|
20
|
+
|
21
|
+
## Rust Installation
|
22
|
+
|
23
|
+
Refer to the [exercism help page][help-page] for Rust installation and learning
|
24
|
+
resources.
|
25
|
+
|
26
|
+
## Writing the Code
|
27
|
+
|
28
|
+
Execute the tests with:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ cargo test
|
32
|
+
```
|
33
|
+
|
34
|
+
All but the first test have been ignored. After you get the first test to
|
35
|
+
pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests
|
36
|
+
to pass again. The test file is located in the `tests` directory. You can
|
37
|
+
also remove the ignore flag from all the tests to get them to run all at once
|
38
|
+
if you wish.
|
39
|
+
|
40
|
+
Make sure to read the [Crates and Modules](https://doc.rust-lang.org/stable/book/crates-and-modules.html) chapter if you
|
41
|
+
haven't already, it will help you with organizing your files.
|
42
|
+
|
43
|
+
## Feedback, Issues, Pull Requests
|
44
|
+
|
45
|
+
The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help!
|
46
|
+
|
47
|
+
If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md).
|
48
|
+
|
49
|
+
[help-page]: http://exercism.io/languages/rust
|
50
|
+
[crates-and-modules]: http://doc.rust-lang.org/stable/book/crates-and-modules.html
|
51
|
+
|
52
|
+
## Source
|
53
|
+
|
54
|
+
Pairing session with Erin Drummond [https://twitter.com/ebdrummond](https://twitter.com/ebdrummond)
|
55
|
+
|
56
|
+
## Submitting Incomplete Solutions
|
57
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
use std::fmt;
|
2
|
+
|
3
|
+
#[derive(Eq,PartialEq,Debug)]
|
4
|
+
pub struct Clock {
|
5
|
+
minutes: i32
|
6
|
+
}
|
7
|
+
|
8
|
+
impl fmt::Display for Clock {
|
9
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
10
|
+
let hours = self.minutes / 60;
|
11
|
+
let mins = self.minutes % 60;
|
12
|
+
write!(f, "{:02}:{:02}", hours, mins)
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
impl Clock {
|
17
|
+
pub fn new(hour: i32, minute: i32) -> Self {
|
18
|
+
Clock::build(hour * 60 + minute)
|
19
|
+
}
|
20
|
+
|
21
|
+
fn build(minutes: i32) -> Self {
|
22
|
+
let mut mins = minutes;
|
23
|
+
while mins < 0 {
|
24
|
+
mins += 1440;
|
25
|
+
}
|
26
|
+
Clock { minutes: mins % 1440 }
|
27
|
+
}
|
28
|
+
|
29
|
+
pub fn add_minutes(&mut self, minutes: i32) -> Self {
|
30
|
+
Clock::build(self.minutes + minutes)
|
31
|
+
}
|
32
|
+
}
|
File without changes
|
@@ -0,0 +1,331 @@
|
|
1
|
+
extern crate clock;
|
2
|
+
|
3
|
+
use clock::Clock;
|
4
|
+
|
5
|
+
//
|
6
|
+
// Clock Creation
|
7
|
+
//
|
8
|
+
|
9
|
+
#[test]
|
10
|
+
fn test_on_the_hour() {
|
11
|
+
assert_eq!(Clock::new(8, 0).to_string(), "08:00");
|
12
|
+
}
|
13
|
+
|
14
|
+
#[test]
|
15
|
+
#[ignore]
|
16
|
+
fn test_past_the_hour() {
|
17
|
+
assert_eq!(Clock::new(11, 9).to_string(), "11:09");
|
18
|
+
}
|
19
|
+
|
20
|
+
#[test]
|
21
|
+
#[ignore]
|
22
|
+
fn test_midnight_is_zero_hours() {
|
23
|
+
assert_eq!(Clock::new(24, 0).to_string(), "00:00");
|
24
|
+
}
|
25
|
+
|
26
|
+
#[test]
|
27
|
+
#[ignore]
|
28
|
+
fn test_hour_rolls_over() {
|
29
|
+
assert_eq!(Clock::new(25, 0).to_string(), "01:00");
|
30
|
+
}
|
31
|
+
|
32
|
+
#[test]
|
33
|
+
#[ignore]
|
34
|
+
fn test_hour_rolls_over_continuously() {
|
35
|
+
assert_eq!(Clock::new(100, 0).to_string(), "04:00");
|
36
|
+
}
|
37
|
+
|
38
|
+
#[test]
|
39
|
+
#[ignore]
|
40
|
+
fn test_sixty_minutes_is_next_hour() {
|
41
|
+
assert_eq!(Clock::new(1, 60).to_string(), "02:00");
|
42
|
+
}
|
43
|
+
|
44
|
+
#[test]
|
45
|
+
#[ignore]
|
46
|
+
fn test_minutes_roll_over() {
|
47
|
+
assert_eq!(Clock::new(0, 160).to_string(), "02:40");
|
48
|
+
}
|
49
|
+
|
50
|
+
#[test]
|
51
|
+
#[ignore]
|
52
|
+
fn test_minutes_roll_over_continuously() {
|
53
|
+
assert_eq!(Clock::new(0, 1723).to_string(), "04:43");
|
54
|
+
}
|
55
|
+
|
56
|
+
#[test]
|
57
|
+
#[ignore]
|
58
|
+
fn test_hours_and_minutes_roll_over() {
|
59
|
+
assert_eq!(Clock::new(25, 160).to_string(), "03:40");
|
60
|
+
}
|
61
|
+
|
62
|
+
#[test]
|
63
|
+
#[ignore]
|
64
|
+
fn test_hours_and_minutes_roll_over_continuously() {
|
65
|
+
assert_eq!(Clock::new(201, 3001).to_string(), "11:01");
|
66
|
+
}
|
67
|
+
|
68
|
+
#[test]
|
69
|
+
#[ignore]
|
70
|
+
fn test_hours_and_minutes_roll_over_to_exactly_midnight() {
|
71
|
+
assert_eq!(Clock::new(72, 8640).to_string(), "00:00");
|
72
|
+
}
|
73
|
+
|
74
|
+
#[test]
|
75
|
+
#[ignore]
|
76
|
+
fn test_negative_hour() {
|
77
|
+
assert_eq!(Clock::new(-1, 15).to_string(), "23:15");
|
78
|
+
}
|
79
|
+
|
80
|
+
#[test]
|
81
|
+
#[ignore]
|
82
|
+
fn test_negative_hour_roll_over() {
|
83
|
+
assert_eq!(Clock::new(-25, 00).to_string(), "23:00");
|
84
|
+
}
|
85
|
+
|
86
|
+
#[test]
|
87
|
+
#[ignore]
|
88
|
+
fn test_negative_hour_roll_over_continuously() {
|
89
|
+
assert_eq!(Clock::new(-91, 00).to_string(), "05:00");
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
#[test]
|
94
|
+
#[ignore]
|
95
|
+
fn test_negative_minutes() {
|
96
|
+
assert_eq!(Clock::new(1, -40).to_string(), "00:20");
|
97
|
+
}
|
98
|
+
|
99
|
+
#[test]
|
100
|
+
#[ignore]
|
101
|
+
fn test_negative_minutes_roll_over() {
|
102
|
+
assert_eq!(Clock::new(1, -160).to_string(), "22:20");
|
103
|
+
}
|
104
|
+
|
105
|
+
#[test]
|
106
|
+
#[ignore]
|
107
|
+
fn test_negative_minutes_roll_over_continuously() {
|
108
|
+
assert_eq!(Clock::new(1, -4820).to_string(), "16:40");
|
109
|
+
}
|
110
|
+
|
111
|
+
#[test]
|
112
|
+
#[ignore]
|
113
|
+
fn test_negative_hour_and_minutes_both_roll_over() {
|
114
|
+
assert_eq!(Clock::new(-25, -160).to_string(), "20:20");
|
115
|
+
}
|
116
|
+
|
117
|
+
#[test]
|
118
|
+
#[ignore]
|
119
|
+
fn test_negative_hour_and_minutes_both_roll_over_continuously() {
|
120
|
+
assert_eq!(Clock::new(-121, -5810).to_string(), "22:10");
|
121
|
+
}
|
122
|
+
|
123
|
+
//
|
124
|
+
// Clock Math
|
125
|
+
//
|
126
|
+
|
127
|
+
#[test]
|
128
|
+
#[ignore]
|
129
|
+
fn test_add_minutes() {
|
130
|
+
let clock = Clock::new(10, 0).add_minutes(3);
|
131
|
+
assert_eq!(clock.to_string(), "10:03");
|
132
|
+
}
|
133
|
+
|
134
|
+
#[test]
|
135
|
+
#[ignore]
|
136
|
+
fn test_add_no_minutes() {
|
137
|
+
let clock = Clock::new(6, 41).add_minutes(0);
|
138
|
+
assert_eq!(clock.to_string(), "06:41");
|
139
|
+
}
|
140
|
+
|
141
|
+
#[test]
|
142
|
+
#[ignore]
|
143
|
+
fn test_add_to_next_hour() {
|
144
|
+
let clock = Clock::new(0, 45).add_minutes(40);
|
145
|
+
assert_eq!(clock.to_string(), "01:25");
|
146
|
+
}
|
147
|
+
|
148
|
+
#[test]
|
149
|
+
#[ignore]
|
150
|
+
fn test_add_more_than_one_hour() {
|
151
|
+
let clock = Clock::new(10, 0).add_minutes(61);
|
152
|
+
assert_eq!(clock.to_string(), "11:01");
|
153
|
+
}
|
154
|
+
|
155
|
+
#[test]
|
156
|
+
#[ignore]
|
157
|
+
fn test_add_more_than_two_hours_with_carry() {
|
158
|
+
let clock = Clock::new(0, 45).add_minutes(160);
|
159
|
+
assert_eq!(clock.to_string(), "03:25");
|
160
|
+
}
|
161
|
+
|
162
|
+
#[test]
|
163
|
+
#[ignore]
|
164
|
+
fn test_add_across_midnight() {
|
165
|
+
let clock = Clock::new(23, 59).add_minutes(2);
|
166
|
+
assert_eq!(clock.to_string(), "00:01");
|
167
|
+
}
|
168
|
+
|
169
|
+
#[test]
|
170
|
+
#[ignore]
|
171
|
+
fn test_add_more_than_one_day() {
|
172
|
+
let clock = Clock::new(5, 32).add_minutes(1500);
|
173
|
+
assert_eq!(clock.to_string(), "06:32");
|
174
|
+
}
|
175
|
+
|
176
|
+
#[test]
|
177
|
+
#[ignore]
|
178
|
+
fn test_add_more_than_two_days() {
|
179
|
+
let clock = Clock::new(1, 1).add_minutes(3500);
|
180
|
+
assert_eq!(clock.to_string(), "11:21");
|
181
|
+
}
|
182
|
+
|
183
|
+
#[test]
|
184
|
+
#[ignore]
|
185
|
+
fn test_subtract_minutes() {
|
186
|
+
let clock = Clock::new(10, 3).add_minutes(-3);
|
187
|
+
assert_eq!(clock.to_string(), "10:00");
|
188
|
+
}
|
189
|
+
|
190
|
+
#[test]
|
191
|
+
#[ignore]
|
192
|
+
fn test_subtract_to_previous_hour() {
|
193
|
+
let clock = Clock::new(10, 3).add_minutes(-30);
|
194
|
+
assert_eq!(clock.to_string(), "09:33");
|
195
|
+
}
|
196
|
+
|
197
|
+
#[test]
|
198
|
+
#[ignore]
|
199
|
+
fn test_subtract_more_than_an_hour() {
|
200
|
+
let clock = Clock::new(10, 3).add_minutes(-70);
|
201
|
+
assert_eq!(clock.to_string(), "08:53");
|
202
|
+
}
|
203
|
+
|
204
|
+
#[test]
|
205
|
+
#[ignore]
|
206
|
+
fn test_subtract_across_midnight() {
|
207
|
+
let clock = Clock::new(0, 3).add_minutes(-4);
|
208
|
+
assert_eq!(clock.to_string(), "23:59");
|
209
|
+
}
|
210
|
+
|
211
|
+
#[test]
|
212
|
+
#[ignore]
|
213
|
+
fn test_subtract_more_than_two_hours() {
|
214
|
+
let clock = Clock::new(0, 0).add_minutes(-160);
|
215
|
+
assert_eq!(clock.to_string(), "21:20");
|
216
|
+
}
|
217
|
+
|
218
|
+
#[test]
|
219
|
+
#[ignore]
|
220
|
+
fn test_subtract_more_than_two_hours_with_borrow() {
|
221
|
+
let clock = Clock::new(6, 15).add_minutes(-160);
|
222
|
+
assert_eq!(clock.to_string(), "03:35");
|
223
|
+
}
|
224
|
+
|
225
|
+
#[test]
|
226
|
+
#[ignore]
|
227
|
+
fn test_subtract_more_than_one_day() {
|
228
|
+
let clock = Clock::new(5, 32).add_minutes(-1500);
|
229
|
+
assert_eq!(clock.to_string(), "04:32");
|
230
|
+
}
|
231
|
+
|
232
|
+
#[test]
|
233
|
+
#[ignore]
|
234
|
+
fn test_subtract_mores_than_two_days() {
|
235
|
+
let clock = Clock::new(2, 20).add_minutes(-3000);
|
236
|
+
assert_eq!(clock.to_string(), "00:20");
|
237
|
+
}
|
238
|
+
|
239
|
+
//
|
240
|
+
// Test Equality
|
241
|
+
//
|
242
|
+
|
243
|
+
#[test]
|
244
|
+
#[ignore]
|
245
|
+
fn test_compare_clocks_for_equality() {
|
246
|
+
assert_eq!(Clock::new(15, 37), Clock::new(15, 37));
|
247
|
+
}
|
248
|
+
|
249
|
+
#[test]
|
250
|
+
#[ignore]
|
251
|
+
fn test_compare_clocks_a_minute_apart() {
|
252
|
+
assert_ne!(Clock::new(15, 36), Clock::new(15, 37));
|
253
|
+
}
|
254
|
+
|
255
|
+
#[test]
|
256
|
+
#[ignore]
|
257
|
+
fn test_compare_clocks_an_hour_apart() {
|
258
|
+
assert_ne!(Clock::new(14, 37), Clock::new(15, 37));
|
259
|
+
}
|
260
|
+
|
261
|
+
#[test]
|
262
|
+
#[ignore]
|
263
|
+
fn test_compare_clocks_with_hour_overflow() {
|
264
|
+
assert_eq!(Clock::new(10, 37), Clock::new(34, 37));
|
265
|
+
}
|
266
|
+
|
267
|
+
#[test]
|
268
|
+
#[ignore]
|
269
|
+
fn test_compare_clocks_with_hour_overflow_by_several_days() {
|
270
|
+
assert_eq!(Clock::new(3, 11), Clock::new(99, 11));
|
271
|
+
}
|
272
|
+
|
273
|
+
#[test]
|
274
|
+
#[ignore]
|
275
|
+
fn test_compare_clocks_with_negative_hour() {
|
276
|
+
assert_eq!(Clock::new(22, 40), Clock::new(-2, 40));
|
277
|
+
}
|
278
|
+
|
279
|
+
#[test]
|
280
|
+
#[ignore]
|
281
|
+
fn test_compare_clocks_with_negative_hour_that_wraps() {
|
282
|
+
assert_eq!(Clock::new(17, 3), Clock::new(-31, 3));
|
283
|
+
}
|
284
|
+
|
285
|
+
#[test]
|
286
|
+
#[ignore]
|
287
|
+
fn test_compare_clocks_with_negative_hour_that_wraps_multiple_times() {
|
288
|
+
assert_eq!(Clock::new(13, 49), Clock::new(-83, 49));
|
289
|
+
}
|
290
|
+
|
291
|
+
#[test]
|
292
|
+
#[ignore]
|
293
|
+
fn test_compare_clocks_with_minutes_overflow() {
|
294
|
+
assert_eq!(Clock::new(0, 1), Clock::new(0, 1441));
|
295
|
+
}
|
296
|
+
|
297
|
+
#[test]
|
298
|
+
#[ignore]
|
299
|
+
fn test_compare_clocks_with_minutes_overflow_by_several_days() {
|
300
|
+
assert_eq!(Clock::new(2, 2), Clock::new(2, 4322));
|
301
|
+
}
|
302
|
+
|
303
|
+
#[test]
|
304
|
+
#[ignore]
|
305
|
+
fn test_compare_clocks_with_negative_minute() {
|
306
|
+
assert_eq!(Clock::new(2, 40), Clock::new(3, -20))
|
307
|
+
}
|
308
|
+
|
309
|
+
#[test]
|
310
|
+
#[ignore]
|
311
|
+
fn test_compare_clocks_with_negative_minute_that_wraps() {
|
312
|
+
assert_eq!(Clock::new(4, 10), Clock::new(5, -1490))
|
313
|
+
}
|
314
|
+
|
315
|
+
#[test]
|
316
|
+
#[ignore]
|
317
|
+
fn test_compare_clocks_with_negative_minute_that_wraps_multiple() {
|
318
|
+
assert_eq!(Clock::new(6, 15), Clock::new(6, -4305))
|
319
|
+
}
|
320
|
+
|
321
|
+
#[test]
|
322
|
+
#[ignore]
|
323
|
+
fn test_compare_clocks_with_negative_hours_and_minutes() {
|
324
|
+
assert_eq!(Clock::new(7, 32), Clock::new(-12, -268))
|
325
|
+
}
|
326
|
+
|
327
|
+
#[test]
|
328
|
+
#[ignore]
|
329
|
+
fn test_compare_clocks_with_negative_hours_and_minutes_that_wrap() {
|
330
|
+
assert_eq!(Clock::new(18, 7), Clock::new(-54, -11513))
|
331
|
+
}
|