added iterator and tests

This commit is contained in:
aj 2020-10-10 17:00:59 +01:00
parent 6270aaee83
commit 4ff6d69534
5 changed files with 47 additions and 5 deletions

View File

@ -1,4 +0,0 @@
fn hello_world(){
}

25
src/iterate.rs Normal file
View 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
}
}
}
}

View File

@ -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();
@ -178,4 +178,14 @@ fn nullables() {
let _some_string = Some("a string"); let _some_string = Some("a string");
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
View 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
View File

@ -0,0 +1,4 @@
pub fn setup() {
println!("During test");
}