kelora 1.5.0

A command-line log analysis tool with embedded Rhai scripting
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
use rhai::{Array, Dynamic, Engine, EvalAltResult};

use super::arrays::{determine_array_type, ArrayType};

pub fn register_functions(engine: &mut Engine) {
    // Register modulo function since % operator seems to be missing
    engine.register_fn("mod", |a: i64, b: i64| -> i64 {
        if b == 0 {
            0 // Avoid division by zero
        } else {
            a % b
        }
    });

    // Also register it as % for completeness
    engine.register_fn("%", |a: i64, b: i64| -> i64 {
        if b == 0 {
            0 // Avoid division by zero
        } else {
            a % b
        }
    });

    // Register clamp function for integers
    engine.register_fn("clamp", clamp_i64);

    // Register clamp function for floats
    engine.register_fn("clamp", clamp_f64);

    // Register statistical functions for arrays
    engine.register_fn("sum", sum_array);
    engine.register_fn("mean", mean_array);
    engine.register_fn("variance", variance_array);
    engine.register_fn("stddev", stddev_array);
}

/// Helper function to convert numeric array values to f64
///
/// Only works on arrays that have already been validated as ArrayType::Numeric.
/// This ensures we only call it after type checking, matching min()/max() behavior.
fn extract_numeric_values(arr: &Array) -> Vec<f64> {
    arr.iter()
        .map(|val| {
            if val.is_int() {
                val.as_int().unwrap() as f64
            } else if val.is_float() {
                val.as_float().unwrap()
            } else {
                // Should never happen if called on validated numeric array
                0.0
            }
        })
        .collect()
}

/// Calculate sum of numeric values in an array
///
/// Returns the sum of all numeric values (int, float) in the array. All elements
/// must be actual numbers (i64, f64). Strings, booleans, and other types are NOT
/// accepted. Mixed-type arrays return `()`. Does NOT parse numeric strings as numbers
/// (use pluck_as_nums() for explicit coercion).
///
/// # Arguments
/// * `arr` - Array containing numeric values
///
/// # Returns
/// Sum as f64, or `()` if array is empty, contains non-numeric values, or has mixed types
///
/// # Examples
/// ```rhai
/// [1, 2, 3, 4, 5].sum()                    // 15.0
/// [1.5, 2.5, 3.0].sum()                    // 7.0
/// [10, 20.5, 30].sum()                     // 60.5 (mixed int/float)
/// [10, "20", 30].sum()                     // () (mixed types rejected)
/// ["10", "20", "30"].sum()                 // () (strings not parsed)
/// [].sum()                                 // () (empty array)
///
/// // Use pluck_as_nums() for explicit coercion
/// e.total_bytes = e.requests.pluck_as_nums("bytes").sum();
/// ```
fn sum_array(arr: Array) -> Dynamic {
    if arr.is_empty() {
        return Dynamic::UNIT;
    }

    let array_type = determine_array_type(&arr);

    match array_type {
        ArrayType::Empty => Dynamic::UNIT,
        ArrayType::Mixed => Dynamic::UNIT,  // Reject mixed types
        ArrayType::String => Dynamic::UNIT, // Reject non-numeric arrays
        ArrayType::Numeric => {
            let sum: f64 = extract_numeric_values(&arr).iter().sum();
            Dynamic::from(sum)
        }
    }
}

/// Calculate mean (average) of numeric values in an array
///
/// Returns the arithmetic mean of all numeric values (int, float). All elements
/// must be actual numbers (i64, f64). Strings, booleans, and other types are NOT
/// accepted. Does NOT parse numeric strings as numbers. Returns an error for
/// empty arrays or arrays with mixed/non-numeric types.
///
/// # Arguments
/// * `arr` - Array containing numeric values
///
/// # Returns
/// Mean as f64, or error if array is empty, contains non-numeric values, or has mixed types
///
/// # Examples
/// ```rhai
/// [1, 2, 3, 4, 5].mean()                   // 3.0
/// [10, 20, 30].mean()                      // 20.0
/// [1.5, 2.5, 3.0].mean()                   // 2.333...
/// [10, 20.5, 30].mean()                    // 20.166... (mixed int/float OK)
/// [10, "20", 30].mean()                    // ERROR (mixed types rejected)
/// [].mean()                                // ERROR (empty array)
///
/// // Use pluck_as_nums() for explicit coercion
/// e.avg_latency = e.latencies.pluck_as_nums("ms").mean();
/// ```
fn mean_array(arr: Array) -> Result<f64, Box<EvalAltResult>> {
    if arr.is_empty() {
        return Err("Cannot calculate mean of empty array".into());
    }

    let array_type = determine_array_type(&arr);

    match array_type {
        ArrayType::Empty => Err("Cannot calculate mean of empty array".into()),
        ArrayType::Mixed => Err("Cannot calculate mean of array with mixed types (numbers and non-numbers). Use pluck_as_nums() for type coercion.".into()),
        ArrayType::String => Err("Cannot calculate mean of array with non-numeric values".into()),
        ArrayType::Numeric => {
            let values = extract_numeric_values(&arr);
            let sum: f64 = values.iter().sum();
            Ok(sum / values.len() as f64)
        }
    }
}

/// Calculate variance of numeric values in an array
///
/// Returns the population variance (sum of squared deviations from mean divided by N).
/// All elements must be actual numbers (i64, f64). Strings, booleans, and other types
/// are NOT accepted. Does NOT parse numeric strings as numbers. Returns an error for
/// empty arrays or arrays with mixed/non-numeric types.
///
/// # Arguments
/// * `arr` - Array containing numeric values
///
/// # Returns
/// Variance as f64, or error if array is empty, contains non-numeric values, or has mixed types
///
/// # Examples
/// ```rhai
/// [1, 2, 3, 4, 5].variance()               // 2.0
/// [10, 20, 30].variance()                  // 66.666...
/// [5, 5, 5, 5].variance()                  // 0.0 (no variation)
/// [10, "20", 30].variance()                // ERROR (mixed types rejected)
///
/// // Use pluck_as_nums() for explicit coercion
/// e.latency_variance = e.latencies.pluck_as_nums("ms").variance();
/// ```
fn variance_array(arr: Array) -> Result<f64, Box<EvalAltResult>> {
    if arr.is_empty() {
        return Err("Cannot calculate variance of empty array".into());
    }

    let array_type = determine_array_type(&arr);

    match array_type {
        ArrayType::Empty => Err("Cannot calculate variance of empty array".into()),
        ArrayType::Mixed => Err("Cannot calculate variance of array with mixed types (numbers and non-numbers). Use pluck_as_nums() for type coercion.".into()),
        ArrayType::String => Err("Cannot calculate variance of array with non-numeric values".into()),
        ArrayType::Numeric => {
            let values = extract_numeric_values(&arr);
            let mean: f64 = values.iter().sum::<f64>() / values.len() as f64;
            let variance = values
                .iter()
                .map(|&val| {
                    let diff = val - mean;
                    diff * diff
                })
                .sum::<f64>()
                / values.len() as f64;
            Ok(variance)
        }
    }
}

/// Calculate standard deviation of numeric values in an array
///
/// Returns the population standard deviation (square root of variance).
/// All elements must be actual numbers (i64, f64). Strings, booleans, and other types
/// are NOT accepted. Does NOT parse numeric strings as numbers. Returns an error for
/// empty arrays or arrays with mixed/non-numeric types.
///
/// # Arguments
/// * `arr` - Array containing numeric values
///
/// # Returns
/// Standard deviation as f64, or error if array is empty, contains non-numeric values, or has mixed types
///
/// # Examples
/// ```rhai
/// [1, 2, 3, 4, 5].stddev()                 // 1.414...
/// [10, 20, 30].stddev()                    // 8.165...
/// [5, 5, 5, 5].stddev()                    // 0.0 (no variation)
/// [10, "20", 30].stddev()                  // ERROR (mixed types rejected)
///
/// // Use pluck_as_nums() for explicit coercion
/// e.latency_stddev = e.latencies.pluck_as_nums("ms").stddev();
/// ```
fn stddev_array(arr: Array) -> Result<f64, Box<EvalAltResult>> {
    let variance = variance_array(arr)?;
    Ok(variance.sqrt())
}

/// Clamp an integer value between a minimum and maximum
///
/// Constrains a value to be within a specified range. If the value is less than
/// the minimum, returns the minimum. If the value is greater than the maximum,
/// returns the maximum. Otherwise returns the value unchanged.
///
/// # Arguments
/// * `value` - The value to clamp
/// * `min` - The minimum allowed value
/// * `max` - The maximum allowed value
///
/// # Returns
/// The clamped value
///
/// # Examples
/// ```rhai
/// clamp(5, 0, 10)    // 5 (within range)
/// clamp(-5, 0, 10)   // 0 (below minimum)
/// clamp(15, 0, 10)   // 10 (above maximum)
/// clamp(50, 0, 100)  // 50 (within range)
///
/// // Useful for normalizing values
/// e.normalized_score = clamp(e.score, 0, 100);
/// e.safe_port = clamp(e.port, 1024, 65535);
/// e.cpu_pct = clamp(e.cpu_usage, 0, 100);
/// ```
///
/// # Panics
/// Panics if `min > max`.
fn clamp_i64(value: i64, min: i64, max: i64) -> i64 {
    value.clamp(min, max)
}

/// Clamp a floating-point value between a minimum and maximum
///
/// Constrains a value to be within a specified range. If the value is less than
/// the minimum, returns the minimum. If the value is greater than the maximum,
/// returns the maximum. Otherwise returns the value unchanged.
///
/// # Arguments
/// * `value` - The value to clamp
/// * `min` - The minimum allowed value
/// * `max` - The maximum allowed value
///
/// # Returns
/// The clamped value
///
/// # Examples
/// ```rhai
/// clamp(3.14, 0.0, 5.0)   // 3.14 (within range)
/// clamp(-1.5, 0.0, 5.0)   // 0.0 (below minimum)
/// clamp(7.8, 0.0, 5.0)    // 5.0 (above maximum)
///
/// // Useful for normalizing metrics
/// e.response_time_sec = clamp(e.response_time_ms / 1000.0, 0.0, 30.0);
/// e.normalized_latency = clamp(e.latency / e.baseline, 0.0, 10.0);
/// ```
///
/// # Panics
/// Panics if `min > max` or if either value is NaN.
fn clamp_f64(value: f64, min: f64, max: f64) -> f64 {
    value.clamp(min, max)
}

#[cfg(test)]
mod tests {
    use super::*;
    use rhai::Dynamic;
    use std::panic::{catch_unwind, AssertUnwindSafe};

    fn panic_message(err: Box<dyn std::any::Any + Send>) -> String {
        if let Some(msg) = err.downcast_ref::<String>() {
            msg.clone()
        } else if let Some(msg) = err.downcast_ref::<&str>() {
            (*msg).to_string()
        } else {
            String::new()
        }
    }

    #[test]
    fn test_clamp_i64_within_range() {
        assert_eq!(clamp_i64(5, 0, 10), 5);
        assert_eq!(clamp_i64(50, 0, 100), 50);
        assert_eq!(clamp_i64(0, 0, 10), 0);
        assert_eq!(clamp_i64(10, 0, 10), 10);
    }

    #[test]
    fn test_clamp_i64_below_min() {
        assert_eq!(clamp_i64(-5, 0, 10), 0);
        assert_eq!(clamp_i64(-100, 0, 100), 0);
        assert_eq!(clamp_i64(-1, 0, 10), 0);
    }

    #[test]
    fn test_clamp_i64_above_max() {
        assert_eq!(clamp_i64(15, 0, 10), 10);
        assert_eq!(clamp_i64(200, 0, 100), 100);
        assert_eq!(clamp_i64(11, 0, 10), 10);
    }

    #[test]
    fn test_clamp_i64_negative_range() {
        assert_eq!(clamp_i64(-5, -10, -1), -5);
        assert_eq!(clamp_i64(-15, -10, -1), -10);
        assert_eq!(clamp_i64(0, -10, -1), -1);
    }

    #[test]
    fn test_clamp_i64_inverted_range() {
        let err = catch_unwind(AssertUnwindSafe(|| clamp_i64(5, 10, 0)))
            .expect_err("clamp_i64 should panic when min > max");
        let msg = panic_message(err);
        assert!(
            msg.contains("assertion failed: min <= max") || msg.contains("min > max"),
            "unexpected panic message: {msg}"
        );
    }

    #[test]
    fn test_clamp_f64_within_range() {
        assert_eq!(clamp_f64(3.5, 0.0, 5.0), 3.5);
        assert_eq!(clamp_f64(2.5, 0.0, 10.0), 2.5);
        assert_eq!(clamp_f64(0.0, 0.0, 5.0), 0.0);
        assert_eq!(clamp_f64(5.0, 0.0, 5.0), 5.0);
    }

    #[test]
    fn test_clamp_f64_below_min() {
        assert_eq!(clamp_f64(-1.5, 0.0, 5.0), 0.0);
        assert_eq!(clamp_f64(-100.0, 0.0, 100.0), 0.0);
        assert_eq!(clamp_f64(-0.1, 0.0, 10.0), 0.0);
    }

    #[test]
    fn test_clamp_f64_above_max() {
        assert_eq!(clamp_f64(7.8, 0.0, 5.0), 5.0);
        assert_eq!(clamp_f64(200.5, 0.0, 100.0), 100.0);
        assert_eq!(clamp_f64(10.1, 0.0, 10.0), 10.0);
    }

    #[test]
    fn test_clamp_f64_negative_range() {
        assert_eq!(clamp_f64(-5.5, -10.0, -1.0), -5.5);
        assert_eq!(clamp_f64(-15.0, -10.0, -1.0), -10.0);
        assert_eq!(clamp_f64(0.0, -10.0, -1.0), -1.0);
    }

    #[test]
    fn test_clamp_f64_inverted_range() {
        let err = catch_unwind(AssertUnwindSafe(|| clamp_f64(5.0, 10.0, 0.0)))
            .expect_err("clamp_f64 should panic when min > max");
        let msg = panic_message(err);
        assert!(
            msg.contains("assertion failed: min <= max") || msg.contains("min > max"),
            "unexpected panic message: {msg}"
        );
    }

    #[test]
    fn test_clamp_f64_fractional() {
        assert_eq!(clamp_f64(0.5, 0.0, 1.0), 0.5);
        assert_eq!(clamp_f64(1.5, 0.0, 1.0), 1.0);
        assert_eq!(clamp_f64(-0.5, 0.0, 1.0), 0.0);
    }

    #[test]
    fn test_sum_integers() {
        let arr: Array = vec![
            Dynamic::from(1i64),
            Dynamic::from(2i64),
            Dynamic::from(3i64),
            Dynamic::from(4i64),
            Dynamic::from(5i64),
        ];
        let result = sum_array(arr);
        assert_eq!(result.as_float().unwrap(), 15.0);
    }

    #[test]
    fn test_sum_floats() {
        let arr: Array = vec![
            Dynamic::from(1.5f64),
            Dynamic::from(2.5f64),
            Dynamic::from(3.0f64),
        ];
        let result = sum_array(arr);
        assert_eq!(result.as_float().unwrap(), 7.0);
    }

    #[test]
    fn test_sum_mixed_numeric() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from(20.5f64),
            Dynamic::from(30i64),
        ];
        let result = sum_array(arr);
        assert_eq!(result.as_float().unwrap(), 60.5);
    }

    #[test]
    fn test_sum_mixed_types_rejected() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from(true),
            Dynamic::from(20i64),
            Dynamic::from(false),
        ];
        // Mixed types (numbers + booleans) are rejected
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_sum_strings_rejected() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from("20".to_string()),
            Dynamic::from(30i64),
        ];
        // Mixed types (numbers + strings) are rejected
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_sum_non_numeric_rejected() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from("not a number".to_string()),
            Dynamic::from(20i64),
        ];
        // Mixed types are rejected
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_sum_empty_array() {
        let arr: Array = vec![];
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_sum_no_numeric_values() {
        let arr: Array = vec![
            Dynamic::from("abc".to_string()),
            Dynamic::from("def".to_string()),
        ];
        // Non-numeric arrays are rejected
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_mean_basic() {
        let arr: Array = vec![
            Dynamic::from(1i64),
            Dynamic::from(2i64),
            Dynamic::from(3i64),
            Dynamic::from(4i64),
            Dynamic::from(5i64),
        ];
        assert_eq!(mean_array(arr).unwrap(), 3.0);
    }

    #[test]
    fn test_mean_floats() {
        let arr: Array = vec![
            Dynamic::from(10.0f64),
            Dynamic::from(20.0f64),
            Dynamic::from(30.0f64),
        ];
        assert_eq!(mean_array(arr).unwrap(), 20.0);
    }

    #[test]
    fn test_mean_mixed_numeric() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from(20.0f64),
            Dynamic::from(30i64),
        ];
        assert_eq!(mean_array(arr).unwrap(), 20.0);
    }

    #[test]
    fn test_mean_mixed_types_rejected() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from(true),
            Dynamic::from(30i64),
            Dynamic::from(false),
        ];
        // Mixed types (numbers + booleans) are rejected
        assert!(mean_array(arr).is_err());
    }

    #[test]
    fn test_mean_mixed_numbers_strings_rejected() {
        let arr: Array = vec![
            Dynamic::from(10i64),
            Dynamic::from("not a number".to_string()),
            Dynamic::from(20i64),
            Dynamic::from(30i64),
        ];
        // Mixed types (numbers + strings) are rejected
        assert!(mean_array(arr).is_err());
    }

    #[test]
    fn test_mean_empty_array_error() {
        let arr: Array = vec![];
        assert!(mean_array(arr).is_err());
    }

    #[test]
    fn test_mean_no_numeric_values_error() {
        let arr: Array = vec![
            Dynamic::from("abc".to_string()),
            Dynamic::from("def".to_string()),
        ];
        // Non-numeric arrays are rejected
        assert!(mean_array(arr).is_err());
    }

    #[test]
    fn test_variance_basic() {
        let arr: Array = vec![
            Dynamic::from(1i64),
            Dynamic::from(2i64),
            Dynamic::from(3i64),
            Dynamic::from(4i64),
            Dynamic::from(5i64),
        ];
        assert_eq!(variance_array(arr).unwrap(), 2.0);
    }

    #[test]
    fn test_variance_no_variation() {
        let arr: Array = vec![
            Dynamic::from(5i64),
            Dynamic::from(5i64),
            Dynamic::from(5i64),
            Dynamic::from(5i64),
        ];
        assert_eq!(variance_array(arr).unwrap(), 0.0);
    }

    #[test]
    fn test_variance_floats() {
        let arr: Array = vec![
            Dynamic::from(2.0f64),
            Dynamic::from(4.0f64),
            Dynamic::from(6.0f64),
        ];
        // Mean = 4.0, variance = ((2-4)^2 + (4-4)^2 + (6-4)^2) / 3 = (4 + 0 + 4) / 3 = 8/3
        let result = variance_array(arr).unwrap();
        assert!((result - 8.0 / 3.0).abs() < 1e-10);
    }

    #[test]
    fn test_variance_empty_array_error() {
        let arr: Array = vec![];
        assert!(variance_array(arr).is_err());
    }

    #[test]
    fn test_variance_no_numeric_values_error() {
        let arr: Array = vec![Dynamic::from("abc".to_string())];
        assert!(variance_array(arr).is_err());
    }

    #[test]
    fn test_stddev_basic() {
        let arr: Array = vec![
            Dynamic::from(1i64),
            Dynamic::from(2i64),
            Dynamic::from(3i64),
            Dynamic::from(4i64),
            Dynamic::from(5i64),
        ];
        // Variance = 2.0, stddev = sqrt(2.0) ≈ 1.414
        let result = stddev_array(arr).unwrap();
        assert!((result - 2.0f64.sqrt()).abs() < 1e-10);
    }

    #[test]
    fn test_stddev_no_variation() {
        let arr: Array = vec![
            Dynamic::from(5i64),
            Dynamic::from(5i64),
            Dynamic::from(5i64),
        ];
        assert_eq!(stddev_array(arr).unwrap(), 0.0);
    }

    #[test]
    fn test_stddev_floats() {
        let arr: Array = vec![
            Dynamic::from(10.0f64),
            Dynamic::from(20.0f64),
            Dynamic::from(30.0f64),
        ];
        // Mean = 20.0, variance = ((10-20)^2 + (20-20)^2 + (30-20)^2) / 3 = 200/3
        // stddev = sqrt(200/3) ≈ 8.165
        let result = stddev_array(arr).unwrap();
        assert!((result - (200.0f64 / 3.0).sqrt()).abs() < 1e-10);
    }

    #[test]
    fn test_stddev_empty_array_error() {
        let arr: Array = vec![];
        assert!(stddev_array(arr).is_err());
    }

    #[test]
    fn test_stddev_no_numeric_values_error() {
        let arr: Array = vec![Dynamic::from("abc".to_string())];
        assert!(stddev_array(arr).is_err());
    }

    #[test]
    fn test_sum_numeric_strings_rejected() {
        let arr: Array = vec![
            Dynamic::from("10".to_string()),
            Dynamic::from("20".to_string()),
            Dynamic::from("30".to_string()),
        ];
        // Numeric strings are not parsed as numbers
        assert!(sum_array(arr).is_unit());
    }

    #[test]
    fn test_mean_numeric_strings_rejected() {
        let arr: Array = vec![
            Dynamic::from("10".to_string()),
            Dynamic::from("20".to_string()),
            Dynamic::from("30".to_string()),
        ];
        // Numeric strings are not parsed as numbers
        assert!(mean_array(arr).is_err());
    }
}