added iterator and tests
This commit is contained in:
parent
6270aaee83
commit
4ff6d69534
@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
fn hello_world(){
|
|
||||||
|
|
||||||
}
|
|
25
src/iterate.rs
Normal file
25
src/iterate.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
mod iterate {
|
||||||
|
struct Counter {
|
||||||
|
count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Counter {
|
||||||
|
fn new() -> Counter {
|
||||||
|
Counter { count: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for Counter {
|
||||||
|
type Item = u32;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.count < 5 {
|
||||||
|
self.count += 1;
|
||||||
|
Some(self.count)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/main.rs
12
src/main.rs
@ -2,7 +2,7 @@ use std::io;
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
mod collections;
|
mod iterate;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
basics();
|
basics();
|
||||||
@ -179,3 +179,13 @@ fn nullables() {
|
|||||||
|
|
||||||
let _absent_number: Option<i32> = None;
|
let _absent_number: Option<i32> = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test1() {
|
||||||
|
assert_eq!(2, 1 + 1);
|
||||||
|
}
|
||||||
|
}
|
7
tests/add_tests.rs
Normal file
7
tests/add_tests.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
mod scaffold;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_test_1() {
|
||||||
|
scaffold::setup();
|
||||||
|
assert_eq!(4, 2 + 2);
|
||||||
|
}
|
4
tests/scaffold/mod.rs
Normal file
4
tests/scaffold/mod.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
pub fn setup() {
|
||||||
|
println!("During test");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user