Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation to polybius and moved two of the tests into doc e… #79

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions src/ciphers/polybius.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/// Encode an ASCII string into its location in a Polybius square.
/// Only alphabetical characters are encoded.
///
/// # Arguments
///
/// * `string` - The ASCII string to encode.
///
/// # Returns
///
/// The encoded string representing the location of each character in the Polybius square.
///
/// # Examples
///
/// ```rust
/// use rust_algorithms::ciphers::encode_ascii;
///
/// let encoded = encode_ascii("This is a test");
///
/// assert_eq!(encoded, "4423244324431144154344");
/// ```
pub fn encode_ascii(string: &str) -> String {
string
.chars()
Expand Down Expand Up @@ -38,6 +56,24 @@ pub fn encode_ascii(string: &str) -> String {
/// letters in a Polybius square.
///
/// Any invalid characters, or whitespace will be ignored.
///
/// # Arguments
///
/// * `string` - The string of integers to decode.
///
/// # Returns
///
/// The decoded string representing the corresponding letters in the Polybius square.
///
/// # Examples
///
/// ```rust
/// use rust_algorithms::ciphers::decode_ascii;
///
/// let decoded = decode_ascii("44 23 24 43 24 43 11 44 15 43 44 ");
///
/// assert_eq!(decoded, "THISISATEST");
/// ```
pub fn decode_ascii(string: &str) -> String {
string
.chars()
Expand Down Expand Up @@ -90,11 +126,6 @@ mod tests {
assert_eq!(encode_ascii(""), "");
}

#[test]
fn encode_valid_string() {
assert_eq!(encode_ascii("This is a test"), "4423244324431144154344");
}

#[test]
fn encode_emoji() {
assert_eq!(encode_ascii("🙂"), "");
Expand All @@ -105,14 +136,6 @@ mod tests {
assert_eq!(decode_ascii(""), "");
}

#[test]
fn decode_valid_string() {
assert_eq!(
decode_ascii("44 23 24 43 24 43 11 44 15 43 44 "),
"THISISATEST"
);
}

#[test]
fn decode_emoji() {
assert_eq!(decode_ascii("🙂"), "");
Expand Down
Loading