mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00: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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert!(
|
// "Centroid {} (empty cluster) does not match any data point",c
|
||||||
matches_data_point,
|
assert!(matches_data_point);
|
||||||
"Centroid {} (empty cluster) does not match any data point",
|
|
||||||
c
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -71,10 +71,8 @@ mod tests {
|
|||||||
counts[v] += 1;
|
counts[v] += 1;
|
||||||
}
|
}
|
||||||
for &c in &counts {
|
for &c in &counts {
|
||||||
assert!(
|
// "Crypto RNG counts far from uniform: {c}"
|
||||||
(c as isize - 100).abs() < 50,
|
assert!((c as isize - 100).abs() < 50);
|
||||||
"Crypto RNG counts far from uniform: {c}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +158,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let total_bits = samples * 64;
|
let total_bits = samples * 64;
|
||||||
let ratio = ones as f64 / total_bits as f64;
|
let ratio = ones as f64 / total_bits as f64;
|
||||||
assert!(
|
// "bit ratio far from 0.5: {ratio}"
|
||||||
(ratio - 0.5).abs() < 0.02,
|
assert!((ratio - 0.5).abs() < 0.02);
|
||||||
"bit ratio far from 0.5: {ratio}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,10 +125,8 @@ mod tests {
|
|||||||
counts[v] += 1;
|
counts[v] += 1;
|
||||||
}
|
}
|
||||||
for &c in &counts {
|
for &c in &counts {
|
||||||
assert!(
|
// "PRNG counts far from uniform: {c}"
|
||||||
(c as isize - 1000).abs() < 150,
|
assert!((c as isize - 1000).abs() < 150);
|
||||||
"PRNG counts far from uniform: {c}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +207,8 @@ mod tests {
|
|||||||
diff * diff / expected
|
diff * diff / expected
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
assert!(chi2 < 20.0, "chi-square statistic too high: {chi2}");
|
// "chi-square statistic too high: {chi2}"
|
||||||
|
assert!(chi2 < 20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -222,9 +221,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let total_bits = samples * 64;
|
let total_bits = samples * 64;
|
||||||
let ratio = ones as f64 / total_bits as f64;
|
let ratio = ones as f64 / total_bits as f64;
|
||||||
assert!(
|
// "bit ratio far from 0.5: {ratio}"
|
||||||
(ratio - 0.5).abs() < 0.01,
|
assert!((ratio - 0.5).abs() < 0.01);
|
||||||
"bit ratio far from 0.5: {ratio}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user