use kdam::tqdm; #[path = "../src/chess.rs"] mod chess; #[path = "../src/shared/util.rs"] mod util; use util::{ read_pgn_file, PGN }; #[cfg(test)] mod tests { use std::thread; use super::*; fn test_pgn(path: &str, pos: usize) { let pgn = read_pgn_file(path); let pgn = PGN::parse_pgn(&pgn); println!("pgn: {:?}", pgn.len()); for (i, g) in tqdm!(pgn.iter().enumerate(), position = pos as u16) { let mut chess = chess::Chess::new(); for m in g.moves.iter() { assert!(chess.m_from_san(m), "Invalid move: {}, {}\n{}", m, i, g.move_origin); } } } #[test] fn test_all_pgn() { let data = vec!["data/Nakamura.pgn", "data/Carlsen.pgn"]; let mut threads = vec![]; for (i, t) in data.into_iter().enumerate() { threads.push( thread::spawn(move || { test_pgn(t, i); }) ); } for t in threads { t.join().unwrap(); } println!("All pgn tests passed"); } }