From e049b59eb3e198448a198924b2556153e6416663 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Mon, 18 Dec 2017 15:34:24 -0800 Subject: [PATCH] yep --- CONTRIBUTING.md | 7 +++++++ src/parser.rs | 2 +- tests/lib.rs | 47 +---------------------------------------------- tests/options.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/parser.rs | 0 5 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 tests/options.rs create mode 100644 tests/parser.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a1dccd..e5c5b54 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,3 +10,10 @@ We try to make use of the styleguide found [here](https://github.com/rust-lang-n ## Character Limit 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/` diff --git a/src/parser.rs b/src/parser.rs index e5e963b..803827b 100644 --- a/src/parser.rs +++ b/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 /// by the engine pub fn parse(s: &str) -> TokenResult { - + let tokens: Vec<&str> = s.split_whitespace().collect::>(); } } diff --git a/tests/lib.rs b/tests/lib.rs index 75cceeb..ccc8570 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -43,52 +43,6 @@ fn send_readyok() { } #[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() { let input = b"UNUSED"; let mut output = Vec::new(); @@ -125,3 +79,4 @@ fn send_available_engine_options() { option name Clear Hash type button\n\ uciok\n"); } + diff --git a/tests/options.rs b/tests/options.rs new file mode 100644 index 0000000..f35b73c --- /dev/null +++ b/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); +} + diff --git a/tests/parser.rs b/tests/parser.rs new file mode 100644 index 0000000..e69de29