1// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! Utilities for testing approximate ordering - especially true for
11//! floating point types, where NaN's cannot be ordered.
12
13pub fn min<T: PartialOrd>(x: T, y: T) -> T {
14 if x <= y {
15 x
16 } else {
17 y
18 }
19}
20
21pub fn max<T: PartialOrd>(x: T, y: T) -> T {
22 if x >= y {
23 x
24 } else {
25 y
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_min() {
35 assert!(min(0u32, 1u32) == 0u32);
36 assert!(min(-1.0f32, 0.0f32) == -1.0f32);
37 }
38
39 #[test]
40 fn test_max() {
41 assert!(max(0u32, 1u32) == 1u32);
42 assert!(max(-1.0f32, 0.0f32) == 0.0f32);
43 }
44}
45