Skip to content

Commit 18bd459

Browse files
committed
Fix clippy errors after rebasing
1 parent 0dcbc9c commit 18bd459

File tree

4 files changed

+105
-77
lines changed

4 files changed

+105
-77
lines changed

tests/difftests/bin/src/differ.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::unimplemented)]
2+
13
use difftest::config::OutputType;
24
use std::marker::PhantomData;
35

@@ -67,16 +69,16 @@ impl OutputDiffer for RawDiffer {
6769
(Some(&b1), Some(&b2)) if b1 != b2 => {
6870
differences.push(Difference {
6971
index: i,
70-
value1: format!("{}", b1),
71-
value2: format!("{}", b2),
72+
value1: format!("{b1}"),
73+
value2: format!("{b2}"),
7274
absolute_diff: DiffMagnitude::Incomparable,
7375
relative_diff: DiffMagnitude::Incomparable,
7476
});
7577
}
7678
(Some(&b1), None) => {
7779
differences.push(Difference {
7880
index: i,
79-
value1: format!("{}", b1),
81+
value1: format!("{b1}"),
8082
value2: "".to_string(),
8183
absolute_diff: DiffMagnitude::Incomparable,
8284
relative_diff: DiffMagnitude::Incomparable,
@@ -86,7 +88,7 @@ impl OutputDiffer for RawDiffer {
8688
differences.push(Difference {
8789
index: i,
8890
value1: "".to_string(),
89-
value2: format!("{}", b2),
91+
value2: format!("{b2}"),
9092
absolute_diff: DiffMagnitude::Incomparable,
9193
relative_diff: DiffMagnitude::Incomparable,
9294
});
@@ -129,8 +131,8 @@ impl DifferenceDisplay for RawDiffer {
129131
};
130132
(
131133
format!("{:>3}", format!("{:02x}", byte)),
132-
format!("{:3}", byte),
133-
format!("{:^5}", ascii),
134+
format!("{byte:3}"),
135+
format!("{ascii:^5}"),
134136
)
135137
};
136138

@@ -151,8 +153,8 @@ impl DifferenceDisplay for RawDiffer {
151153
};
152154
(
153155
format!("{:>3}", format!("{:02x}", byte)),
154-
format!("{:3}", byte),
155-
format!("{:^5}", ascii),
156+
format!("{byte:3}"),
157+
format!("{ascii:^5}"),
156158
)
157159
};
158160

@@ -194,8 +196,7 @@ impl DifferenceDisplay for RawDiffer {
194196
let last_line_width = result
195197
.lines()
196198
.last()
197-
.map(|l| l.chars().count())
198-
.unwrap_or(0);
199+
.map_or(0, |l| l.chars().count());
199200
result.push_str(&format!(
200201
"\n{:>width$}",
201202
format!("... {} more differences", diffs.len() - 10),
@@ -226,7 +227,7 @@ impl DifferenceDisplay for RawDiffer {
226227
for (i, chunk) in output.chunks(16).enumerate() {
227228
write!(file, "{:08x}: ", i * 16)?;
228229
for byte in chunk {
229-
write!(file, "{:02x} ", byte)?;
230+
write!(file, "{byte:02x} ")?;
230231
}
231232
writeln!(file)?;
232233
}
@@ -255,7 +256,7 @@ impl NumericType for f32 {
255256
"F32"
256257
}
257258
fn format_value(value: Self) -> String {
258-
format!("{:.9}", value)
259+
format!("{value:.9}")
259260
}
260261
fn can_have_relative_diff() -> bool {
261262
true
@@ -280,7 +281,7 @@ impl NumericType for u32 {
280281
"U32"
281282
}
282283
fn format_value(value: Self) -> String {
283-
format!("{}", value)
284+
format!("{value}")
284285
}
285286
fn can_have_relative_diff() -> bool {
286287
true
@@ -379,7 +380,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
379380
let abs_str = match &d.absolute_diff {
380381
DiffMagnitude::Numeric(val) => {
381382
if T::can_have_relative_diff() {
382-
format!("{:.3e}", val)
383+
format!("{val:.3e}")
383384
} else {
384385
format!("{}", *val as u64)
385386
}
@@ -434,8 +435,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
434435
let last_line_width = result
435436
.lines()
436437
.last()
437-
.map(|l| l.chars().count())
438-
.unwrap_or(0);
438+
.map_or(0, |l| l.chars().count());
439439
result.push_str(&format!(
440440
"\n{:>width$}",
441441
format!("... {} more differences", diffs.len() - 10),
@@ -482,9 +482,9 @@ impl From<OutputType> for Box<dyn OutputDiffer + Send + Sync> {
482482
match output_type {
483483
OutputType::Raw => Box::new(RawDiffer),
484484
OutputType::F32 => Box::new(F32Differ::default()),
485-
OutputType::F64 => todo!("F64Differ not implemented yet"),
485+
OutputType::F64 => unimplemented!("F64Differ not implemented yet"),
486486
OutputType::U32 => Box::new(U32Differ::default()),
487-
OutputType::I32 => todo!("I32Differ not implemented yet"),
487+
OutputType::I32 => unimplemented!("I32Differ not implemented yet"),
488488
}
489489
}
490490
}
@@ -494,9 +494,9 @@ impl From<OutputType> for Box<dyn DifferenceDisplay + Send + Sync> {
494494
match output_type {
495495
OutputType::Raw => Box::new(RawDiffer),
496496
OutputType::F32 => Box::new(F32Differ::default()),
497-
OutputType::F64 => todo!("F64Display not implemented yet"),
497+
OutputType::F64 => unimplemented!("F64Differ not implemented yet"),
498498
OutputType::U32 => Box::new(U32Differ::default()),
499-
OutputType::I32 => todo!("I32Display not implemented yet"),
499+
OutputType::I32 => unimplemented!("I32Differ not implemented yet"),
500500
}
501501
}
502502
}
@@ -533,11 +533,11 @@ mod tests {
533533
assert_eq!(diffs[0].value2, "5");
534534
match &diffs[0].absolute_diff {
535535
DiffMagnitude::Numeric(val) => assert_eq!(*val, 3.0),
536-
_ => panic!("Expected numeric difference"),
536+
DiffMagnitude::Incomparable => panic!("Expected numeric difference"),
537537
}
538538
match &diffs[0].relative_diff {
539539
DiffMagnitude::Numeric(val) => assert_eq!(*val, 3.0 / 5.0), // 3/5 = 0.6
540-
_ => panic!("Expected numeric relative diff for U32"),
540+
DiffMagnitude::Incomparable => panic!("Expected numeric relative diff for U32"),
541541
}
542542

543543
// Check second difference (index 3: 4 vs 7)
@@ -546,7 +546,7 @@ mod tests {
546546
assert_eq!(diffs[1].value2, "7");
547547
match &diffs[1].absolute_diff {
548548
DiffMagnitude::Numeric(val) => assert_eq!(*val, 3.0),
549-
_ => panic!("Expected numeric difference"),
549+
DiffMagnitude::Incomparable => panic!("Expected numeric difference"),
550550
}
551551
}
552552

@@ -665,12 +665,12 @@ mod tests {
665665

666666
match numeric {
667667
DiffMagnitude::Numeric(val) => assert_eq!(val, 42.0),
668-
_ => panic!("Expected numeric"),
668+
DiffMagnitude::Incomparable => panic!("Expected numeric"),
669669
}
670670

671671
match incomparable {
672672
DiffMagnitude::Incomparable => {}
673-
_ => panic!("Expected incomparable"),
673+
DiffMagnitude::Numeric(_) => panic!("Expected incomparable"),
674674
}
675675
}
676676
}

tests/difftests/bin/src/runner.rs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct ErrorReport {
9191
impl ErrorReport {
9292
fn new(test_info: TestInfo, differ_name: &'static str, epsilon: Option<f32>) -> Self {
9393
let epsilon_str = match epsilon {
94-
Some(e) => format!(", ε={}", e),
94+
Some(e) => format!(", ε={e}"),
9595
None => String::new(),
9696
};
9797
Self {
@@ -106,16 +106,15 @@ impl ErrorReport {
106106
self.summary_parts
107107
.push(format!("{} differences", differences.len()));
108108

109-
if let Some((max_diff, max_rel)) = self.calculate_max_differences(differences) {
109+
if let Some((max_diff, max_rel)) = Self::calculate_max_differences(differences) {
110110
self.summary_parts
111111
.push(format!("max: {:.3e} ({:.2}%)", max_diff, max_rel * 100.0));
112112
}
113113
}
114114
}
115115

116116
fn set_distinct_outputs(&mut self, count: usize) {
117-
self.summary_parts
118-
.push(format!("{} distinct outputs", count));
117+
self.summary_parts.push(format!("{count} distinct outputs"));
119118
}
120119

121120
fn add_output_files(
@@ -159,7 +158,7 @@ impl ErrorReport {
159158

160159
fn add_summary_line(&mut self, differences: &[Difference]) {
161160
if !differences.is_empty() {
162-
if let Some((max_diff, max_rel)) = self.calculate_max_differences(differences) {
161+
if let Some((max_diff, max_rel)) = Self::calculate_max_differences(differences) {
163162
self.lines.push(format!(
164163
"• {} differences, max: {:.3e} ({:.2}%)",
165164
differences.len(),
@@ -173,7 +172,7 @@ impl ErrorReport {
173172
}
174173
}
175174

176-
fn calculate_max_differences(&self, differences: &[Difference]) -> Option<(f64, f64)> {
175+
fn calculate_max_differences(differences: &[Difference]) -> Option<(f64, f64)> {
177176
let max_diff = differences
178177
.iter()
179178
.filter_map(|d| match &d.absolute_diff {
@@ -369,8 +368,7 @@ impl Runner {
369368
error!("Failed to parse metadata for package '{}'", pkg_name);
370369
return Err(RunnerError::Config {
371370
msg: format!(
372-
"Failed to parse metadata for package '{}': {}",
373-
pkg_name, e
371+
"Failed to parse metadata for package '{pkg_name}': {e}"
374372
),
375373
});
376374
}
@@ -472,7 +470,7 @@ impl Runner {
472470
let mut found_group = false;
473471

474472
for (group_output, group) in groups.iter_mut() {
475-
if self.outputs_match(&po.output, group_output, epsilon, output_type) {
473+
if Self::outputs_match(&po.output, group_output, epsilon, output_type) {
476474
group.push(po);
477475
found_group = true;
478476
break;
@@ -488,7 +486,6 @@ impl Runner {
488486
}
489487

490488
fn outputs_match(
491-
&self,
492489
output1: &[u8],
493490
output2: &[u8],
494491
epsilon: Option<f32>,
@@ -862,19 +859,25 @@ mod tests {
862859

863860
#[test]
864861
fn test_outputs_match_no_epsilon() {
865-
let runner = Runner::new(PathBuf::from("dummy_base"));
866-
867862
// Exact match should work
868-
assert!(runner.outputs_match(b"hello", b"hello", None, OutputType::Raw));
863+
assert!(Runner::outputs_match(
864+
b"hello",
865+
b"hello",
866+
None,
867+
OutputType::Raw
868+
));
869869

870870
// Different content should not match
871-
assert!(!runner.outputs_match(b"hello", b"world", None, OutputType::Raw));
871+
assert!(!Runner::outputs_match(
872+
b"hello",
873+
b"world",
874+
None,
875+
OutputType::Raw
876+
));
872877
}
873878

874879
#[test]
875880
fn test_outputs_match_with_epsilon_f32() {
876-
let runner = Runner::new(PathBuf::from("dummy_base"));
877-
878881
// Prepare test data - two floats with small difference
879882
let val1: f32 = 1.0;
880883
let val2: f32 = 1.00001;
@@ -884,19 +887,32 @@ mod tests {
884887
let bytes2 = bytemuck::cast_slice(&arr2);
885888

886889
// Should not match without epsilon
887-
assert!(!runner.outputs_match(bytes1, bytes2, None, OutputType::F32));
890+
assert!(!Runner::outputs_match(
891+
bytes1,
892+
bytes2,
893+
None,
894+
OutputType::F32
895+
));
888896

889897
// Should match with sufficient epsilon
890-
assert!(runner.outputs_match(bytes1, bytes2, Some(0.0001), OutputType::F32));
898+
assert!(Runner::outputs_match(
899+
bytes1,
900+
bytes2,
901+
Some(0.0001),
902+
OutputType::F32
903+
));
891904

892905
// Should not match with too small epsilon
893-
assert!(!runner.outputs_match(bytes1, bytes2, Some(0.000001), OutputType::F32));
906+
assert!(!Runner::outputs_match(
907+
bytes1,
908+
bytes2,
909+
Some(0.000001),
910+
OutputType::F32
911+
));
894912
}
895913

896914
#[test]
897915
fn test_outputs_match_with_epsilon_f64() {
898-
let runner = Runner::new(PathBuf::from("dummy_base"));
899-
900916
// Prepare test data - two doubles with small difference
901917
let val1: f64 = 1.0;
902918
let val2: f64 = 1.00001;
@@ -906,13 +922,28 @@ mod tests {
906922
let bytes2 = bytemuck::cast_slice(&arr2);
907923

908924
// Should not match without epsilon
909-
assert!(!runner.outputs_match(bytes1, bytes2, None, OutputType::F64));
925+
assert!(!Runner::outputs_match(
926+
bytes1,
927+
bytes2,
928+
None,
929+
OutputType::F64
930+
));
910931

911932
// Should match with sufficient epsilon
912-
assert!(runner.outputs_match(bytes1, bytes2, Some(0.0001), OutputType::F64));
933+
assert!(Runner::outputs_match(
934+
bytes1,
935+
bytes2,
936+
Some(0.0001),
937+
OutputType::F64
938+
));
913939

914940
// Should not match with too small epsilon
915-
assert!(!runner.outputs_match(bytes1, bytes2, Some(0.000001), OutputType::F64));
941+
assert!(!Runner::outputs_match(
942+
bytes1,
943+
bytes2,
944+
Some(0.000001),
945+
OutputType::F64
946+
));
916947
}
917948

918949
#[test]

0 commit comments

Comments
 (0)