|
|
|
extern crate uci;
|
|
|
|
|
|
|
|
use uci::Engine;
|
|
|
|
use uci::options::constants;
|
|
|
|
use uci::options::{ EngineOption, EngineOptionType, EngineOptionDataType, EngineOptionData };
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn instantiate_new_engine() {
|
|
|
|
let input = b"UNUSED";
|
|
|
|
let mut output = Vec::new();
|
|
|
|
|
|
|
|
let e = Engine::new("test_name", "test", &input[..], &mut output, vec!());
|
|
|
|
assert_eq!(e.name, "test_name");
|
|
|
|
assert_eq!(e.author, "test");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn send_identification_data() {
|
|
|
|
let input = b"UNUSED";
|
|
|
|
let mut output = Vec::new();
|
|
|
|
|
|
|
|
// We need to scope this so that the mutable borrow ends and we can test it safely
|
|
|
|
{
|
|
|
|
let mut e = Engine::new("test_name", "test", &input[..], &mut output, vec!());
|
|
|
|
e.identify();
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: This looks weird bceause you'd think it would store each insertion into the output buffer
|
|
|
|
// as a separate element of that buffer, but it really just appends the two strings since in reality
|
|
|
|
// the buffer would be flushed after reading.
|
|
|
|
assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_identification_data"),
|
|
|
|
"id name test_name\nid author test\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn send_readyok() {
|
|
|
|
let input = b"UNUSED";
|
|
|
|
let mut output = Vec::new();
|
|
|
|
{
|
|
|
|
let mut e = Engine::new("test_name", "test", &input[..], &mut output, vec!());
|
|
|
|
e.ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_readyok"),
|
|
|
|
"readyok\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn engine_option_equality() {
|
|
|
|
let name = constants::HASH;
|
|
|
|
let option_type = EngineOptionType::Spin;
|
|
|
|
let option_data1 =
|
|
|
|
[(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Min, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Max, EngineOptionData::Int(128))
|
|
|
|
].iter().cloned().collect();
|
|
|
|
let option_data2 =
|
|
|
|
[(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Min, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Max, EngineOptionData::Int(128))
|
|
|
|
].iter().cloned().collect();
|
|
|
|
|
|
|
|
let o1 = EngineOption {
|
|
|
|
name: name,
|
|
|
|
option_type: option_type,
|
|
|
|
option_data: option_data1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let o2 = EngineOption {
|
|
|
|
name: name,
|
|
|
|
option_type: option_type,
|
|
|
|
option_data: option_data2,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(o1, o2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn engine_option_string() {
|
|
|
|
let name = constants::HASH;
|
|
|
|
let option_type = EngineOptionType::Spin;
|
|
|
|
let option_data =
|
|
|
|
[(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Min, EngineOptionData::Int(1)),
|
|
|
|
(EngineOptionDataType::Max, EngineOptionData::Int(128))
|
|
|
|
].iter().cloned().collect();
|
|
|
|
|
|
|
|
let o = EngineOption {
|
|
|
|
name: name,
|
|
|
|
option_type: option_type,
|
|
|
|
option_data: option_data1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = "option name hash type spin default 1 min 1 max 128\n";
|
|
|
|
assert_eq!(o.option_string(), expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn send_available_engine_options() {
|
|
|
|
// This should send two to three options and check the string in the
|
|
|
|
// buffer to make sure it's correct.
|
|
|
|
assert_eq!(true, false);
|
|
|
|
}
|