Skip to content

Commit

Permalink
Auto merge of #115412 - eswartz:docs/total_cmp-test-result-in-docs, r…
Browse files Browse the repository at this point in the history
…=scottmcm

Expose tests for {f32,f64}.total_cmp in docs

Expose tests for {f32,f64}.total_cmp in docs

Uncomment the helpful `assert_eq!` line, which is stripped out completely in docs, and leaves the reader to mentally play through the algorithm, or go to the playground and add a println!, to see what the result will be.

(If these tests are known to fail on some platforms, is there some mechanism to conditionalize this or escape the test so the `assert_eq!` source will be visible on the web? I am a newbie, which is why I was reading docs ;)
  • Loading branch information
bors committed Nov 18, 2023
2 parents 61d3b26 + 8066079 commit 6416e2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,17 @@ impl f32 {
/// ];
///
/// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
/// # assert!(bois.into_iter().map(|b| b.weight)
/// # .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
///
/// // `f32::NAN` could be positive or negative, which will affect the sort order.
/// if f32::NAN.is_sign_negative() {
/// assert!(bois.into_iter().map(|b| b.weight)
/// .zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// } else {
/// assert!(bois.into_iter().map(|b| b.weight)
/// .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// }
/// ```
#[stable(feature = "total_cmp", since = "1.62.0")]
#[must_use]
Expand Down
14 changes: 11 additions & 3 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,17 @@ impl f64 {
/// ];
///
/// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
/// # assert!(bois.into_iter().map(|b| b.weight)
/// # .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
///
/// // `f64::NAN` could be positive or negative, which will affect the sort order.
/// if f64::NAN.is_sign_negative() {
/// assert!(bois.into_iter().map(|b| b.weight)
/// .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// } else {
/// assert!(bois.into_iter().map(|b| b.weight)
/// .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// }
/// ```
#[stable(feature = "total_cmp", since = "1.62.0")]
#[must_use]
Expand Down

0 comments on commit 6416e2e

Please sign in to comment.