Skip to content

Commit

Permalink
Move test code to mod tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HiraokaTakuya committed Jan 5, 2024
1 parent c2dbab0 commit 0163ca6
Show file tree
Hide file tree
Showing 13 changed files with 2,483 additions and 2,414 deletions.
553 changes: 279 additions & 274 deletions src/bitboard.rs

Large diffs are not rendered by default.

131 changes: 68 additions & 63 deletions src/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ impl Book {
}
}

#[test]
fn test_book() {
std::thread::Builder::new()
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_book() {
std::thread::Builder::new()
.stack_size(crate::stack_size::STACK_SIZE)
.spawn(|| {
let sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1";
Expand Down Expand Up @@ -117,75 +121,75 @@ fn test_book() {
.unwrap()
.join()
.unwrap();
}
}

#[test]
fn test_book_probe() {
std::thread::Builder::new()
.stack_size(crate::stack_size::STACK_SIZE)
.spawn(|| {
let sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1";
let pos = Position::new_from_sfen(sfen).unwrap();
let mut b = Book::new();
b.insert(
sfen.to_string(),
Move::new_from_usi_str("2g2f", &pos).unwrap(),
Info {
value: Value(36),
win: 70,
lose: 30,
},
);
b.insert(
sfen.to_string(),
Move::new_from_usi_str("7g7f", &pos).unwrap(),
Info {
value: Value(99),
win: 30,
lose: 10,
},
);
#[test]
fn test_book_probe() {
std::thread::Builder::new()
.stack_size(crate::stack_size::STACK_SIZE)
.spawn(|| {
let sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1";
let pos = Position::new_from_sfen(sfen).unwrap();
let mut b = Book::new();
b.insert(
sfen.to_string(),
Move::new_from_usi_str("2g2f", &pos).unwrap(),
Info {
value: Value(36),
win: 70,
lose: 30,
},
);
b.insert(
sfen.to_string(),
Move::new_from_usi_str("7g7f", &pos).unwrap(),
Info {
value: Value(99),
win: 30,
lose: 10,
},
);

let mut rng = rand::thread_rng();
for i in 0.. {
assert!(i < 10000);
match b.probe(&pos, &mut rng) {
Some(mv) => {
if mv.to_usi_string() == "2g2f" {
break;
let mut rng = rand::thread_rng();
for i in 0.. {
assert!(i < 10000);
match b.probe(&pos, &mut rng) {
Some(mv) => {
if mv.to_usi_string() == "2g2f" {
break;
}
}
None => unreachable!(),
}
let mv = b.probe(&pos, &mut rng).unwrap();
if mv.to_usi_string() == "2g2f" {
break;
}
None => unreachable!(),
}
let mv = b.probe(&pos, &mut rng).unwrap();
if mv.to_usi_string() == "2g2f" {
break;
}
}
for i in 0.. {
assert!(i < 10000);
match b.probe(&pos, &mut rng) {
Some(mv) => {
if mv.to_usi_string() == "2g2f" {
break;
for i in 0.. {
assert!(i < 10000);
match b.probe(&pos, &mut rng) {
Some(mv) => {
if mv.to_usi_string() == "2g2f" {
break;
}
}
None => unreachable!(),
}
let mv = b.probe(&pos, &mut rng).unwrap();
if mv.to_usi_string() == "7g7f" {
break;
}
None => unreachable!(),
}
let mv = b.probe(&pos, &mut rng).unwrap();
if mv.to_usi_string() == "7g7f" {
break;
}
}
})
.unwrap()
.join()
.unwrap();
}
})
.unwrap()
.join()
.unwrap();
}

#[test]
fn test_book_from_file() {
std::thread::Builder::new()
#[test]
fn test_book_from_file() {
std::thread::Builder::new()
.stack_size(crate::stack_size::STACK_SIZE)
.spawn(|| {
let path = std::path::Path::new("test/book.json");
Expand All @@ -198,4 +202,5 @@ fn test_book_from_file() {
.unwrap()
.join()
.unwrap();
}
}
Loading

0 comments on commit 0163ca6

Please sign in to comment.