2 arbitrary::{any, any_with, Arbitrary, StrategyFor}, |
2 arbitrary::{any, any_with, Arbitrary, StrategyFor}, |
3 strategy::{BoxedStrategy, Just, Map, Strategy}, |
3 strategy::{BoxedStrategy, Just, Map, Strategy}, |
4 test_runner::{Reason, TestRunner}, |
4 test_runner::{Reason, TestRunner}, |
5 }; |
5 }; |
6 |
6 |
7 use crate::core::types::{GameCfg, HedgehogInfo, ServerVar, ServerVar::*, TeamInfo}; |
7 use crate::core::types::{GameCfg, HedgehogInfo, ServerVar, ServerVar::*, TeamInfo, VoteType}; |
8 |
8 |
9 use super::messages::{HwProtocolMessage, HwProtocolMessage::*}; |
9 use super::messages::{HwProtocolMessage, HwProtocolMessage::*}; |
10 |
10 |
11 // Due to inability to define From between Options |
11 // Due to inability to define From between Options |
12 trait Into2<T>: Sized { |
12 trait Into2<T>: Sized { |
162 }) |
162 }) |
163 .boxed() |
163 .boxed() |
164 } |
164 } |
165 |
165 |
166 type Strategy = BoxedStrategy<ServerVar>; |
166 type Strategy = BoxedStrategy<ServerVar>; |
|
167 } |
|
168 |
|
169 impl Arbitrary for VoteType { |
|
170 type Parameters = (); |
|
171 |
|
172 fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { |
|
173 use VoteType::*; |
|
174 (0..=4) |
|
175 .no_shrink() |
|
176 .prop_flat_map(|i| { |
|
177 proto_msg_match!(i, def = VoteType::Pause, |
|
178 0 => Kick(Ascii), |
|
179 1 => Map(Option<Ascii>), |
|
180 2 => Pause(), |
|
181 3 => NewSeed(), |
|
182 4 => HedgehogsPerTeam(u8) |
|
183 ) |
|
184 }) |
|
185 .boxed() |
|
186 } |
|
187 |
|
188 type Strategy = BoxedStrategy<VoteType>; |
167 } |
189 } |
168 |
190 |
169 pub fn gen_proto_msg() -> BoxedStrategy<HwProtocolMessage> where { |
191 pub fn gen_proto_msg() -> BoxedStrategy<HwProtocolMessage> where { |
170 let res = (0..=55).no_shrink().prop_flat_map(|i| { |
192 let res = (0..=55).no_shrink().prop_flat_map(|i| { |
171 proto_msg_match!(i, def = Ping, |
193 proto_msg_match!(i, def = Ping, |
215 44 => TeamChat(Ascii), |
237 44 => TeamChat(Ascii), |
216 45 => MaxTeams(u8), |
238 45 => MaxTeams(u8), |
217 46 => Fix(), |
239 46 => Fix(), |
218 47 => Unfix(), |
240 47 => Unfix(), |
219 48 => Greeting(Option<Ascii>), |
241 48 => Greeting(Option<Ascii>), |
220 //49 => CallVote(Option<(String, Option<String>)>), |
242 49 => CallVote(Option<VoteType>), |
221 50 => Vote(bool), |
243 50 => Vote(bool), |
222 51 => ForceVote(bool), |
244 51 => ForceVote(bool), |
223 52 => Save(Ascii, Ascii), |
245 52 => Save(Ascii, Ascii), |
224 53 => Delete(Ascii), |
246 53 => Delete(Ascii), |
225 54 => SaveRoom(Ascii), |
247 54 => SaveRoom(Ascii), |