Skip to content

Commit

Permalink
Add test for panic in cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Jul 1, 2024
1 parent 11f0398 commit ce43e95
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions tests/evil.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
use std::num::FpCategory;
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
use num_traits::float::FloatCore;
use num_traits::{Num, NumCast, One, ToPrimitive, Zero};
use ordered_float::{NotNan};

#[derive(PartialOrd, PartialEq)]
struct EvilFloat(f32);

impl Zero for EvilFloat {
fn zero() -> Self {
todo!()
}

fn is_zero(&self) -> bool {
todo!()
}
}

impl Add for EvilFloat {
type Output = Self;

fn add(self, _: Self) -> Self::Output {
todo!()
}
}

impl One for EvilFloat {
fn one() -> Self {
todo!()
}
}

impl Mul for EvilFloat {
type Output = Self;

fn mul(self, _: Self) -> Self::Output {
todo!()
}
}

impl Sub for EvilFloat {
type Output = Self;

fn sub(self, _: Self) -> Self::Output {
todo!()
}
}

impl Div for EvilFloat {
type Output = Self;

fn div(self, _: Self) -> Self::Output {
todo!()
}
}

impl Rem for EvilFloat {
type Output = Self;

fn rem(self, _: Self) -> Self::Output {
todo!()
}
}

impl NumCast for EvilFloat {
fn from<T: ToPrimitive>(_: T) -> Option<Self> {
todo!()
}
}

impl ToPrimitive for EvilFloat {
fn to_i64(&self) -> Option<i64> {
todo!()
}

fn to_u64(&self) -> Option<u64> {
todo!()
}
}

impl Neg for EvilFloat {
type Output = Self;

fn neg(self) -> Self::Output {
todo!()
}
}

impl Copy for EvilFloat {}

impl Clone for EvilFloat {
fn clone(&self) -> Self {
todo!()
}
}

impl FloatCore for EvilFloat {
fn is_nan(self) -> bool {
false
}
fn infinity() -> Self { todo!() }
fn neg_infinity() -> Self { todo!() }
fn nan() -> Self { todo!() }
fn neg_zero() -> Self { todo!() }
fn min_value() -> Self { todo!() }
fn min_positive_value() -> Self { todo!() }
fn epsilon() -> Self { todo!() }
fn max_value() -> Self { todo!() }
fn classify(self) -> FpCategory { todo!() }
fn to_degrees(self) -> Self { todo!() }
fn to_radians(self) -> Self { todo!() }
fn integer_decode(self) -> (u64, i16, i8) { todo!() }

}

impl Num for EvilFloat {
type FromStrRadixErr = ();

fn from_str_radix(_: &str, _: u32) -> Result<Self, Self::FromStrRadixErr> {
todo!()
}
}

#[test]
#[should_panic]
fn test_cmp_panic() {
let evil_value = NotNan::new(EvilFloat(f32::NAN)).unwrap();
let x = NotNan::new(EvilFloat(0.0)).unwrap();
let _ = evil_value.cmp(&x);
}

0 comments on commit ce43e95

Please sign in to comment.