Add test
This commit is contained in:
23
src/lib.rs
23
src/lib.rs
@@ -123,6 +123,29 @@ impl Universe {
|
||||
pub fn cells(&self) -> *const Cell {
|
||||
self.cells.as_ptr()
|
||||
}
|
||||
|
||||
pub fn set_width(&mut self, width: u32) {
|
||||
self.width = width;
|
||||
self.cells = (0..width * self.height).map(|_i| Cell::Dead).collect();
|
||||
}
|
||||
|
||||
pub fn set_height(&mut self, height: u32) {
|
||||
self.height = height;
|
||||
self.cells = (0..height * self.height).map(|_i| Cell::Dead).collect();
|
||||
}
|
||||
}
|
||||
|
||||
impl Universe {
|
||||
pub fn get_cells(&self) -> &[Cell] {
|
||||
&self.cells
|
||||
}
|
||||
|
||||
pub fn set_cells(&mut self, cells: &[(u32, u32)]) {
|
||||
for (row, col) in cells.iter().cloned() {
|
||||
let idx = self.get_index(row, col);
|
||||
self.cells[idx] = Cell::Alive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Universe {
|
||||
|
||||
Reference in New Issue
Block a user