Refactor functions for strict Clippy checks

This commit is contained in:
Dylan M. Taylor
2026-10-28 10:52:53 +00:00
parent e17f06fb67
commit 7898cc8cfd
15 changed files with 38 additions and 18 deletions
+11 -3
View File
@@ -389,7 +389,7 @@ mod tests {
}
#[test]
fn criteria() {
fn text_criteria() {
assert!(m(">5", Value::Number(6.0)));
assert!(!m(">5", Value::Number(5.0)));
assert!(m(">=5", Value::Number(5.0)));
@@ -402,6 +402,10 @@ mod tests {
assert!(m("?pple", Value::from("apple")));
assert!(m("~*", Value::from("*")));
assert!(!m("~*", Value::from("x")));
}
#[test]
fn blank_criteria() {
assert!(m("", Value::Empty));
assert!(m("", Value::from("")));
assert!(!m("", Value::Number(0.0)));
@@ -409,10 +413,14 @@ mod tests {
assert!(!m("=", Value::from("a")));
assert!(m("<>", Value::from("a")));
assert!(!m("<>", Value::Empty));
assert!(m("TRUE", Value::Bool(true)));
// A bare "<=" or ">=" never matches an empty string (Excel 365: COUNTIF(="", "<=") is 0).
assert!(!m("<=", Value::from("")));
assert!(!m(">=", Value::from("")));
// A bare "<=" or ">=" never matches an empty string (Excel 365: COUNTIF(="", "<=") is 0).
}
#[test]
fn typed_criteria() {
assert!(m("TRUE", Value::Bool(true)));
assert!(m("<b", Value::from("apple")));
assert!(!m("<b", Value::Number(1.0)));
assert!(m("#N/A", Value::Error(CellError::NA)));
+5 -1
View File
@@ -66,11 +66,15 @@ fn cell_criterion(v: &Value) -> Option<Criterion> {
}
}
/// A criteria row: its index and its conditions (criteria column, database column or `None`
/// when the label is unknown, criterion).
type CriteriaRow = (usize, Vec<(usize, Option<usize>, Criterion)>);
/// Rows (1-based within the database, excluding the header) of matching records.
fn matching_records(db: &Array, crit: &Array, ctx: &mut dyn Ctx) -> Vec<usize> {
// Per criteria row: its index and a list of (criteria column, database column or None when
// the label is unknown, criterion).
let mut rows: Vec<(usize, Vec<(usize, Option<usize>, Criterion)>)> = Vec::new();
let mut rows: Vec<CriteriaRow> = Vec::new();
for r in 1..crit.rows {
let mut conds = Vec::new();
for c in 0..crit.cols {
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, PI, R, Value, num, num_val};
// ---------------------------------------------------------------------------------------------
// Bessel functions
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, R, Value, flatten, has, num, num_val, number_to_text, scalar, text, text_val};
// ---------------------------------------------------------------------------------------------
// Complex numbers
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, R, Value, num, num_val, text};
// ---------------------------------------------------------------------------------------------
// CONVERT
+3 -1
View File
@@ -1,4 +1,6 @@
use super::*;
use super::{
Arg, CellError, Ctx, DateSystem, R, Value, datetime_from_serial, days_in_month, is_leap, max_serial, num, num_val, opt_num, serial_from_ymd,
};
// ---------------------------------------------------------------------------------------------
// Dates and day counts
@@ -1,5 +1,5 @@
use super::day_count::{basis_arg, date, year_frac};
use super::*;
use super::{Arg, CellError, Ctx, R, Value, num, num_val, opt_bool, opt_num};
// ---------------------------------------------------------------------------------------------
// Depreciation
+5 -2
View File
@@ -1,5 +1,5 @@
use super::day_count::{basis_arg, coup_daybs, coup_days, coup_daysnc, coupons, date, day_count, freq_arg, shift_months, year_basis, year_frac, ymd};
use super::*;
use super::{Arg, CellError, Ctx, DateSystem, R, Value, days_in_month, has, num, num_val, opt_bool};
// ---------------------------------------------------------------------------------------------
// Securities
@@ -479,7 +479,10 @@ fn odd_last(sys: DateSystem, settle: f64, mat: f64, last: f64, freq: f64, basis:
}
/// settlement, maturity, last_interest, rate, yld/pr, redemption, frequency, [basis].
fn odd_last_args(a: &[Arg], sys: DateSystem) -> R<((f64, f64, f64), f64, f64, f64, f64)> {
/// `((dc, acc, dsc), rate, yield-or-price, redemption, frequency)` of an odd-last-period call.
type OddLastArgs = ((f64, f64, f64), f64, f64, f64, f64);
fn odd_last_args(a: &[Arg], sys: DateSystem) -> R<OddLastArgs> {
let (s, m, last) = (date(a, 0)?, date(a, 1)?, date(a, 2)?);
let (rate, x, red) = (num(a, 3)?, num(a, 4)?, num(a, 5)?);
let (f, basis) = (freq_arg(a, 6)?, basis_arg(a, 7)?);
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, R, Value, array_numbers, as_array, flatten, num, num_val, numbers, opt_num, type_arg};
// ---------------------------------------------------------------------------------------------
// Time value of money
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, Array, CellError, Criterion, Ctx, R, Value, as_array, has, num_val};
// ---------------------------------------------------------------------------------------------
// Criteria aggregates
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, MAX_CELLS, R, Value, array_val, as_array, check_size, num, num_val, to_sig_digits};
// ---------------------------------------------------------------------------------------------
// Matrices
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, CellError, Ctx, R, Value, num, num_val, opt_num, text, text_val};
// ---------------------------------------------------------------------------------------------
// Number systems
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arg, C, CellError, R, Value, arg, array_numbers, array_val, as_array, has, num, num_val, opt_num};
// ---------------------------------------------------------------------------------------------
// Basic helpers over number lists
+4 -1
View File
@@ -1,5 +1,8 @@
use super::descriptive::{arg_nums, arg_pairs, mean, var_s};
use super::*;
use super::{
Arg, C, CellError, R, Value, arg, as_array, boolean, erf, gamma, has, invert, ln_beta, ln_gamma, norm_cdf, norm_inv, norm_pdf, num, num_val,
reg_gamma_p, reg_gamma_q, reg_inc_beta,
};
// ---------------------------------------------------------------------------------------------
// Distributions
+1 -1
View File
@@ -1,5 +1,5 @@
use super::descriptive::{arg_pairs, intercept, moments, slope};
use super::*;
use super::{Arg, C, CellError, R, Value, arg, array_val, as_array, boolean, has, num, num_val};
pub(super) fn forecast(a: &[Arg], _: C) -> R<Value> {
let x = num(a, 0)?;