screen tests

This commit is contained in:
2024-01-02 22:35:10 -07:00
parent 213407d89a
commit ce77465b91
2 changed files with 25 additions and 22 deletions
+25 -2
View File
@@ -22,7 +22,7 @@ impl Screen {
}
pub fn get_valid_movements(&self, pos: &Point) -> Vec<Point> {
let binding = pos.get_neighbors();
let binding = pos.get_neighbors();
binding
.iter()
.filter(|e| self.is_in_bounds(e))
@@ -31,10 +31,33 @@ impl Screen {
}
pub fn render(&self, p: &Point, char: &str) {
mvprintw(p.1 + self.center.1, p.0 + self.center.0, char);
mvprintw(p.1 + self.center.1, p.0 + self.center.0, char);
}
}
#[test]
fn test_in_bounds() {
let x = 20;
let y = 20;
let s = Screen::new(x, y);
assert!(&s.is_in_bounds(&Point(0, 0)));
assert!(!&s.is_in_bounds(&Point(21, 0)));
}
#[test]
fn test_get_valid_movements_board() {
let x = 20;
let y = 20;
let s = Screen::new(x, y);
let valid = s.get_valid_movements(&Point(0,0));
assert_eq!(valid, Point(0,0).get_neighbors());
let border = s.get_valid_movements(&Point(19,19));
assert!(border.len() == 2);
}
pub enum BoardCommand {
Dig(Point),
LayEgg(Point, u32),
-20
View File
@@ -29,24 +29,6 @@ fn render(e: &Entities, w: &World, b: &Screen) {
}
}
#[cfg(test)]
mod tests {
// TODO: tests, cleanup code in general
use super::*;
#[test]
fn board() {
let max_x = 20;
let max_y = 20;
let mut board = Screen::new(max_x, max_y);
let mut world = World::new();
dbg!(board.is_in_bounds(&Point(0, 0)));
dbg!(board.get_valid_movements(&Point(0, 0)));
}
}
fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) {
let cmds: Vec<BoardCommand> = e
.data
@@ -90,8 +72,6 @@ fn main() {
getmaxyx(stdscr(), &mut max_y, &mut max_x);
// TODO: fix renderable to render different colors
let mut board = Screen::new(max_x, max_y);
let mut world = World::new();