Add reverse and its test

This commit is contained in:
KAAAsS 2021-02-05 18:19:58 +08:00
parent 5ba61ba026
commit fd96a13916
Signed by: KAAAsS
GPG Key ID: D56625F3E671882F
4 changed files with 43 additions and 0 deletions

5
.gitignore vendored
View File

@ -11,3 +11,8 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
#Added by cargo
/target

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "ci-test"
version = "0.1.0"
authors = ["KAAAsS <admin@kaaass.net>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

18
src/lib.rs Normal file
View File

@ -0,0 +1,18 @@
pub fn reverse(s : &str) -> String {
s.chars().rev().collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_reverse() {
let query = "hello";
assert_eq!(
"olleh",
reverse(query)
);
}
}

11
src/main.rs Normal file
View File

@ -0,0 +1,11 @@
use std::env;
use ci_test::reverse;
fn main() {
// Read from argument
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
panic!("argument invalid");
}
println!("{}", reverse(&args[1]));
}