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
pub mod ilds;
pub mod lds;
pub mod lds_n;

pub use crate::lds::PRIME_TABLE;
pub use crate::lds::{Circle, Halton, Sphere, Sphere3Hopf, VdCorput};
pub use crate::lds_n::HaltonN;

#[cfg(test)]
mod tests {
    use super::lds::*;
    use super::lds_n::*;
    use approx_eq::assert_approx_eq;

    #[test]
    fn it_works() {
        let base: [usize; 5] = [2, 3, 5, 7, 11];

        let mut vgen = VdCorput::new(2);
        vgen.reseed(10);
        for _i in 0..10 {
            println!("{}", vgen.pop());
        }
        let res = vgen.pop();
        assert_approx_eq!(res, 0.65625);

        let mut cgen = Circle::new(2);
        cgen.reseed(10);
        for _i in 0..10 {
            println!("{:?}", cgen.pop());
        }
        let res = cgen.pop();
        assert_approx_eq!(res[0], -0.8314696123025452);

        let mut hgen = Halton::new(2, 3);
        hgen.reseed(10);
        for _i in 0..10 {
            println!("{:?}", hgen.pop());
        }
        let res = hgen.pop();
        assert_approx_eq!(res[0], 0.65625);

        let mut sgen = Sphere::new(&base);
        sgen.reseed(10);
        for _i in 0..10 {
            println!("{:?}", sgen.pop());
        }
        let res = sgen.pop();
        assert_approx_eq!(res[0], 0.8722297870746605);

        let mut s3fgen = Sphere3Hopf::new(&base);
        s3fgen.reseed(10);
        for _i in 0..10 {
            println!("{:?}", s3fgen.pop());
        }
        let res = s3fgen.pop();
        assert_approx_eq!(res[0], 0.23764785962349413);

        let mut hgen = HaltonN::new(5, &PRIME_TABLE);
        hgen.reseed(10);
        for _i in 0..10 {
            println!("{:?}", hgen.pop_vec());
        }
        let res = hgen.pop_vec();
        assert_approx_eq!(res[0], 0.65625);
    }
}