File: duration.rs

package info (click to toggle)
rust-datetime 0.5.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 728 kB
  • sloc: ruby: 18; makefile: 6
file content (67 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download | duplicates (3)
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
extern crate datetime;
pub use datetime::Duration;


mod addition {
    use super::*;

    #[test]
    fn simple() {
        assert_eq!(Duration::of(10), Duration::of(2) + Duration::of(8))
    }

    #[test]
    fn milliseconds() {
        assert_eq!(Duration::of_ms(0, 500), Duration::of_ms(0, 167) + Duration::of_ms(0, 333))
    }

    #[test]
    fn wrapping() {
        assert_eq!(Duration::of_ms(1, 500), Duration::of_ms(0, 750) + Duration::of_ms(0, 750))
    }

    #[test]
    fn wrapping_exact() {
        assert_eq!(Duration::of(1), Duration::of_ms(0, 500) + Duration::of_ms(0, 500))
    }
}


mod subtraction {
    use super::*;

    #[test]
    fn simple() {
        assert_eq!(Duration::of(13), Duration::of(28) - Duration::of(15))
    }

    #[test]
    fn milliseconds() {
        assert_eq!(Duration::of_ms(0, 300), Duration::of_ms(0, 950) - Duration::of_ms(0, 650))
    }

    #[test]
    fn wrapping() {
        assert_eq!(Duration::of_ms(0, 750), Duration::of_ms(1, 500) - Duration::of_ms(0, 750))
    }

    #[test]
    fn wrapping_exact() {
        assert_eq!(Duration::of(1), Duration::of_ms(1, 500) - Duration::of_ms(0, 500))
    }
}


mod multiplication {
    use super::*;

    #[test]
    fn simple() {
        assert_eq!(Duration::of(16), Duration::of(8) * 2)
    }

    #[test]
    fn milliseconds() {
        assert_eq!(Duration::of(1), Duration::of_ms(0, 500) * 2)
    }
}