Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
rinx
Commits
bb1b3927
Commit
bb1b3927
authored
Mar 06, 2016
by
Constantin Berhard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
progress with TestableEvent
fun with the Box<Any> type
parent
78b08081
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
20 deletions
+41
-20
src/brain/mod.rs
src/brain/mod.rs
+0
-9
src/testing/book_keeper.rs
src/testing/book_keeper.rs
+7
-1
src/testing/events.rs
src/testing/events.rs
+17
-7
src/testing/mod.rs
src/testing/mod.rs
+17
-3
No files found.
src/brain/mod.rs
View file @
bb1b3927
...
...
@@ -18,15 +18,6 @@ pub struct Actors {
buzz
:
Box
<
Actor
<
bool
>>
,
}
/// Corresponds to the position of the respective actor in struct Actors.
/// It is used for testing, to check that the correct actor is activated.
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
pub
enum
ActorType
{
GreenLed
,
Lock
,
Buzz
,
}
/// A [Situation] is something that can deal with all events coming in at a
/// particular time. It has access to the actors and can handle events by
/// using the [Environment]. When done, it has to return back all the actors,
...
...
src/testing/book_keeper.rs
View file @
bb1b3927
struct
BookKeeper
;
use
std
::
sync
::
mpsc
::
Receiver
;
use
testing
::
TestableEvent
;
struct
BookKeeper
{
receiver
:
Receiver
<
Box
<
TestableEvent
>>
,
}
src/testing/events.rs
View file @
bb1b3927
use
std
::
fmt
::
Debug
;
use
bra
in
::
ActorType
;
use
test
in
g
::
ActorType
;
use
testing
::
TestableEvent
;
use
std
::
boxed
::
Box
;
use
std
::
any
::
Any
;
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
struct
ActorActed
<
T
>
where
T
:
PartialEq
+
Eq
+
Debug
+
Copy
+
Clone
pub
struct
ActorActed
<
T
>
where
T
:
PartialEq
+
Eq
+
Debug
+
Copy
+
Clone
+
Any
{
actor
:
ActorType
,
act
:
T
,
pub
actor
:
ActorType
,
pub
act
:
T
,
}
impl
<
T
>
TestableEvent
for
ActorActed
<
T
>
where
T
:
PartialEq
+
Eq
+
Debug
+
Copy
+
Clone
{}
where
T
:
PartialEq
+
Eq
+
Debug
+
Copy
+
Clone
+
Any
{
fn
obj_equals
(
&
self
,
other
:
Box
<
Any
>
)
->
bool
{
match
other
.downcast
::
<
ActorActed
<
T
>>
()
{
Ok
(
other
)
=>
*
self
==
*
other
,
Err
(
_
)
=>
false
,
}
}
}
src/testing/mod.rs
View file @
bb1b3927
use
std
::
fmt
::
Debug
;
use
std
::
cmp
::
Eq
;
use
std
::
any
::
Any
;
trait
TestableEvent
:
Debug
+
Eq
{}
/// An event of some kind, that can be compared to other `TestableEvent`s for testing
/// and has a `Debug` implementation for human debugging with the logger.
pub
trait
TestableEvent
:
Debug
+
Any
{
fn
obj_equals
(
&
self
,
other
:
Box
<
Any
>
)
->
bool
;
}
mod
events
;
/// Corresponds to the position of the respective actor in brain::Actors.
/// It is used for testing, to check that the correct actor is activated.
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
pub
enum
ActorType
{
GreenLed
,
Lock
,
Buzz
,
}
pub
mod
events
;
mod
book_keeper
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment