add basic unit test
This commit is contained in:
parent
d57e41a276
commit
44eec66c54
|
@ -1,7 +1,9 @@
|
||||||
extern crate piston_window;
|
extern crate piston_window;
|
||||||
|
|
||||||
use piston_window::*;
|
use piston_window::*;
|
||||||
|
use std::f64::consts;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
struct Position {
|
struct Position {
|
||||||
x: f64,
|
x: f64,
|
||||||
y: f64,
|
y: f64,
|
||||||
|
@ -32,6 +34,10 @@ impl Engine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn closest_point(pos: Position, angle: f64) -> Position {
|
||||||
|
return Position {x: 2., y: 2.}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, context: Context, graphics: &mut G2d) {
|
pub fn render(&mut self, context: Context, graphics: &mut G2d) {
|
||||||
|
|
||||||
clear([1.0; 4], graphics);
|
clear([1.0; 4], graphics);
|
||||||
|
@ -66,3 +72,16 @@ impl Engine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn closest_point() {
|
||||||
|
let origin = super::Position { x: 2.2, y: 2.3 };
|
||||||
|
let angle = 0.;
|
||||||
|
let closest = Engine::closest_point(origin, angle);
|
||||||
|
assert_eq!(closest, super::Position { x: 3.0, y: 2.3 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue