mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-28 20:56:54 -06:00
Refactor functions for strict Clippy checks
This commit is contained in:
@@ -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)));
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{Arg, CellError, Ctx, PI, R, Value, num, num_val};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Bessel functions
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{Arg, CellError, Ctx, R, Value, num, num_val, text};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// CONVERT
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,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,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{Arg, Array, CellError, Criterion, Ctx, R, Value, as_array, has, num_val};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Criteria aggregates
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{Arg, CellError, Ctx, R, Value, num, num_val, opt_num, text, text_val};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Number systems
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,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)?;
|
||||
|
||||
Reference in New Issue
Block a user