Splits article_row.rs and subscribe_form.rs into mod.rs + component.rs + handlers.rs (mirroring the components/*/ convention), and adds a sibling app/handlers.rs for App's heading computation. RSX now calls into plain functions (score_percent, normalize_feed_url, subscribed_message, feed_heading) that are covered by unit tests, instead of computing the same logic inline where it can't be tested without a Dioxus runtime. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
29 lines
851 B
Rust
29 lines
851 B
Rust
/// Converts a fractional relevance score into a whole-number percentage for
|
|
/// the row's badge, rounding rather than truncating so e.g. 0.995 shows 100%
|
|
/// instead of 99%.
|
|
pub fn score_percent(final_score: Option<f32>) -> Option<i32> {
|
|
final_score.map(|s| (s * 100.0).round() as i32)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn no_score_yields_no_percent() {
|
|
assert_eq!(score_percent(None), None);
|
|
}
|
|
|
|
#[test]
|
|
fn score_is_rounded_not_truncated() {
|
|
assert_eq!(score_percent(Some(0.995)), Some(100));
|
|
assert_eq!(score_percent(Some(0.554)), Some(55));
|
|
}
|
|
|
|
#[test]
|
|
fn score_is_scaled_to_a_percentage() {
|
|
assert_eq!(score_percent(Some(0.5)), Some(50));
|
|
assert_eq!(score_percent(Some(0.0)), Some(0));
|
|
assert_eq!(score_percent(Some(1.0)), Some(100));
|
|
}
|
|
}
|