Skip to content

Commit 5012076

Browse files
committed
config: simplify tests; use type aliases to resolve clippy warnings
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6603e50a4f662776ab3ce5d1a8a705b26a6a6964
1 parent 5f0c5f7 commit 5012076

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

watt/config.rs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ use crate::{
2424
system,
2525
};
2626

27+
type CpuDeltas = HashMap<Arc<cpu::Cpu>, cpu::Delta>;
28+
type CpuEvalResult = anyhow::Result<(CpuDeltas, Option<bool>)>;
29+
type PowerSupplyDeltas =
30+
HashMap<Arc<power_supply::PowerSupply>, power_supply::Delta>;
31+
type PowerSupplyEvalResult =
32+
anyhow::Result<(PowerSupplyDeltas, Option<String>)>;
33+
2734
fn is_default<T: Default + PartialEq>(value: &T) -> bool {
2835
*value == T::default()
2936
}
@@ -74,10 +81,7 @@ pub struct CpusDelta {
7481
}
7582

7683
impl CpusDelta {
77-
pub fn eval(
78-
&self,
79-
state: &EvalState<'_, '_>,
80-
) -> anyhow::Result<(HashMap<Arc<cpu::Cpu>, cpu::Delta>, Option<bool>)> {
84+
pub fn eval(&self, state: &EvalState<'_, '_>) -> CpuEvalResult {
8185
log::debug!("evaluating CPU deltas...");
8286

8387
let cpus = match &self.for_ {
@@ -249,13 +253,7 @@ pub struct PowersDelta {
249253
}
250254

251255
impl PowersDelta {
252-
pub fn eval(
253-
&self,
254-
state: &EvalState<'_, '_>,
255-
) -> anyhow::Result<(
256-
HashMap<Arc<power_supply::PowerSupply>, power_supply::Delta>,
257-
Option<String>,
258-
)> {
256+
pub fn eval(&self, state: &EvalState<'_, '_>) -> PowerSupplyEvalResult {
259257
log::debug!("evaluating power supply deltas...");
260258

261259
let power_supplies = match &self.for_ {
@@ -1248,34 +1246,21 @@ mod tests {
12481246
cpu_log: &cpu_log,
12491247
};
12501248

1251-
let result_volatility = Expression::CpuUsageVolatility.eval(&state);
1249+
let result = Expression::CpuUsageVolatility.eval(&state);
12521250
assert!(
1253-
result_volatility.is_ok(),
1254-
"CpuUsageVolatility eval should succeed"
1255-
);
1256-
assert_eq!(
1257-
result_volatility.unwrap(),
1258-
None,
1251+
result.is_ok() && result.as_ref().unwrap().is_none(),
12591252
"CpuUsageVolatility should return None with insufficient data"
12601253
);
12611254

1262-
let result_temp = Expression::CpuTemperature.eval(&state);
1263-
assert!(result_temp.is_ok(), "CpuTemperature eval should succeed");
1264-
assert_eq!(
1265-
result_temp.unwrap(),
1266-
None,
1255+
let result = Expression::CpuTemperature.eval(&state);
1256+
assert!(
1257+
result.is_ok() && result.as_ref().unwrap().is_none(),
12671258
"CpuTemperature should return None with insufficient data"
12681259
);
12691260

1270-
let result_temp_volatility =
1271-
Expression::CpuTemperatureVolatility.eval(&state);
1261+
let result = Expression::CpuTemperatureVolatility.eval(&state);
12721262
assert!(
1273-
result_temp_volatility.is_ok(),
1274-
"CpuTemperatureVolatility eval should succeed"
1275-
);
1276-
assert_eq!(
1277-
result_temp_volatility.unwrap(),
1278-
None,
1263+
result.is_ok() && result.as_ref().unwrap().is_none(),
12791264
"CpuTemperatureVolatility should return None with insufficient data"
12801265
);
12811266
}

0 commit comments

Comments
 (0)