An implementation of the Universal Chess Interface in Rust.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.8 KiB

extern crate uci;
use uci::Engine;
7 years ago
use uci::options::constants;
use uci::options::{ EngineOption, EngineOptionType, EngineOptionDataType, EngineOptionData };
use std::str;
#[test]
fn instantiate_new_engine() {
7 years ago
let input = b"UNUSED";
let mut output = Vec::new();
7 years ago
let e = Engine::new("test_name", "test", &input[..], &mut output, vec!());
assert_eq!(e.name, "test_name");
assert_eq!(e.author, "test");
}
7 years ago
#[test]
fn send_identification_data() {
7 years ago
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
{
7 years ago
let mut e = Engine::new("test_name", "test", &input[..], &mut output, vec!());
7 years ago
e.identify();
}
assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_identification_data"),
"id name test_name\nid author test\n");
7 years ago
}
#[test]
fn send_readyok() {
let input = b"UNUSED";
let mut output = Vec::new();
{
7 years ago
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");
}
7 years ago
#[test]
fn engine_option_equality() {
let name = constants::HASH;
let option_type = EngineOptionType::Spin;
let option_data1 =
7 years ago
[(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,
};
7 years ago
let o2 = EngineOption {
name: name,
option_type: option_type,
option_data: option_data2,
};
7 years ago
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, option_type, option_data, };
let expected = "option name Hash type spin default 1 min 1 max 128\n";
assert_eq!(o.to_string(), expected);
}
#[test]
fn send_available_engine_options() {
let input = b"UNUSED";
let mut output = Vec::new();
let o1 = EngineOption {
name: constants::HASH,
option_type: EngineOptionType::Spin,
option_data: [(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
(EngineOptionDataType::Min, EngineOptionData::Int(1)),
(EngineOptionDataType::Max, EngineOptionData::Int(128))
].iter().cloned().collect(),
};
let o2 = EngineOption {
name: constants::NALIMOVPATH,
option_type: EngineOptionType::TypeString,
option_data: [(EngineOptionDataType::DefaultVal, EngineOptionData::Text(String::from(r"c:\"))),
].iter().cloned().collect(),
};
let o3 = EngineOption {
name: "Clear Hash",
option_type: EngineOptionType::Button,
option_data: [].iter().cloned().collect(),
};
{
let mut e = Engine::new("test_name", "test", &input[..], &mut output, vec!(o1, o2, o3));
e.send_available_options();
}
assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_identification_data"),
"option name Hash type spin default 1 min 1 max 128\n\
7 years ago
option name NalimovPath type string default c:\\\n\
option name Clear Hash type button\n\
uciok\n");
}