Skip to content

Instantly share code, notes, and snippets.

@eloraiby
Created May 29, 2020 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eloraiby/fdfc477a6ae986ac44a64b10980da7e6 to your computer and use it in GitHub Desktop.
Save eloraiby/fdfc477a6ae986ac44a64b10980da7e6 to your computer and use it in GitHub Desktop.
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