use crate::WADFile;

use std::sync::OnceLock;

static WAD_INSTANCE: OnceLock<WADFile> = OnceLock::new();

/// Helper function to access the WAD file once
fn get_wad() -> &'static WADFile {
    WAD_INSTANCE.get_or_init(|| WADFile::new(String::from("WADs/doom1.wad")))
}

#[test]
pub fn successful_wad_id() {
    let wad_file = get_wad();

    assert_eq!(wad_file.wad_id, "IWAD");
}

#[test]
pub fn correct_lumps() {
    let wad_file = get_wad();

    assert_eq!(wad_file.num_lumps, 1264);
}

#[test]
pub fn correct_dir_size() {
    let wad_file = get_wad();

    assert_eq!(wad_file.directory.len(), 1264);
}

#[test]
pub fn correct_lump_name() {
    let wad_file = get_wad();

    assert_eq!(wad_file.directory[0].name, "PLAYPAL");
}

#[test]
pub fn read_level_lump() {
    let wad_file = get_wad();

    assert_eq!(wad_file.directory[6].name, "E1M1");
}

#[test]
pub fn read_vertex_lump() {
    let wad_file = get_wad();

    let vertex_lump = wad_file.get_vertex_lump(wad_file.directory[10].to_owned());

    assert_ne!(vertex_lump.vertexes.len(), 0);
}

#[test]
pub fn read_num_vertexes() {
    let wad_file = get_wad();

    let vertex_lump = wad_file.get_vertex_lump(wad_file.directory[10].to_owned());

    assert_eq!(vertex_lump.vertexes.len(), 1868 / 4);
}

#[test]
pub fn read_first_vertex() {
    use crate::types::Vertex;

    let wad_file = get_wad();

    let vertex_lump = wad_file.get_vertex_lump(wad_file.directory[10].to_owned());

    let correct_vertex = Vertex { x: 1088, y: -3680 };

    assert_eq!(vertex_lump.get_vertex(0), correct_vertex);
}
