@@ -67,3 +67,47 @@ impl fmt::Debug for SignedDuration {
67
67
write ! ( f, "{:?}" , self . duration)
68
68
}
69
69
}
70
+
71
+ #[ cfg( test) ]
72
+ mod test {
73
+ use std:: time:: Duration ;
74
+ use super :: SignedDuration ;
75
+
76
+ #[ test]
77
+ fn op_subtract ( ) {
78
+ let zero_d = Duration :: from_nanos ( 0 ) ;
79
+ let one_d = Duration :: from_nanos ( 1 ) ;
80
+ let two_d = Duration :: from_nanos ( 2 ) ;
81
+
82
+ let zero_sd = SignedDuration :: from ( zero_d) ;
83
+ let one_sd = SignedDuration :: from ( one_d) ;
84
+ let neg_one_sd = SignedDuration { duration : one_d, is_positive : false } ;
85
+ let two_sd = SignedDuration :: from ( two_d) ;
86
+ let neg_two_sd = SignedDuration { duration : two_d, is_positive : false } ;
87
+
88
+ assert_eq ! ( zero_d, zero_sd. duration) ;
89
+ assert_eq ! ( true , zero_sd. is_positive) ;
90
+
91
+ assert_eq ! ( zero_sd, zero_sd - zero_sd) ;
92
+
93
+ assert_eq ! ( one_d, one_sd. duration) ;
94
+ assert_eq ! ( true , one_sd. is_positive) ;
95
+
96
+ assert_eq ! ( one_sd, one_sd - zero_sd) ;
97
+
98
+ assert_eq ! ( one_d, neg_one_sd. duration) ;
99
+ assert_eq ! ( false , neg_one_sd. is_positive) ;
100
+
101
+ assert_eq ! ( neg_one_sd, neg_one_sd - zero_sd) ;
102
+
103
+ assert_eq ! ( zero_sd, one_sd - one_sd) ;
104
+
105
+ assert_eq ! ( one_sd, two_sd - one_sd) ;
106
+
107
+ assert_eq ! ( neg_one_sd, one_sd - two_sd) ;
108
+
109
+ assert_eq ! ( neg_two_sd, neg_one_sd - one_sd) ;
110
+
111
+ assert_eq ! ( zero_sd, neg_one_sd - neg_one_sd) ;
112
+ }
113
+ }
0 commit comments