|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 | 11 | use core::cmp::lexical_ordering;
|
| 12 | +use core::cmp::{ partial_min, partial_max }; |
12 | 13 |
|
13 | 14 | #[test]
|
14 | 15 | fn test_int_totalord() {
|
@@ -56,6 +57,72 @@ fn test_lexical_ordering() {
|
56 | 57 | }
|
57 | 58 | }
|
58 | 59 |
|
| 60 | +#[test] |
| 61 | +fn test_partial_min() { |
| 62 | + use core::f64::NAN; |
| 63 | + let data_integer = [ |
| 64 | + // a, b, result |
| 65 | + (0i, 0i, Some(0i)), |
| 66 | + (1i, 0i, Some(0i)), |
| 67 | + (0i, 1i, Some(0i)), |
| 68 | + (-1i, 0i, Some(-1i)), |
| 69 | + (0i, -1i, Some(-1i)) |
| 70 | + ]; |
| 71 | + |
| 72 | + let data_float = [ |
| 73 | + // a, b, result |
| 74 | + (0.0f64, 0.0f64, Some(0.0f64)), |
| 75 | + (1.0f64, 0.0f64, Some(0.0f64)), |
| 76 | + (0.0f64, 1.0f64, Some(0.0f64)), |
| 77 | + (-1.0f64, 0.0f64, Some(-1.0f64)), |
| 78 | + (0.0f64, -1.0f64, Some(-1.0f64)), |
| 79 | + (NAN, NAN, None), |
| 80 | + (NAN, 1.0f64, None), |
| 81 | + (1.0f64, NAN, None) |
| 82 | + ]; |
| 83 | + |
| 84 | + for &(a, b, result) in data_integer.iter() { |
| 85 | + assert!(partial_min(a, b) == result); |
| 86 | + } |
| 87 | + |
| 88 | + for &(a, b, result) in data_float.iter() { |
| 89 | + assert!(partial_min(a, b) == result); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +#[test] |
| 94 | +fn test_partial_max() { |
| 95 | + use core::f64::NAN; |
| 96 | + let data_integer = [ |
| 97 | + // a, b, result |
| 98 | + (0i, 0i, Some(0i)), |
| 99 | + (1i, 0i, Some(1i)), |
| 100 | + (0i, 1i, Some(1i)), |
| 101 | + (-1i, 0i, Some(0i)), |
| 102 | + (0i, -1i, Some(0i)) |
| 103 | + ]; |
| 104 | + |
| 105 | + let data_float = [ |
| 106 | + // a, b, result |
| 107 | + (0.0f64, 0.0f64, Some(0.0f64)), |
| 108 | + (1.0f64, 0.0f64, Some(1.0f64)), |
| 109 | + (0.0f64, 1.0f64, Some(1.0f64)), |
| 110 | + (-1.0f64, 0.0f64, Some(0.0f64)), |
| 111 | + (0.0f64, -1.0f64, Some(0.0f64)), |
| 112 | + (NAN, NAN, None), |
| 113 | + (NAN, 1.0f64, None), |
| 114 | + (1.0f64, NAN, None) |
| 115 | + ]; |
| 116 | + |
| 117 | + for &(a, b, result) in data_integer.iter() { |
| 118 | + assert!(partial_max(a, b) == result); |
| 119 | + } |
| 120 | + |
| 121 | + for &(a, b, result) in data_float.iter() { |
| 122 | + assert!(partial_max(a, b) == result); |
| 123 | + } |
| 124 | +} |
| 125 | + |
59 | 126 | #[test]
|
60 | 127 | fn test_user_defined_eq() {
|
61 | 128 | // Our type.
|
|
0 commit comments