write tests
This commit is contained in:
parent
b9298c9c5e
commit
ab37033267
1 changed files with 28 additions and 0 deletions
28
tests/web.rs
28
tests/web.rs
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#![cfg(target_arch = "wasm32")]
|
#![cfg(target_arch = "wasm32")]
|
||||||
|
|
||||||
|
extern crate wasm_game_of_life;
|
||||||
extern crate wasm_bindgen_test;
|
extern crate wasm_bindgen_test;
|
||||||
|
use wasm_game_of_life::Universe;
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
wasm_bindgen_test_configure!(run_in_browser);
|
wasm_bindgen_test_configure!(run_in_browser);
|
||||||
|
@ -11,3 +13,29 @@ wasm_bindgen_test_configure!(run_in_browser);
|
||||||
fn pass() {
|
fn pass() {
|
||||||
assert_eq!(1 + 1, 2);
|
assert_eq!(1 + 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn input_spaceship() -> Universe {
|
||||||
|
let mut universe = Universe::new();
|
||||||
|
universe.set_width(6);
|
||||||
|
universe.set_height(6);
|
||||||
|
universe.set_cells(&[(1,2), (2,3), (3,1), (3,2), (3,3)]);
|
||||||
|
universe
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn expected_spaceship() -> Universe {
|
||||||
|
let mut universe = Universe::new();
|
||||||
|
universe.set_width(6);
|
||||||
|
universe.set_height(6);
|
||||||
|
universe.set_cells(&[(2,1), (2,3), (3,2), (3,3), (4,2)]);
|
||||||
|
universe
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
pub fn test_tick() {
|
||||||
|
let mut input_universe = input_spaceship();
|
||||||
|
let expected_universe = expected_spaceship();
|
||||||
|
input_universe.tick();
|
||||||
|
assert_eq!(&input_universe.get_cells(), &expected_universe.get_cells());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue