Ai
2 Star 1 Fork 0

endpoint_rust/Rust

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
another_rot13.rs 935 Bytes
一键复制 编辑 原始数据 按行查看 历史
pub fn another_rot13(text: &str) -> String {
let input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let output = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
text.chars()
.map(|c| match input.find(c) {
Some(i) => output.chars().nth(i).unwrap(),
None => c,
})
.collect()
}
#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn test_simple() {
assert_eq!(another_rot13("ABCzyx"), "NOPmlk");
}
#[test]
fn test_every_alphabet_with_space() {
assert_eq!(
another_rot13("The quick brown fox jumps over the lazy dog"),
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt"
);
}
#[test]
fn test_non_alphabet() {
assert_eq!(another_rot13("🎃 Jack-o'-lantern"), "🎃 Wnpx-b'-ynagrea");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/endpoint_rust/Rust.git
git@gitee.com:endpoint_rust/Rust.git
endpoint_rust
Rust
Rust
master

搜索帮助