|
|
@ -9,13 +9,13 @@ enum Message {
|
|
|
|
|
|
|
|
|
|
|
|
struct Point {
|
|
|
|
struct Point {
|
|
|
|
x: u8,
|
|
|
|
x: u8,
|
|
|
|
y: u8
|
|
|
|
y: u8,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
struct State {
|
|
|
|
color: (u8, u8, u8),
|
|
|
|
color: (u8, u8, u8),
|
|
|
|
position: Point,
|
|
|
|
position: Point,
|
|
|
|
quit: bool
|
|
|
|
quit: bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl State {
|
|
|
|
impl State {
|
|
|
@ -46,14 +46,14 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_match_message_call() {
|
|
|
|
fn test_match_message_call() {
|
|
|
|
let mut state = State{
|
|
|
|
let mut state = State {
|
|
|
|
quit: false,
|
|
|
|
quit: false,
|
|
|
|
position: Point{ x: 0, y: 0 },
|
|
|
|
position: Point { x: 0, y: 0 },
|
|
|
|
color: (0, 0, 0)
|
|
|
|
color: (0, 0, 0),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
state.process(Message::ChangeColor((255, 0, 255)));
|
|
|
|
state.process(Message::ChangeColor((255, 0, 255)));
|
|
|
|
state.process(Message::Echo(String::from("hello world")));
|
|
|
|
state.process(Message::Echo(String::from("hello world")));
|
|
|
|
state.process(Message::Move(Point{ x: 10, y: 15 }));
|
|
|
|
state.process(Message::Move(Point { x: 10, y: 15 }));
|
|
|
|
state.process(Message::Quit);
|
|
|
|
state.process(Message::Quit);
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(state.color, (255, 0, 255));
|
|
|
|
assert_eq!(state.color, (255, 0, 255));
|
|
|
@ -61,5 +61,4 @@ mod tests {
|
|
|
|
assert_eq!(state.position.y, 15);
|
|
|
|
assert_eq!(state.position.y, 15);
|
|
|
|
assert_eq!(state.quit, true);
|
|
|
|
assert_eq!(state.quit, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|