benford

This crate provides a way to test of some given set of numbers conforms to Benford's law

Currently, only the first digit is being used. You can use your own method of mapping a number to a digit, by implementing [BenfordClass]

Example 1: Fibonacci numbers are Benford

```rust use benford::{BenfordTester, FirstDigitBase10}; use num::CheckedAdd;

struct Fibonacci(D, D) where D: CheckedAdd + Copy + From ;

impl Iterator for Fibonacci where D: CheckedAdd + Copy + From , { type Item = D;

fn next(&mut self) -> Option<Self::Item> {
    let res = self.0;
    self.0 = self.1;
    self.1 = match self.1.checked_add(&res) {
        Some(sum) => sum,
        None => return None,
    };
    Some(res)
}

}

impl Default for Fibonacci where D: CheckedAdd + Copy + From { fn default() -> Self { Self(0.into(), 1.into()) } }

let mut tester = BenfordTester::default(); let mut fibonacci = Fibonacci::::default(); for val in fibonacci { if val != 0 { tester.addsample::(val.into()); } } assert!(tester.isbenford()); ```

Example 2: Natural numbers are not Benford

```rust use benford::{BenfordTester, FirstDigitBase10};

let mut tester = BenfordTester::default(); for val in 1..u16::MAX { tester.addsample::(val.into()); } assert!(! tester.isbenford()) ```

License: GPL-3.0