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
pub mod timehash;

#[cfg(test)]
mod tests {
    #[test]
    fn timehash_encode() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::encode(1487708113.0, 10).unwrap(), "afcccc0e1b");
        Ok(())
    }

    #[test]
    fn timehash_encode_precision_length() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::encode(1487708113.0, 10)?.len(), 10);
        Ok(())
    }

    #[test]
    fn timehash_decode() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::decode("afcccc0e1b")?, 1487708111.2923145);
        Ok(())
    }

    #[test]
    fn timehash_before() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::before("afcccc0e1b")?, "afcccc0e1a");
        assert_eq!(timehash::before("afcccc0e1a")?, "afcccc0e11");
        assert_eq!(timehash::before("afcccc0e10")?, "afcccc0e0f");
        Ok(())
    }

    #[test]
    fn timehash_after() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::after("afcccc0e0f")?, "afcccc0e10");
        assert_eq!(timehash::after("afcccc0e1a")?, "afcccc0e1b");
        assert_eq!(timehash::after("afcccc0e1b")?, "afcccc0e1c");
        Ok(())
    }

    #[test]
    fn timehash_neighbors() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::neighbors("afcccc0e0f")?, ("afcccc0e0e".to_string(), "afcccc0e10".to_string()));
        Ok(())
    }

    #[test]
    fn timehash_expand() -> Result<(), String> {
        use timehash;
        assert_eq!(timehash::expand("afcccc0e0f")?, ("afcccc0e0e".to_string(), "afcccc0e0f".to_string(), "afcccc0e10".to_string()));
        Ok(())
    }
}