-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ roland = [] | |
camloc = ["dep:camloc-server"] | ||
|
||
gpio-backend = ["dep:rppal"] | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
pub mod de; | ||
pub mod error; | ||
pub mod ser; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ | ||
cmd::{self, Concrete}, | ||
event, | ||
}; | ||
use rand::random; | ||
|
||
#[test] | ||
fn ser_matches_de() -> anyhow::Result<()> { | ||
for _ in 0..100 { | ||
let cs = [ | ||
Concrete::MoveRobot(cmd::MoveRobot(random(), random())), | ||
Concrete::MoveRobotByAngle(cmd::MoveRobotByAngle(random(), random())), | ||
Concrete::StopRobot(cmd::StopRobot), | ||
Concrete::Led(cmd::Led(random(), random(), random())), | ||
Concrete::RolandServo(cmd::RolandServo(random())), | ||
Concrete::Buzzer(cmd::Buzzer(random())), | ||
Concrete::TrackSensor(cmd::TrackSensor), | ||
Concrete::UltraSensor(cmd::UltraSensor), | ||
Concrete::PinMode(cmd::PinMode( | ||
random(), | ||
if random::<bool>() { | ||
crate::gpio::Mode::Input | ||
} else { | ||
crate::gpio::Mode::Output | ||
}, | ||
)), | ||
Concrete::ReadPin(cmd::ReadPin(random())), | ||
Concrete::WritePin(cmd::WritePin(random(), random())), | ||
Concrete::Pwm(cmd::Pwm(random(), random(), random())), | ||
Concrete::Servo(cmd::Servo(random(), random())), | ||
Concrete::GetPosition(cmd::GetPosition), | ||
Concrete::Subscribe(cmd::Subscribe(event::GpioPin(random()).into())), | ||
Concrete::Unsubscribe(cmd::Unsubscribe(event::GpioPin(random()).into())), | ||
Concrete::Nop(cmd::Nop), | ||
Concrete::GetUptime(cmd::GetUptime), | ||
Concrete::Abort(cmd::Abort), | ||
]; | ||
|
||
for c in cs { | ||
let txt1 = super::ser::to_string(&c)?; | ||
let concrete = super::de::from_str::<Concrete>(&txt1)?; | ||
let txt2 = super::ser::to_string(&concrete)?; | ||
if txt1 != txt2 { | ||
println!("❌ {txt1} | {txt2}"); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
20f249e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Artifacts
View all