1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-19 10:20:08 +01:00
Dieser Commit ist enthalten in:
Chaoscaot 2023-04-24 22:52:03 +02:00
Ursprung eb84adb4a3
Commit a357da2ce8

Datei anzeigen

@ -136,19 +136,12 @@ pub fn normalize_data(data: &str, ignore_data: bool) -> &str {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use schemsearch_files::SchematicVersioned::V2;
use schemsearch_files::SpongeV2Schematic;
use crate::pattern_mapper::strip_data; use crate::pattern_mapper::strip_data;
use super::*; use super::*;
#[test] #[test]
fn read_schematic() { fn read_schematic() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let schematic = match schematic {
V2 (schematic) => schematic,
_ => panic!("Invalid schematic version"),
};
assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len()); assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len());
assert_eq!(schematic.palette_max, schematic.palette.len() as i32); assert_eq!(schematic.palette_max, schematic.palette.len() as i32);
@ -156,12 +149,7 @@ mod tests {
#[test] #[test]
fn test_parse_function() { fn test_parse_function() {
let schematic: SchematicVersioned = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let schematic = match schematic {
V2 (schematic) => schematic,
_ => panic!("Invalid schematic version"),
};
assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len()); assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len());
assert_eq!(schematic.palette_max, schematic.palette.len() as i32); assert_eq!(schematic.palette_max, schematic.palette.len() as i32);
@ -169,32 +157,32 @@ mod tests {
#[test] #[test]
fn test_strip_schem() { fn test_strip_schem() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let stripped = strip_data(&schematic); let stripped = strip_data(&schematic);
assert_eq!(stripped.get_palette().keys().any(|k| k.contains('[')), false); assert_eq!(stripped.palette.keys().any(|k| k.contains('[')), false);
} }
#[test] #[test]
fn test_match_palette() { fn test_match_palette() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = SchematicVersioned::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let endstone = SpongeSchematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = match_palette(&schematic, &endstone, true); let _ = match_palette(&schematic, &endstone, true);
} }
#[test] #[test]
fn test_match_palette_ignore_data() { fn test_match_palette_ignore_data() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = SchematicVersioned::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let endstone = SpongeSchematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = match_palette(&schematic, &endstone, false); let _ = match_palette(&schematic, &endstone, false);
} }
#[test] #[test]
pub fn test_big_search() { pub fn test_big_search() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = SchematicVersioned::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let endstone = SpongeSchematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = search(schematic, &endstone, SearchBehavior { let _ = search(schematic, &endstone, SearchBehavior {
ignore_block_data: true, ignore_block_data: true,
@ -208,8 +196,8 @@ mod tests {
#[test] #[test]
pub fn test_search() { pub fn test_search() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/Random.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/Random.schem")).unwrap();
let pattern = SchematicVersioned::load(&PathBuf::from("../tests/Pattern.schem")).unwrap(); let pattern = SpongeSchematic::load(&PathBuf::from("../tests/Pattern.schem")).unwrap();
let matches = search(schematic, &pattern, SearchBehavior { let matches = search(schematic, &pattern, SearchBehavior {
ignore_block_data: true, ignore_block_data: true,
@ -230,8 +218,8 @@ mod tests {
#[test] #[test]
pub fn test_search_ws() { pub fn test_search_ws() {
let schematic = SchematicVersioned::load(&PathBuf::from("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap(); let schematic = SpongeSchematic::load(&PathBuf::from("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap();
let pattern = SchematicVersioned::load(&PathBuf::from("../tests/gray_castle_complex.schem")).unwrap(); let pattern = SpongeSchematic::load(&PathBuf::from("../tests/gray_castle_complex.schem")).unwrap();
let matches = search(schematic, &pattern, SearchBehavior { let matches = search(schematic, &pattern, SearchBehavior {
ignore_block_data: false, ignore_block_data: false,