1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use rand::Rng;
use {Space, Card, Surjection};
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct EmptySpace;
impl Space for EmptySpace {
type Value = ();
fn dim(&self) -> usize { 0 }
fn card(&self) -> Card { Card::Null }
fn sample<R: Rng + ?Sized>(&self, _: &mut R) -> () { () }
}
impl<T> Surjection<T, ()> for EmptySpace {
fn map(&self, _: T) -> () { () }
}
#[cfg(test)]
mod tests {
extern crate serde_test;
use self::serde_test::{assert_tokens, Token};
use rand::thread_rng;
use {EmptySpace, Space, Card, Surjection};
#[test]
fn test_copy() {
let s = EmptySpace;
assert_eq!(s, s);
}
#[test]
fn test_dim() {
assert_eq!(EmptySpace.dim(), 0);
}
#[test]
fn test_card() {
assert_eq!(EmptySpace.card(), Card::Null);
}
#[test]
fn test_sample() {
let mut rng = thread_rng();
assert_eq!(EmptySpace.sample(&mut rng), ());
}
#[test]
fn test_surjection() {
assert_eq!(EmptySpace.map(1), ());
assert_eq!(EmptySpace.map(1.0), ());
assert_eq!(EmptySpace.map("test"), ());
assert_eq!(EmptySpace.map(Some(true)), ());
}
#[test]
fn test_serialisation() {
let d = EmptySpace;
assert_tokens(&d, &[Token::UnitStruct { name: "EmptySpace" }]);
}
}