Taylor Bockman 7 years ago
parent
commit
e049b59eb3
  1. 7
      CONTRIBUTING.md
  2. 2
      src/parser.rs
  3. 47
      tests/lib.rs
  4. 52
      tests/options.rs
  5. 0
      tests/parser.rs

7
CONTRIBUTING.md

@ -10,3 +10,10 @@ We try to make use of the styleguide found [here](https://github.com/rust-lang-n
## Character Limit ## Character Limit
We try to make each line less than or equal to 120 charcters. We try to make each line less than or equal to 120 charcters.
## Testing
Prefer seperating out your tests into discrete modules where possible. In general:
1. Engine "global" tests go into `tests/lib.rs`
2. Everything else gets it's own module inside `tests/`

2
src/parser.rs

@ -54,7 +54,7 @@ impl Parser {
/// Parses a single string from the GUI and turns it into a neatly packaged TokenResult for processing /// Parses a single string from the GUI and turns it into a neatly packaged TokenResult for processing
/// by the engine /// by the engine
pub fn parse(s: &str) -> TokenResult { pub fn parse(s: &str) -> TokenResult {
let tokens: Vec<&str> = s.split_whitespace().collect::<Vec<&str>>();
} }
} }

47
tests/lib.rs

@ -43,52 +43,6 @@ fn send_readyok() {
} }
#[test] #[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, 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() { fn send_available_engine_options() {
let input = b"UNUSED"; let input = b"UNUSED";
let mut output = Vec::new(); let mut output = Vec::new();
@ -125,3 +79,4 @@ fn send_available_engine_options() {
option name Clear Hash type button\n\ option name Clear Hash type button\n\
uciok\n"); uciok\n");
} }

52
tests/options.rs

@ -0,0 +1,52 @@
extern crate uci;
use uci::Engine;
use uci::options::constants;
use uci::options::{ EngineOption, EngineOptionType, EngineOptionDataType, EngineOptionData };
#[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, option_type, option_data, };
let expected = "option name Hash type spin default 1 min 1 max 128\n";
assert_eq!(o.to_string(), expected);
}

0
tests/parser.rs

Loading…
Cancel
Save