wasm-game-of-life/tests/web.rs

42 lines
1,016 B
Rust
Raw Permalink Normal View History

2021-05-10 23:47:13 +02:00
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
2021-05-15 21:48:49 +02:00
extern crate wasm_game_of_life;
2021-05-10 23:47:13 +02:00
extern crate wasm_bindgen_test;
2021-05-15 21:48:49 +02:00
use wasm_game_of_life::Universe;
2021-05-10 23:47:13 +02:00
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}
2021-05-15 21:48:49 +02:00
#[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());
}