Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tuple comparison tests #59393

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions src/libcore/tests/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cmp::Ordering::{Equal, Less, Greater};
use std::f64::NAN;

#[test]
fn test_clone() {
Expand All @@ -8,18 +9,18 @@ fn test_clone() {
}

#[test]
fn test_tuple_cmp() {
fn test_partial_eq() {
let (small, big) = ((1, 2, 3), (3, 2, 1));

let nan = 0.0f64/0.0;

// PartialEq
assert_eq!(small, small);
assert_eq!(big, big);
assert!(small != big);
assert!(big != small);
assert_ne!(small, big);
assert_ne!(big, small);
}

#[test]
fn test_partial_ord() {
let (small, big) = ((1, 2, 3), (3, 2, 1));

// PartialOrd
assert!(small < big);
assert!(!(small < small));
assert!(!(big < small));
Expand All @@ -33,18 +34,21 @@ fn test_tuple_cmp() {
assert!(big >= small);
assert!(big >= big);

assert!(!((1.0f64, 2.0f64) < (nan, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (nan, 3.0)));
assert!(!((1.0f64, 2.0f64) > (nan, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (nan, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, nan)));
assert!(!((2.0f64, 2.0f64) < (2.0, nan)));

// Ord
assert!(small.cmp(&small) == Equal);
assert!(big.cmp(&big) == Equal);
assert!(small.cmp(&big) == Less);
assert!(big.cmp(&small) == Greater);
assert!(!((1.0f64, 2.0f64) < (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, NAN)));
}

#[test]
fn test_ord() {
let (small, big) = ((1, 2, 3), (3, 2, 1));
assert_eq!(small.cmp(&small), Equal);
assert_eq!(big.cmp(&big), Equal);
assert_eq!(small.cmp(&big), Less);
assert_eq!(big.cmp(&small), Greater);
}

#[test]
Expand Down