mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-19 23:20:01 +00:00
Refactor assertions in tests to simplify error messages for KMeans, CryptoRng, and Prng modules
This commit is contained in:
parent
750adc72e9
commit
ef322fc6a2
@ -192,11 +192,8 @@ mod tests {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
matches_data_point,
|
||||
"Centroid {} (empty cluster) does not match any data point",
|
||||
c
|
||||
);
|
||||
// "Centroid {} (empty cluster) does not match any data point",c
|
||||
assert!(matches_data_point);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -71,10 +71,8 @@ mod tests {
|
||||
counts[v] += 1;
|
||||
}
|
||||
for &c in &counts {
|
||||
assert!(
|
||||
(c as isize - 100).abs() < 50,
|
||||
"Crypto RNG counts far from uniform: {c}"
|
||||
);
|
||||
// "Crypto RNG counts far from uniform: {c}"
|
||||
assert!((c as isize - 100).abs() < 50);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,9 +158,7 @@ mod tests {
|
||||
}
|
||||
let total_bits = samples * 64;
|
||||
let ratio = ones as f64 / total_bits as f64;
|
||||
assert!(
|
||||
(ratio - 0.5).abs() < 0.02,
|
||||
"bit ratio far from 0.5: {ratio}"
|
||||
);
|
||||
// "bit ratio far from 0.5: {ratio}"
|
||||
assert!((ratio - 0.5).abs() < 0.02);
|
||||
}
|
||||
}
|
||||
|
@ -125,10 +125,8 @@ mod tests {
|
||||
counts[v] += 1;
|
||||
}
|
||||
for &c in &counts {
|
||||
assert!(
|
||||
(c as isize - 1000).abs() < 150,
|
||||
"PRNG counts far from uniform: {c}"
|
||||
);
|
||||
// "PRNG counts far from uniform: {c}"
|
||||
assert!((c as isize - 1000).abs() < 150);
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +207,8 @@ mod tests {
|
||||
diff * diff / expected
|
||||
})
|
||||
.sum();
|
||||
assert!(chi2 < 20.0, "chi-square statistic too high: {chi2}");
|
||||
// "chi-square statistic too high: {chi2}"
|
||||
assert!(chi2 < 20.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -222,9 +221,7 @@ mod tests {
|
||||
}
|
||||
let total_bits = samples * 64;
|
||||
let ratio = ones as f64 / total_bits as f64;
|
||||
assert!(
|
||||
(ratio - 0.5).abs() < 0.01,
|
||||
"bit ratio far from 0.5: {ratio}"
|
||||
);
|
||||
// "bit ratio far from 0.5: {ratio}"
|
||||
assert!((ratio - 0.5).abs() < 0.01);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user