|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
| 11 | +//! Temporal quantification. |
| 12 | +
|
| 13 | +#![stable(feature = "time", since = "1.3.0")] |
| 14 | + |
11 | 15 | use ops::{Add, Sub, Mul, Div};
|
12 | 16 |
|
13 | 17 | const NANOS_PER_SEC: u32 = 1_000_000_000;
|
@@ -154,81 +158,3 @@ impl Div<u32> for Duration {
|
154 | 158 | Duration { secs: secs, nanos: nanos }
|
155 | 159 | }
|
156 | 160 | }
|
157 |
| - |
158 |
| -#[cfg(test)] |
159 |
| -mod tests { |
160 |
| - use super::Duration; |
161 |
| - |
162 |
| - #[test] |
163 |
| - fn creation() { |
164 |
| - assert!(Duration::from_secs(1) != Duration::from_secs(0)); |
165 |
| - assert_eq!(Duration::from_secs(1) + Duration::from_secs(2), |
166 |
| - Duration::from_secs(3)); |
167 |
| - assert_eq!(Duration::from_millis(10) + Duration::from_secs(4), |
168 |
| - Duration::new(4, 10 * 1_000_000)); |
169 |
| - assert_eq!(Duration::from_millis(4000), Duration::new(4, 0)); |
170 |
| - } |
171 |
| - |
172 |
| - #[test] |
173 |
| - fn secs() { |
174 |
| - assert_eq!(Duration::new(0, 0).as_secs(), 0); |
175 |
| - assert_eq!(Duration::from_secs(1).as_secs(), 1); |
176 |
| - assert_eq!(Duration::from_millis(999).as_secs(), 0); |
177 |
| - assert_eq!(Duration::from_millis(1001).as_secs(), 1); |
178 |
| - } |
179 |
| - |
180 |
| - #[test] |
181 |
| - fn nanos() { |
182 |
| - assert_eq!(Duration::new(0, 0).subsec_nanos(), 0); |
183 |
| - assert_eq!(Duration::new(0, 5).subsec_nanos(), 5); |
184 |
| - assert_eq!(Duration::new(0, 1_000_000_001).subsec_nanos(), 1); |
185 |
| - assert_eq!(Duration::from_secs(1).subsec_nanos(), 0); |
186 |
| - assert_eq!(Duration::from_millis(999).subsec_nanos(), 999 * 1_000_000); |
187 |
| - assert_eq!(Duration::from_millis(1001).subsec_nanos(), 1 * 1_000_000); |
188 |
| - } |
189 |
| - |
190 |
| - #[test] |
191 |
| - fn add() { |
192 |
| - assert_eq!(Duration::new(0, 0) + Duration::new(0, 1), |
193 |
| - Duration::new(0, 1)); |
194 |
| - assert_eq!(Duration::new(0, 500_000_000) + Duration::new(0, 500_000_001), |
195 |
| - Duration::new(1, 1)); |
196 |
| - } |
197 |
| - |
198 |
| - #[test] |
199 |
| - fn sub() { |
200 |
| - assert_eq!(Duration::new(0, 1) - Duration::new(0, 0), |
201 |
| - Duration::new(0, 1)); |
202 |
| - assert_eq!(Duration::new(0, 500_000_001) - Duration::new(0, 500_000_000), |
203 |
| - Duration::new(0, 1)); |
204 |
| - assert_eq!(Duration::new(1, 0) - Duration::new(0, 1), |
205 |
| - Duration::new(0, 999_999_999)); |
206 |
| - } |
207 |
| - |
208 |
| - #[test] #[should_panic] |
209 |
| - fn sub_bad1() { |
210 |
| - Duration::new(0, 0) - Duration::new(0, 1); |
211 |
| - } |
212 |
| - |
213 |
| - #[test] #[should_panic] |
214 |
| - fn sub_bad2() { |
215 |
| - Duration::new(0, 0) - Duration::new(1, 0); |
216 |
| - } |
217 |
| - |
218 |
| - #[test] |
219 |
| - fn mul() { |
220 |
| - assert_eq!(Duration::new(0, 1) * 2, Duration::new(0, 2)); |
221 |
| - assert_eq!(Duration::new(1, 1) * 3, Duration::new(3, 3)); |
222 |
| - assert_eq!(Duration::new(0, 500_000_001) * 4, Duration::new(2, 4)); |
223 |
| - assert_eq!(Duration::new(0, 500_000_001) * 4000, |
224 |
| - Duration::new(2000, 4000)); |
225 |
| - } |
226 |
| - |
227 |
| - #[test] |
228 |
| - fn div() { |
229 |
| - assert_eq!(Duration::new(0, 1) / 2, Duration::new(0, 0)); |
230 |
| - assert_eq!(Duration::new(1, 1) / 3, Duration::new(0, 333_333_333)); |
231 |
| - assert_eq!(Duration::new(99, 999_999_000) / 100, |
232 |
| - Duration::new(0, 999_999_990)); |
233 |
| - } |
234 |
| -} |
0 commit comments