Skip to content

Commit

Permalink
fix & tesst target
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Nov 10, 2023
1 parent 898018e commit c9b18d7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
18 changes: 5 additions & 13 deletions data/src/config/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ impl Linear {
let yb: f32 = self.max_speed.into();

let a = (yb - ya) / (xb - xa);

Affine {
a,
b: ya - a * xa,
}

Affine { a, b: ya - a * xa }
}
}

Expand All @@ -88,17 +85,13 @@ impl ToNode for Linear {
}
}




#[cfg(test)]
mod test{
mod test {
use super::Linear;


#[test]
fn test_update() {
env_logger::init();
let _ = env_logger::try_init();

let linear = Linear {
name: "linear".to_string(),
Expand All @@ -112,6 +105,5 @@ mod test{
assert!(linear.update(9).unwrap().value == 10);
assert!(linear.update(70).unwrap().value == 100);
assert!(linear.update(40).unwrap().value == 55);

}
}
}
53 changes: 52 additions & 1 deletion data/src/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Target {
}
};
UpdateResult {
value: self.load_speed.into(),
value: self.idle_speed.into(),
side_effect: Box::new(idle_reatch),
}
.into()
Expand Down Expand Up @@ -89,3 +89,54 @@ impl ToNode for Target {
Node::new(id_generator, NodeType::Target(self), inputs)
}
}

#[cfg(test)]
mod test {
use hardware::HardwareBridge;

use crate::node::{AppGraph, NodeType, ToNode};

use super::Target;

#[test]
fn test_update() {
let _ = env_logger::try_init();

let target = Target {
name: "linear".to_string(),
input: Some("temp1".into()),
idle_temp: 40,
idle_speed: 10,
load_temp: 70,
load_speed: 100,
idle_has_been_reatch: false,
};

let hardware = hardware::hardware_test::TestBridge::generate_hardware();
let mut app_graph = AppGraph::default(&hardware);
let mut node = target.to_node(&mut app_graph.id_generator, &app_graph.nodes, &hardware);

if let NodeType::Target(target) = &node.node_type {
let res = target.update(55).unwrap();
(res.side_effect)(&mut node);
assert!(res.value == 100);
}
if let NodeType::Target(target) = &node.node_type {
let res = target.update(30).unwrap();
(res.side_effect)(&mut node);
assert!(res.value == 10);
}

if let NodeType::Target(target) = &node.node_type {
let res = target.update(55).unwrap();
(res.side_effect)(&mut node);
assert!(res.value == 10);
}

if let NodeType::Target(target) = &node.node_type {
let res = target.update(70).unwrap();
(res.side_effect)(&mut node);
assert!(res.value == 100);
}
}
}
6 changes: 0 additions & 6 deletions hardware/src/hardware_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ struct InternalSensor {}
#[derive(Debug)]
struct InternalControl {}

impl Drop for InternalControl {
fn drop(&mut self) {
println!("pwm sould be set to auto");
// TODO: set to auto
}
}

impl HardwareBridge for TestBridge {
fn generate_hardware() -> Hardware {
Expand Down
2 changes: 1 addition & 1 deletion hardware/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct InternalControl {

impl Drop for InternalControl {
fn drop(&mut self) {
println!("pwm sould be set to auto");
info!("pwm sould be set to auto");
// TODO: set to auto
}
}
Expand Down

0 comments on commit c9b18d7

Please sign in to comment.