Created
May 29, 2020 21:15
-
-
Save eloraiby/fdfc477a6ae986ac44a64b10980da7e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
} | |
#[cfg(test)] | |
mod tests { | |
#[test] | |
fn test_for() { | |
let mut v = Vec::new(); | |
for i in 0..10 { | |
v.push(i); | |
} | |
for i in 0..v.len() { | |
if i < 100 { | |
v.push(i); | |
} | |
} | |
assert!(v.len() == 110); // count is 20 | |
} | |
#[test] | |
fn test_loop() { | |
let mut v = Vec::new(); | |
for i in 0..10 { | |
v.push(i); | |
} | |
let mut i = 0; | |
loop { | |
if i >= v.len() { | |
break; | |
} | |
if i < 100 { | |
v.push(i); | |
} | |
i += 1; | |
} | |
assert!(v.len() == 110); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment