-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf.rs
75 lines (66 loc) · 1.94 KB
/
elf.rs
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
69
70
71
72
73
74
75
pub mod elf {
#[cfg(test)]
use proptest_derive::Arbitrary;
#[repr(u32)]
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, Hash, Eq)]
#[cfg_attr(test, derive(Arbitrary))]
pub enum Race {
Dark = 1,
High = 2,
}
#[repr(u32)]
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, Hash, Eq)]
#[cfg_attr(test, derive(Arbitrary))]
pub enum Role {
Swordsman = 1,
Archer = 2,
Priest = 5,
Warlock = 4,
}
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, Hash, Eq)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Elf {
race: Race,
role: Role,
}
impl Elf {
pub fn new(role: Role, race: Race) -> Self {
Elf { race, role }
}
pub fn value(&self) -> u32 {
*&self.race as u32 * *&self.role as u32
}
}
#[cfg(test)]
mod unit_tests {
use super::*;
#[test]
fn two_warlock_dark_elves_should_be_equal() {
let doomshadow = Elf::new(Role::Warlock, Race::Dark);
let thundershade = Elf::new(Role::Warlock, Race::Dark);
assert_eq!(doomshadow, thundershade);
}
#[test]
fn archer_dark_and_swordsman_high_values_should_be_equal() {
let faeor = Elf::new(Role::Archer, Race::Dark).value();
let shadowblight = Elf::new(Role::Swordsman, Race::High).value();
assert_eq!(faeor, shadowblight);
}
}
#[cfg(test)]
mod property_tests {
use super::*;
use proptest::prelude::*;
proptest! {
#[test]
fn elf_value_should_be_positive(elf : Elf) {
assert!(elf.value() > 0);
}
// #[test]
// fn high_elf_value_should_be_even(role : Role) {
// let elf = Elf::new(role, Race::High);
// assert_eq!(elf.value() % 2, 0);
// }
}
}
}