Scaffold statistic

From dathere/qsv-stats · View interactive version

Scaffold statistic is an AI agent skill from the GitHub repository dathere/qsv-stats. Generate boilerplate for a new statistic following library conventions

How to use this skill

Skill file

Scaffold Statistic

Generate the boilerplate code for adding a new statistic to qsv-stats, following established library conventions.

Arguments

The user should provide:

What to Generate

1. Module-level convenience function

/// Brief description of the statistic.
///
/// This has time complexity `O(...)` and space complexity `O(...)`.
///
/// ## Example
///
/// ```
/// use stats;
///
/// let vals = vec![1, 2, 3, 4, 5];
/// let result = stats::statistic_name(vals.into_iter());
/// ```
pub fn statistic_name<I>(it: I, precalc_param: Option<f64>) -> Option<f64>
where
    I: Iterator,
    I::Item: PartialOrd + ToPrimitive,
{
    let mut unsorted = Unsorted::new();
    unsorted.extend(it);
    unsorted.statistic_name(precalc_param)
}

2. Instance method on the appropriate struct

pub fn statistic_name(&mut self, precalc_param: Option<f64>) -> Option<f64> {
    // TODO: implement
    todo!()
}

3. Tests (in the module's `#[cfg(test)]` block)

Generate edge-case tests following the existing pattern:

#[test]
fn test_statistic_name_empty() {
    let vals: Vec<f64> = vec![];
    assert_eq!(statistic_name(vals.into_iter(), None), None);
}

#[test]
fn test_statistic_name_single() {
    let vals = vec![42.0];
    // TODO: expected value for single element
}

#[test]
fn test_statistic_name_basic() {
    let vals = vec![1.0, 2.0, 3.0, 4.0, 5.0];
    // TODO: expected value
}

#[test]
fn test_statistic_name_duplicates() {
    let vals = vec![1.0, 1.0, 2.0, 2.0, 3.0];
    // TODO: expected value
}

#[test]
fn test_statistic_name_negatives() {
    let vals = vec![-3.0, -1.0, 0.0, 1.0, 3.0];
    // TODO: expected value
}

#[test]
fn test_statistic_name_with_precalc() {
    // Test that passing precalculated values produces same result
    let vals = vec![1.0, 2.0, 3.0, 4.0, 5.0];
    let without = statistic_name(vals.clone().into_iter(), None);
    let with = statistic_name(vals.into_iter(), Some(precalc_value));
    assert_eq!(without, with);
}

Conventions to Follow

After Scaffolding

Remind the user to:

  1. Fill in the todo!() implementation
  2. Update the expected values in tests
  3. Add a re-export in lib.rs if it's a module-level function
  4. Run cargo test to verify
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.