-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync rail-fence-cipher with problem-specifications (#1787)
[no important files changed]
- Loading branch information
Showing
4 changed files
with
102 additions
and
61 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
exercises/practice/rail-fence-cipher/.meta/additional-tests.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"uuid": "46dc5c50-5538-401d-93a5-41102680d068", | ||
"description": "encode wide characters", | ||
"property": "encode", | ||
"input": { | ||
"msg": "古池蛙飛び込む水の音", | ||
"rails": 3 | ||
}, | ||
"expected": "古びの池飛込水音蛙む" | ||
} | ||
] |
19 changes: 19 additions & 0 deletions
19
exercises/practice/rail-fence-cipher/.meta/test_template.tera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use rail_fence_cipher::RailFence; | ||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | slugify | replace(from="-", to="_") }}() { | ||
let input = {{ test.input.msg | json_encode() }}; | ||
let rails = {{ test.input.rails | json_encode() }}; | ||
let rail_fence = RailFence::new(rails); | ||
{% if test.property == "encode" -%} | ||
let output = rail_fence.encode(input); | ||
{%- else -%} | ||
let output = rail_fence.decode(input); | ||
{%- endif %} | ||
let expected = {{ test.expected | json_encode() }}; | ||
assert_eq!(output, expected); | ||
} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
# This is an auto-generated file. Regular comments will be removed when this | ||
# file is regenerated. Regenerating will not touch any manually added keys, | ||
# so comments can be added in a "comment" key. | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[46dc5c50-5538-401d-93a5-41102680d068] | ||
description = "encode -> encode with two rails" | ||
|
||
[25691697-fbd8-4278-8c38-b84068b7bc29] | ||
description = "encode -> encode with three rails" | ||
|
||
[384f0fea-1442-4f1a-a7c4-5cbc2044002c] | ||
description = "encode -> encode with ending in the middle" | ||
|
||
[cd525b17-ec34-45ef-8f0e-4f27c24a7127] | ||
description = "decode -> decode with three rails" | ||
|
||
[dd7b4a98-1a52-4e5c-9499-cbb117833507] | ||
description = "decode -> decode with five rails" | ||
|
||
[93e1ecf4-fac9-45d9-9cd2-591f47d3b8d3] | ||
description = "decode -> decode with six rails" |
101 changes: 43 additions & 58 deletions
101
exercises/practice/rail-fence-cipher/tests/rail-fence-cipher.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,77 @@ | ||
//! Tests for rail-fence-cipher | ||
//! | ||
//! Generated by [script][script] using [canonical data][canonical-data] | ||
//! | ||
//! [script]: https://github.com/exercism/rust/blob/main/bin/init_exercise.py | ||
//! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/rail-fence-cipher/canonical_data.json | ||
//! | ||
//! The tests do not expect any normalization or cleaning. | ||
//! That trade is tested in enough other exercises. | ||
use rail_fence_cipher::*; | ||
|
||
/// Process a single test case for the property `encode` | ||
/// | ||
/// All cases for the `encode` property are implemented | ||
/// in terms of this function. | ||
fn process_encode_case(input: &str, rails: u32, expected: &str) { | ||
let rail_fence = RailFence::new(rails); | ||
assert_eq!(rail_fence.encode(input), expected); | ||
} | ||
|
||
/// Process a single test case for the property `decode` | ||
/// | ||
/// All cases for the `decode` property are implemented | ||
/// in terms of this function. | ||
fn process_decode_case(input: &str, rails: u32, expected: &str) { | ||
let rail_fence = RailFence::new(rails); | ||
assert_eq!(rail_fence.decode(input), expected); | ||
} | ||
|
||
// encode | ||
use rail_fence_cipher::RailFence; | ||
|
||
#[test] | ||
/// encode with two rails | ||
fn encode_with_two_rails() { | ||
process_encode_case("XOXOXOXOXOXOXOXOXO", 2, "XXXXXXXXXOOOOOOOOO"); | ||
let input = "XOXOXOXOXOXOXOXOXO"; | ||
let rails = 2; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.encode(input); | ||
let expected = "XXXXXXXXXOOOOOOOOO"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
/// encode with three rails | ||
fn encode_with_three_rails() { | ||
process_encode_case("WEAREDISCOVEREDFLEEATONCE", 3, "WECRLTEERDSOEEFEAOCAIVDEN"); | ||
let input = "WEAREDISCOVEREDFLEEATONCE"; | ||
let rails = 3; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.encode(input); | ||
let expected = "WECRLTEERDSOEEFEAOCAIVDEN"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
/// encode with ending in the middle | ||
fn encode_with_ending_in_the_middle() { | ||
process_encode_case("EXERCISES", 4, "ESXIEECSR"); | ||
let input = "EXERCISES"; | ||
let rails = 4; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.encode(input); | ||
let expected = "ESXIEECSR"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
// decode | ||
|
||
#[test] | ||
#[ignore] | ||
/// decode with three rails | ||
fn decode_with_three_rails() { | ||
process_decode_case("TEITELHDVLSNHDTISEIIEA", 3, "THEDEVILISINTHEDETAILS"); | ||
let input = "TEITELHDVLSNHDTISEIIEA"; | ||
let rails = 3; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.decode(input); | ||
let expected = "THEDEVILISINTHEDETAILS"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
/// decode with five rails | ||
fn decode_with_five_rails() { | ||
process_decode_case("EIEXMSMESAORIWSCE", 5, "EXERCISMISAWESOME"); | ||
let input = "EIEXMSMESAORIWSCE"; | ||
let rails = 5; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.decode(input); | ||
let expected = "EXERCISMISAWESOME"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
/// decode with six rails | ||
fn decode_with_six_rails() { | ||
process_decode_case( | ||
"133714114238148966225439541018335470986172518171757571896261", | ||
6, | ||
"112358132134558914423337761098715972584418167651094617711286", | ||
); | ||
let input = "133714114238148966225439541018335470986172518171757571896261"; | ||
let rails = 6; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.decode(input); | ||
let expected = "112358132134558914423337761098715972584418167651094617711286"; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
/// encode wide characters | ||
/// | ||
/// normally unicode is not part of exercism exercises, but in an exercise | ||
/// specifically oriented around shuffling characters, it seems worth ensuring | ||
/// that wide characters are handled properly | ||
/// | ||
/// this text is possibly one of the most famous haiku of all time, by | ||
/// Matsuo Bashō (松尾芭蕉) | ||
fn encode_wide_characters() { | ||
process_encode_case("古池蛙飛び込む水の音", 3, "古びの池飛込水音蛙む"); | ||
let input = "古池蛙飛び込む水の音"; | ||
let rails = 3; | ||
let rail_fence = RailFence::new(rails); | ||
let output = rail_fence.encode(input); | ||
let expected = "古びの池飛込水音蛙む"; | ||
assert_eq!(output, expected); | ||
} |