mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Add tests for runner
This commit is contained in:
parent
f860e190f6
commit
1dcc712983
@ -3,6 +3,9 @@ use crate::sampler::{Sample, Sampler};
|
|||||||
use crate::surface::Surface;
|
use crate::surface::Surface;
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
|
use mockall::automock;
|
||||||
|
|
||||||
|
#[automock]
|
||||||
pub trait Renderer {
|
pub trait Renderer {
|
||||||
fn render(&mut self, step: f32);
|
fn render(&mut self, step: f32);
|
||||||
fn present(&mut self) -> Result<(), Error>;
|
fn present(&mut self) -> Result<(), Error>;
|
||||||
|
@ -19,7 +19,7 @@ impl<T1: Timer, T2: Renderer> Runner<T1, T2> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(mut self) -> Result<(), Error> {
|
pub fn run(mut self) -> Result<(), Error> {
|
||||||
for i in 0..self.ticks {
|
for i in 0..=self.ticks {
|
||||||
let step = i as f32 / self.ticks as f32;
|
let step = i as f32 / self.ticks as f32;
|
||||||
|
|
||||||
self.renderer.render(step);
|
self.renderer.render(step);
|
||||||
@ -28,4 +28,41 @@ impl<T1: Timer, T2: Renderer> Runner<T1, T2> {
|
|||||||
}
|
}
|
||||||
self.renderer.finish()
|
self.renderer.finish()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use std::time::Duration;
|
||||||
|
use mockall::predicate::*;
|
||||||
|
use mockall::Sequence;
|
||||||
|
use crate::timer::MockTimer;
|
||||||
|
use crate::render::MockRenderer;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run() {
|
||||||
|
let mut timer = MockTimer::new();
|
||||||
|
let mut renderer = MockRenderer::new();
|
||||||
|
let seq = &mut Sequence::new();
|
||||||
|
|
||||||
|
timer.expect_delay().return_const(Duration::from_secs(2));
|
||||||
|
|
||||||
|
renderer.expect_render().once().with(eq(0.0)).in_sequence(seq).return_const(());
|
||||||
|
renderer.expect_present().once().in_sequence(seq).returning(|| Ok(()));
|
||||||
|
timer.expect_sleep().once().in_sequence(seq).return_const(());
|
||||||
|
|
||||||
|
renderer.expect_render().once().with(eq(0.5)).in_sequence(seq).return_const(());
|
||||||
|
renderer.expect_present().once().in_sequence(seq).returning(|| Ok(()));
|
||||||
|
timer.expect_sleep().once().in_sequence(seq).return_const(());
|
||||||
|
|
||||||
|
renderer.expect_render().once().with(eq(1.0)).in_sequence(seq).return_const(());
|
||||||
|
renderer.expect_present().once().in_sequence(seq).returning(|| Ok(()));
|
||||||
|
timer.expect_sleep().once().in_sequence(seq).return_const(());
|
||||||
|
|
||||||
|
renderer.expect_finish().once().in_sequence(seq).returning(|| Ok(()));
|
||||||
|
|
||||||
|
let runner = Runner::new(Duration::from_secs(4), timer, renderer);
|
||||||
|
|
||||||
|
runner.run().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user