rustics 1.0.3

simple statistic library for performance analysis
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
//
//  Copyright 2024 Jonathan L Bertoni
//
//  This code is available under the Berkeley 2-Clause, Berkeley 3-clause,
//  and MIT licenses.
//

//!
//! ## Type
//!
//! * Printable
//!     * Printable implements the output formatting used by all the
//!       Rustics types, like RunningInteger.
//!
//!     * This module provides helper functions for formatting integers
//!       and time values.
//!
//! ## Example
//!```
//!     use rustics::printable::Printable;
//!
//!
//!     let hz      = 1_000_000_000;
//!     let second  = hz as f64;
//!     let ms      = second / 1000.0;
//!     let us      = second / 1000_000.0;
//!     let ns      = second / 1_000_000_000.0;
//!     let minute  = second * 60.0;
//!     let hour    = minute * 60.0;
//!     let day     = 24.0 * hour;
//!     let week    = day * 7.0;
//!
//!     let examples =
//!         [
//!             (         100.0,   100.0,  "nanoseconds" ),
//!             (         102.4,   102.4,  "nanoseconds" ),
//!             (       1_000.0,     1.0,  "microsecond" ),
//!             (       1_200.0,     1.2,  "microseconds"),
//!             (      29_000.0,    29.0,  "microseconds"),
//!             (   1_000_000.0,     1.0,  "millisecond" ),
//!             (  29_000_000.0,    29.0,  "milliseconds"),
//!
//!             (       us - ns,   999.0,  "nanoseconds" ),
//!             (       ms - us,   999.0,  "microseconds"),
//!             (   second - ms,   999.0,  "milliseconds"),
//!
//!             (        second,     1.0,  "second" ),
//!             (  1.5 * second,     1.5,  "seconds"),
//!             (  3.0 * second,     3.0,  "seconds"),
//!             (  3.0 * second,     3.0,  "seconds"),
//!             ( 42.0 * second,    42.0,  "seconds"),
//!             (        hour,       1.0,  "hour"   ),
//!             ( 12.6 * hour,      12.6,  "hours"  ),
//!             (        day,        1.0,  "day"    ),
//!             (  2.0 * day,        2.0,  "days"   ),
//!             (999.0 * day,      999.0,  "days"   ),
//!             (        week,       7.0,  "days"   ),
//!         ];
//!
//!     // Convert a time in ticks to a scaled value and
//!     // and a string for units.  For example, 1000 ns
//!     // should return (1.0, "nanoseconds").
//!
//!     for example in examples {
//!         let (ticks, time, units) = example;
//!
//!         let (result_time, result_units) =
//!             Printable::scale_time(ticks, hz);
//!
//!         println!(
//!             "documentation:  expect ({} {}) from {}, got ({} {})",
//!             time, units,
//!             ticks,
//!             result_time, result_units
//!         );
//!
//!         assert!(result_time  == time);
//!         assert!(result_units == units);
//!
//!         // The commas functions works to add commas to integer output.
//!         // It handles "+" and "-" signs.  The interface functions
//!         // commas_64 and commas_u64 are a bit more convenient to use.
//!
//!         assert_eq!(Printable::commas(   "+20"),       "+20");
//!         assert_eq!(Printable::commas(  "-200"),      "-200");
//!         assert_eq!(Printable::commas(  "2000"),     "2,000");
//!         assert_eq!(Printable::commas("+12345"),   "+12,345");
//!         assert_eq!(Printable::commas("-12345"),   "-12,345");
//!         assert_eq!(Printable::commas("200000"),   "200,000");
//!     }
//!```

// The Printable struct and associated functions are common code for
// printing statistics.
//
// The Printable struct is used to pass values to be printed
// by standard output routines.

use super::Printer;
use super::Units;

/// The Printable struct is used to pass data to the standard print
/// functions shared by all the code.  Developers who are implementing
/// the Rustics trait for a new type might use this module.

#[derive(Clone)]
pub struct Printable {
    pub n:          u64,
    pub nans:       u64,
    pub infinities: u64,
    pub min_i64:    i64,
    pub max_i64:    i64,
    pub min_f64:    f64,
    pub max_f64:    f64,
    pub mode_value: f64,
    pub log_mode:   i64,
    pub mean:       f64,
    pub variance:   f64,
    pub skewness:   f64,
    pub kurtosis:   f64,
    pub units:      Units,
}

impl Printable {
    /// The commas() function inserts commas into a string
    /// containing the character form of an integer.  This
    /// input string might or might not have a leading "+" or
    /// "-" sign.

    pub fn commas(value: &str) -> String {
        if value.len() <= 3 {
            return value.to_string()
        }

        let sign;
        let digits;
        let comma_interval = 3;

        // A string like "-200" shouldn't be printed as "-,200", so detect and
        // handle leading signs that'll cause a comma to be added.  If the
        // string length is 1 mod 3 and the top character is a sign, we need to
        // intervene.

        if value.len() % comma_interval == 1 {
            match value.chars().next().unwrap() {
                '+' => { sign = "+"; digits = value[1..].to_string(); }
                '-' => { sign = "-"; digits = value[1..].to_string(); }
                _   => { sign = ""; digits = value.to_string(); }
            }
        } else {
            sign   = "";
            digits = value.to_string()
        }

        let result =
            digits
                .as_bytes()                 // convert the input to a byte array
                .rchunks(comma_interval)    // break into chunks of three (or whatever) from the right
                .rev()                      // reverse the current order back to the original order
                .map(std::str::from_utf8)   // convert back to a vector of strings
                .collect::<Result<Vec<&str>, _>>()
                .unwrap()
                .join(",");                 // join the blocks of three digits with commas

        // Add the sign back in front as needed.

        match sign {
            "+" => "+".to_string() + &result,
            "-" => "-".to_string() + &result,
            _   => result,
        }
    }

    /// Converts an i64 into a string with comma separators.

    pub fn commas_i64(value: i64) -> String {
        let base = value.to_string();

        Self::commas(&base)
    }

    /// Converts a u64 into a string with comma separators.

    pub fn commas_u64(value: u64) -> String {
        let base = value.to_string();

        Self::commas(&base)
    }

    /// Converts a time interval in clock ticks into a human-
    /// readable value and unit.  The chosen unit is returned
    /// as a string for printing.

    pub fn scale_time(time: f64, hz: i64) -> (f64, String) {
        let microsecond = 1_000.0;
        let millisecond = microsecond * 1000.0;
        let second      = millisecond * 1000.0;
        let minute      = 60.0 * second;
        let hour        = 60.0 * minute;
        let day         = hour * 24.0;

        // Convert the time to nanoseconds

        let time = time * (1_000_000_000.0 / hz as f64);

        let unit;
        let scale;
        let has_plural;

        // Decide what units to use.

        if time >= day {
            unit       = "day";
            scale      = day;
            has_plural = true;
        } else if time >= hour {
            unit       = "hour";
            scale      = hour;
            has_plural = true;
        } else if time >= minute {
            unit       = "minute";
            scale      = minute;
            has_plural = true;
        } else if time >= second {
            unit       = "second";
            scale      = second;
            has_plural = true;
        } else if time >= millisecond {
            unit       = "millisecond";
            scale      = millisecond;
            has_plural = true;
        } else if time >= microsecond {
            unit       = "microsecond";
            scale      = microsecond;
            has_plural = true;
        } else {
            unit       = "nanosecond";
            scale      = 1.0;
            has_plural = true;
        }

        let plural = time != scale;

        let suffix =
            if plural & has_plural {
                "s"
            } else {
                ""
            };

        let     scaled_time = time / scale;
        let mut unit        = unit.to_string();

        unit.push_str(suffix);

        (scaled_time, unit)
    }

    /// Prints an integer statistic and its name in the standard format.

    pub fn print_integer(name: &str, value: i64, printer: &mut dyn Printer) {
        Printable::print_integer_units(name, value, printer, &Units::empty());
    }

    /// Prints an integer statistic with its name and units in the standard format.

    pub fn print_integer_units(name: &str, value: i64, printer: &mut dyn Printer, units: &Units) {
        let unit_string =
            if value == 1 {
                &units.singular
            } else {
                &units.plural
            };

        let output = format!("    {:<12} {:>12} {}", name, Self::commas_i64(value), unit_string);

        printer.print(&output);
    }

    /// Prints a float statistic and its name in the standard format.

    pub fn print_float(name: &str, value: f64, printer: &mut dyn Printer) {
        Self::print_float_unit(name, value, "", printer)
    }

    /// Prints a float statistic in the standard format  using a Units
    /// descriptor and a given printer.

    pub fn print_float_units(name: &str, value: f64, printer: &mut dyn Printer, units: &Units) {
        let unit =
            if value == 1.0 {
                &units.singular
            } else {
                &units.plural
            };

        Printable::print_float_unit(name, value, unit, printer);
    }

    /// Prints a float value and its name along with a string specifying
    /// the units.

    pub fn print_float_unit(name: &str, value: f64, unit: &str, printer: &mut dyn Printer) {
        assert!(!value.is_nan());

        let (mantissa, exponent) = Printable::format_float(value);

        let output = format!("    {:<13}    {} {} {}", name, mantissa, exponent, unit);

        printer.print(&output);
    }

    /// Converts an f64 value into a mantissa and exponent string.

    pub fn format_float(value: f64) -> (String, String) {
        // Print the value in scientific notation, then
        // force a sign onto the exponent to make things
        // line up.

        let value =
             format!("{:+e}", value)
            .replace('e',   " e+")
            .replace("e+-", " e-") ;

        // Force the mantissa to 8 digits.  This should
        // help with legibility since all the numbers
        // should align.

        let     mantissa_digits = 8;
        let mut mantissa        = Vec::with_capacity(2 * mantissa_digits);
        let mut got_decimal     = false;

        for char in value.chars() {
            if char == ' ' {
                break;
            }

            if char == '.' {
                got_decimal = true;
            }

            mantissa.push(char);

            // Add "|| mantissa.len == 6 && !got_decimal"?  Not currently
            // possible.

            if mantissa.len() == 8 {
                break;
            }
        }

        // The format macro doesn't always provide a decimal point,
        // so add one as needed.

        if !got_decimal {
            mantissa.push('.');
            mantissa.push('0');
        }

        // Add trailing zeroes as needed to get to the desired number
        // of digits.

        while mantissa.len() < mantissa_digits {
            mantissa.push('0');
        }

        // Convert the mantissa Vec into a String.

        let mantissa: String = mantissa.into_iter().collect();

        // Now extract the exponent and pad to at least 4 bytes.

        let     size     = 4;
        let mut exponent = value.split(' ').last().unwrap().to_string();

        if exponent.len() < size {
            for _i in 0..size - exponent.len() {
                exponent.push(' ');
            }
        }

        (mantissa, exponent)
    }

    /// Prints a time value in human-usable form.

    pub fn print_time(name: &str, time: f64, hz: i64, printer: &mut dyn Printer) {
        let (scaled_time, unit) = Self::scale_time(time, hz);

        if scaled_time > 999999.0 {
            Self::print_float_unit(name, scaled_time, &unit, printer);
        } else {
            let output = format!("    {:<12} {:>12.3} {}", name, scaled_time, unit);
            printer.print(&output);
        }
    }

    /// Prints the common statistics for i64 (integer) samples as passed
    /// in a Printable instance.

    pub fn print_common_i64(&self, printer: &mut dyn Printer) {
        Self::print_integer("Count", self.n as i64, printer);

        if self.n > 0 {
            let mode_value = 1_i64 << self.log_mode.abs();
            let mode_value = mode_value - (mode_value / 4);

            let mode_value =
                if self.log_mode < 0 {
                    -mode_value
                } else {
                    mode_value
                };

            Self::print_integer_units("Minimum",    self.min_i64,  printer, &self.units);
            Self::print_integer_units("Maximum",    self.max_i64,  printer, &self.units);
            Self::print_integer      ("Log Mode",   self.log_mode, printer             );
            Self::print_integer_units("Mode Value", mode_value,    printer, &self.units);
        }
    }

    /// Prints the common statistics for f64 (float) samples as passed
    /// in a Printable instance.

    pub fn print_common_f64(&self, printer: &mut dyn Printer) {
        Self::print_integer("Count",      self.n          as i64, printer);
        Self::print_integer("NaNs",       self.nans       as i64, printer);
        Self::print_integer("Infinities", self.infinities as i64, printer);

        if self.n > 0 {
            Self::print_float_units("Minimum",     self.min_f64,    printer, &self.units);
            Self::print_float_units("Maximum",     self.max_f64,    printer, &self.units);
            Self::print_float_units("Mode Value",  self.mode_value, printer, &self.units);
        }
    }

    /// Prints the common float statistics as passed in a Printable instance.
    /// This includes values like the mean.

    pub fn print_common_float(&self, printer: &mut dyn Printer) {
        if self.n > 0 {
            Self::print_float_units("Mean",     self.mean,            printer, &self.units);
            Self::print_float_units("Std Dev",  self.variance.sqrt(), printer, &self.units);
            Self::print_float      ("Variance", self.variance,        printer             );
            Self::print_float      ("Skewness", self.skewness,        printer             );
            Self::print_float      ("Kurtosis", self.kurtosis,        printer             );
        }
    }

    /// Converts the pseudo-log mode of a time-based histogram
    /// into an approximate time for the bucket.  Note that this
    /// approximation can be bigger than the maximum value since
    /// the pseudo-log function rounds up.

    pub fn log_mode_to_time(&self) -> f64 {
        // Time values should never be negative...

        if self.log_mode < 0 {
            return 0.0;
        }

        let log   = self.log_mode.abs();
        let base  = 2_u64;
        let ticks = base.pow(log as u32);
        let ticks = ticks - (ticks / 4);

        ticks as f64
    }

    /// Prints integer values that are in time units as actual times. The
    /// mode of the pseudo-log is an exception.

    pub fn print_common_integer_times(&self, hz: i64, printer: &mut dyn Printer) {
        Self::print_integer("Count", self.n as i64, printer);

        if self.n > 0 {
            let approximation = self.log_mode_to_time();

            Self::print_time   ("Minimum",    self.min_i64 as f64, hz, printer);
            Self::print_time   ("Maximum",    self.max_i64 as f64, hz, printer);
            Self::print_integer("Log Mode",   self.log_mode,           printer);
            Self::print_time   ("Mode Value", approximation,       hz, printer);
        }
    }

    /// Prints the common f64 summary statistics for time samples.

    pub fn print_common_float_times(&self, hz: i64, printer: &mut dyn Printer) {
        if self.n > 0 {
            Self::print_time ("Mean",     self.mean,            hz, printer);
            Self::print_time ("Std Dev",  self.variance.sqrt(), hz, printer);
            Self::print_float("Variance", self.variance,            printer);
            Self::print_float("Skewness", self.skewness,            printer);
            Self::print_float("Kurtosis", self.kurtosis,            printer);
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::tests::CheckPrinter;

    pub fn test_commas() {
        let test   = [ 123456, 12, -1, -1234, 4000000, -200, -2000, -20000 ];

        let expect =
            [ "123,456", "12", "-1", "-1,234", "4,000,000", "-200", "-2,000", "-20,000" ];

        for i in 0..test.len() {
            println!("Test:  {} vs {}", Printable::commas_i64(test[i]), expect[i]);

            assert_eq!(Printable::commas_i64(test[i]), expect[i]);
        }

        assert_eq!(Printable::commas(    "+21"),      "+21");
        assert_eq!(Printable::commas(   "+212"),     "+212");
        assert_eq!(Printable::commas(  "+2123"),   "+2,123");
        assert_eq!(Printable::commas( "+21234"),  "+21,234");
        assert_eq!(Printable::commas("+212345"), "+212,345");

        assert_eq!(Printable::commas(     "12"),       "12");
        assert_eq!(Printable::commas(    "123"),      "123");
        assert_eq!(Printable::commas(   "2345"),    "2,345");
        assert_eq!(Printable::commas(  "23456"),   "23,456");
        assert_eq!(Printable::commas( "345678"),  "345,678");

        assert_eq!(Printable::commas(    "+12"),      "+12");
        assert_eq!(Printable::commas(   "+123"),     "+123");
        assert_eq!(Printable::commas(  "+2345"),   "+2,345");
        assert_eq!(Printable::commas( "+23456"),  "+23,456");
        assert_eq!(Printable::commas("+345678"), "+345,678");

        assert_eq!(Printable::commas(    "-12"),      "-12");
        assert_eq!(Printable::commas(   "-123"),     "-123");
        assert_eq!(Printable::commas(  "-2345"),   "-2,345");
        assert_eq!(Printable::commas( "-23456"),  "-23,456");
        assert_eq!(Printable::commas("-345678"), "-345,678");

        assert_eq!(Printable::commas(    "+20"),      "+20");
        assert_eq!(Printable::commas(   "+200"),     "+200");
        assert_eq!(Printable::commas(  "+2000"),   "+2,000");
        assert_eq!(Printable::commas( "+20000"),  "+20,000");
        assert_eq!(Printable::commas("+200000"), "+200,000");

        assert_eq!(Printable::commas(    "-20"),      "-20");
        assert_eq!(Printable::commas(   "-200"),     "-200");
        assert_eq!(Printable::commas(  "-2000"),   "-2,000");
        assert_eq!(Printable::commas( "-20000"),  "-20,000");
        assert_eq!(Printable::commas("-200000"), "-200,000");
    }

    fn test_log_mode_to_time() {
        let n          =  100;
        let nans       =    0;
        let infinities =    0;
        let min_i64    =    1;
        let max_i64    = 1000;
        let min_f64    =    1.0;
        let max_f64    = 1000.0;
        let mode_value =  2.0;
        let log_mode   =   32;

        let mean       = 10.0;
        let variance   = 10.0;
        let skewness   = -4.0;
        let kurtosis   = 10.0;

        let base       = 2 as u64;
        let expected   = base.pow(log_mode as u32) as f64;
        let expected   = expected - expected / 4.0;
        let units      = Units::default();

        let mut printable =
            Printable {
                n,           nans,      infinities,  min_i64,   max_i64,   min_f64,
                max_f64,     log_mode,  mean,        variance,  skewness,  kurtosis,
                mode_value,  units
            };

        println!("test_log_mode_to_time:  got {}, expected {}",
             printable.log_mode_to_time(), expected);

        assert!(printable.log_mode_to_time() == expected);

        // Negative times aren't actually possible, do a sanity test.

        printable.log_mode = -printable.log_mode;

        assert!(printable.log_mode_to_time() == 0.0);

        printable.log_mode = 63;

        let base     = 2 as u64;
        let expected = base.pow(63) as f64;
        let expected   = expected - expected / 4.0;

        assert!(printable.log_mode_to_time() == expected);
    }

    fn documentation() {
        let hz       = 1_000_000_000;
        let second   = hz as f64;
        let ms       = second / 1000.0;
        let us       = second / 1000_000.0;
        let ns       = second / 1_000_000_000.0;
        let minute   = second * 60.0;
        let hour     = minute * 60.0;
        let day      = 24.0 * hour;
        let week     = day * 7.0;

        let examples =
            [
                (            1.0,     1.0,  "nanosecond"  ),
                (          100.0,   100.0,  "nanoseconds" ),
                (          102.4,   102.4,  "nanoseconds" ),
                (        1_000.0,     1.0,  "microsecond" ),
                (        1_200.0,     1.2,  "microseconds"),
                (       29_000.0,    29.0,  "microseconds"),
                (    1_000_000.0,     1.0,  "millisecond" ),
                (   29_000_000.0,    29.0,  "milliseconds"),

                (us     - ns,       999.0,  "nanoseconds" ),
                (ms     - us,       999.0,  "microseconds"),
                (second - ms,       999.0,  "milliseconds"),
                (minute - second,    59.0,  "seconds"     ),
                (hour   - minute,    59.0,  "minutes"     ),
                (day    - hour,      23.0,  "hours"       ),

                (   3.0 * second,     3.0,  "seconds"     ),
                (   3.0 * second,     3.0,  "seconds"     ),
                (   1.5 * second,     1.5,  "seconds"     ),
                (  42.0 * second,    42.0,  "seconds"     ),
                ( 999.0 * day,      999.0,  "days"        ),
                (  12.6 * hour,      12.6,  "hours"       ),
                (         week,       7.0,  "days"        ),

                (         second,     1.0,  "second"      ),
                (   2.0 * second,     2.0,  "seconds"     ),
                (         minute,     1.0,  "minute"      ),
                (   2.0 * minute,     2.0,  "minutes"     ),
                (         hour,       1.0,  "hour"        ),
                (   2.0 * hour,       2.0,  "hours"       ),
                (         day,        1.0,  "day"         ),
                (   2.0 * day,        2.0,  "days"        ),
            ];

        for example in examples {
            let (ticks, time, unit) = example;

            let (result_time, result_unit) = Printable::scale_time(ticks, hz);

            println!("documentation:  expect ({} {}) from {}, got ({} {})",
                time, unit,
                ticks,
                result_time, result_unit
            );

            assert!(result_time  == time);
            assert!(result_unit  == unit);
        }
    }

    fn test_format_float() {
        let billion = 1000.0 as f64 * 1000.0 * 1000.0;

        let test_values =
            [
                   0.0,
                   1.0,
                   2.0,
                   3.00005,
                   3.000005,
                1000.0,
                 999.0,
                   1.0 * billion,
                  10.0 * billion,

                  -0.0,
                  -1.0,
                  -2.0,
                  -3.00005,
                  -3.000005,
               -1000.0,
                -999.0,
                  -1.0 * billion,
                 -10.0 * billion
            ];

        let expected =
            [
                "+0.00000 e+0 ",
                "+1.00000 e+0 ",
                "+2.00000 e+0 ",
                "+3.00005 e+0 ",
                "+3.00000 e+0 ",
                "+1.00000 e+3 ",
                "+9.99000 e+2 ",
                "+1.00000 e+9 ",
                "+1.00000 e+10",

                "-0.00000 e+0 ",
                "-1.00000 e+0 ",
                "-2.00000 e+0 ",
                "-3.00005 e+0 ",
                "-3.00000 e+0 ",
                "-1.00000 e+3 ",
                "-9.99000 e+2 ",
                "-1.00000 e+9 ",
                "-1.00000 e+10"
            ];

        for i in 0..test_values.len() {
            let (mantissa, exponent) = Printable::format_float(test_values[i]);

            let mut result = mantissa.clone();

            result.push_str(" ");
            result.push_str(&exponent);

            println!("test_format_float:  got (\"{}\", \"{}\") -> \"{}\", expected \"{}\" for {}",
                mantissa, exponent, result, expected[i], test_values[i]);

            assert!(result == expected[i]);
        }
    }

    fn test_print_time() {
        let     expected      = [ "    >                +1.00000 e+6  days" ];
        let mut check_printer = CheckPrinter::new(&expected, false, false);

        let     hz     = 1;
        let     days   = 60 * 60 * 24 * hz;
        let     sample = 1_000_000 * days;
        let     sample = sample as f64;

        Printable::print_time(">", sample, hz, &mut check_printer);
    }

    #[test]
    fn run_tests() {
        test_commas          ();
        test_log_mode_to_time();
        test_format_float    ();
        test_print_time      ();
        documentation        ();
    }
}