test configurations

This commit is contained in:
2020-04-19 08:13:55 +01:00
parent d0614b6de2
commit 76e6c2477c
15 changed files with 515 additions and 451 deletions

View File

@@ -300,140 +300,146 @@ impl Game {
}
}
#[test]
fn test_game_from_string() {
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap();
#[cfg(test)]
mod test {
use crate::game::{Version, Game};
use crate::text::{TextDirection, Font};
use crate::tile::Tile;
let expected = crate::mock::game_default();
#[test]
fn test_game_from_string() {
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap();
let expected = crate::mock::game_default();
assert_eq!(output, expected);
}
assert_eq!(output, expected);
}
#[test]
fn test_game_to_string() {
let output = crate::mock::game_default().to_string();
let expected = include_str!["test-resources/default.bitsy"].to_string();
assert_eq!(output, expected);
}
#[test]
fn test_game_to_string() {
let output = crate::mock::game_default().to_string();
let expected = include_str!["test-resources/default.bitsy"].to_string();
assert_eq!(output, expected);
}
#[test]
fn test_tile_ids() {
assert_eq!(crate::mock::game_default().tile_ids(), vec![10]);
}
#[test]
fn test_tile_ids() {
assert_eq!(crate::mock::game_default().tile_ids(), vec![10]);
}
#[test]
fn test_new_tile_id() {
// default tile has an id of 10 ("a"), so 0 is available
assert_eq!(crate::mock::game_default().new_tile_id(), 0);
#[test]
fn test_new_tile_id() {
// default tile has an id of 10 ("a"), so 0 is available
assert_eq!(crate::mock::game_default().new_tile_id(), 0);
let mut game = crate::mock::game_default();
let mut tiles: Vec<Tile> = Vec::new();
let mut game = crate::mock::game_default();
let mut tiles: Vec<Tile> = Vec::new();
for n in 0..9 {
if n != 4 {
let mut new_tile = crate::mock::tile_default();
new_tile.id = n;
tiles.push(new_tile);
for n in 0..9 {
if n != 4 {
let mut new_tile = crate::mock::tile_default();
new_tile.id = n;
tiles.push(new_tile);
}
}
game.tiles = tiles;
assert_eq!(game.new_tile_id(), 4);
// fill in the space created above, and test that tile IDs get sorted
let mut new_tile = crate::mock::tile_default();
new_tile.id = 4;
game.tiles.push(new_tile);
assert_eq!(game.new_tile_id(), 10);
}
#[test]
fn test_add_tile() {
let mut game = crate::mock::game_default();
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 0);
assert_eq!(game.tiles.len(), 2);
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 1);
assert_eq!(game.tiles.len(), 3);
}
#[test]
fn test_bitsy_omnibus() {
let acceptable_failures: Vec<String> = vec![
// fails because of sprite colours but also because a tile contains "NaN"
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
// SET instead of ROOM? todo investigate
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
// not sure about this one but it uses room wall array
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
// bad game data
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
// this one has font data appended to the end of the game data - is this valid?
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
// has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
// extra line between dialogues
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
// something going on with dialogues? todo investigate
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
];
let mut passes = 0;
let mut skips = 0;
let files = std::fs::read_dir("src/test-resources/omnibus");
if !files.is_ok() {
return;
}
for file in files.unwrap() {
let path = file.unwrap().path();
let nice_name = format!("{}", path.display());
if !nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) {
skips += 1;
// println!("Skipping: {}", nice_name);
println!("Skipped. {} passes, {} skips.", passes, skips);
continue;
}
println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone()).unwrap();
assert_eq!(
game.to_string().trim_matches('\n'),
game_data.trim_matches('\n')
);
passes += 1;
println!("Success! {} passes, {} skips.", passes, skips);
}
}
game.tiles = tiles;
#[test]
fn test_arabic() {
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
assert_eq!(game.new_tile_id(), 4);
// fill in the space created above, and test that tile IDs get sorted
let mut new_tile = crate::mock::tile_default();
new_tile.id = 4;
game.tiles.push(new_tile);
assert_eq!(game.new_tile_id(), 10);
}
#[test]
fn test_add_tile() {
let mut game = crate::mock::game_default();
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 0);
assert_eq!(game.tiles.len(), 2);
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 1);
assert_eq!(game.tiles.len(), 3);
}
#[test]
fn test_bitsy_omnibus() {
let acceptable_failures: Vec<String> = vec![
// fails because of sprite colours but also because a tile contains "NaN"
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
// SET instead of ROOM? todo investigate
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
// not sure about this one but it uses room wall array
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
// bad game data
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
// this one has font data appended to the end of the game data - is this valid?
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
// has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
// extra line between dialogues
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
// something going on with dialogues? todo investigate
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
];
let mut passes = 0;
let mut skips = 0;
let files = std::fs::read_dir("src/test-resources/omnibus");
if !files.is_ok() {
return;
assert_eq!(game.font, Font::Arabic);
assert_eq!(game.text_direction, TextDirection::RightToLeft);
}
for file in files.unwrap() {
let path = file.unwrap().path();
let nice_name = format!("{}", path.display());
if !nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) {
skips += 1;
// println!("Skipping: {}", nice_name);
println!("Skipped. {} passes, {} skips.", passes, skips);
continue;
}
println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone()).unwrap();
assert_eq!(
game.to_string().trim_matches('\n'),
game_data.trim_matches('\n')
);
passes += 1;
println!("Success! {} passes, {} skips.", passes, skips);
#[test]
fn test_version_formatting() {
let mut game = crate::mock::game_default();
game.version = Version { major: 5, minor: 0 };
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
}
}
#[test]
fn test_arabic() {
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
assert_eq!(game.font, Font::Arabic);
assert_eq!(game.text_direction, TextDirection::RightToLeft);
}
#[test]
fn test_version_formatting() {
let mut game = crate::mock::game_default();
game.version = Version { major: 5, minor: 0 };
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
}