Skip to content

Commit a97a1a2

Browse files
ref(docs): polish polybius cipher docs (#79)
1 parent 817f850 commit a97a1a2

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/ciphers/polybius.rs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
/// Encode an ASCII string into its location in a Polybius square.
22
/// Only alphabetical characters are encoded.
3+
///
4+
/// # Arguments
5+
///
6+
/// * `string` - The ASCII string to encode.
7+
///
8+
/// # Returns
9+
///
10+
/// The encoded string representing the location of each character in the Polybius square.
11+
///
12+
/// # Examples
13+
///
14+
/// ```rust
15+
/// use rust_algorithms::ciphers::encode_ascii;
16+
///
17+
/// let encoded = encode_ascii("This is a test");
18+
///
19+
/// assert_eq!(encoded, "4423244324431144154344");
20+
/// ```
321
pub fn encode_ascii(string: &str) -> String {
422
string
523
.chars()
@@ -38,6 +56,24 @@ pub fn encode_ascii(string: &str) -> String {
3856
/// letters in a Polybius square.
3957
///
4058
/// Any invalid characters, or whitespace will be ignored.
59+
///
60+
/// # Arguments
61+
///
62+
/// * `string` - The string of integers to decode.
63+
///
64+
/// # Returns
65+
///
66+
/// The decoded string representing the corresponding letters in the Polybius square.
67+
///
68+
/// # Examples
69+
///
70+
/// ```rust
71+
/// use rust_algorithms::ciphers::decode_ascii;
72+
///
73+
/// let decoded = decode_ascii("44 23 24 43 24 43 11 44 15 43 44 ");
74+
///
75+
/// assert_eq!(decoded, "THISISATEST");
76+
/// ```
4177
pub fn decode_ascii(string: &str) -> String {
4278
string
4379
.chars()
@@ -90,11 +126,6 @@ mod tests {
90126
assert_eq!(encode_ascii(""), "");
91127
}
92128

93-
#[test]
94-
fn encode_valid_string() {
95-
assert_eq!(encode_ascii("This is a test"), "4423244324431144154344");
96-
}
97-
98129
#[test]
99130
fn encode_emoji() {
100131
assert_eq!(encode_ascii("🙂"), "");
@@ -105,14 +136,6 @@ mod tests {
105136
assert_eq!(decode_ascii(""), "");
106137
}
107138

108-
#[test]
109-
fn decode_valid_string() {
110-
assert_eq!(
111-
decode_ascii("44 23 24 43 24 43 11 44 15 43 44 "),
112-
"THISISATEST"
113-
);
114-
}
115-
116139
#[test]
117140
fn decode_emoji() {
118141
assert_eq!(decode_ascii("🙂"), "");

0 commit comments

Comments
 (0)