diff options
Diffstat (limited to 'challenge-272/roger-bell-west/rust/ch-1.rs')
| -rwxr-xr-x | challenge-272/roger-bell-west/rust/ch-1.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-272/roger-bell-west/rust/ch-1.rs b/challenge-272/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..ef13992b11 --- /dev/null +++ b/challenge-272/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,24 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit + +#[test] +fn test_ex1() { + assert_eq!(defrangip("1.1.1.1"), "1[.]1[.]1[.]1"); +} + +#[test] +fn test_ex2() { + assert_eq!(defrangip("255.101.1.0"), "255[.]101[.]1[.]0"); +} + +fn defrangip(a: &str) -> String { + let mut out = String::new(); + for c in a.chars() { + if c == '.' { + out.push_str("[.]"); + } else { + out.push(c); + } + } + out +} |
