googletest/matchers/
is_infinite_matcher.rs1use crate::{
16 description::Description,
17 matcher::{Matcher, MatcherBase, MatcherResult},
18};
19use num_traits::float::Float;
20use std::fmt::Debug;
21
22pub fn is_infinite() -> IsInfiniteMatcher {
24 IsInfiniteMatcher
25}
26
27#[derive(MatcherBase)]
28pub struct IsInfiniteMatcher;
29
30impl<T: Float + Debug + Copy> Matcher<T> for IsInfiniteMatcher {
31 fn matches(&self, actual: T) -> MatcherResult {
32 actual.is_infinite().into()
33 }
34
35 fn describe(&self, matcher_result: MatcherResult) -> Description {
36 if matcher_result.into() { "is Infinite" } else { "isn't Infinite" }.into()
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use crate::prelude::*;
43 use crate::Result;
44
45 #[test]
46 fn matches_f32_pos_infinity() -> Result<()> {
47 verify_that!(f32::INFINITY, is_infinite())
48 }
49
50 #[test]
51 fn matches_f32_neg_infinity() -> Result<()> {
52 verify_that!(f32::NEG_INFINITY, is_infinite())
53 }
54
55 #[test]
56 fn does_not_match_f32_number() -> Result<()> {
57 verify_that!(0.0f32, not(is_infinite()))
58 }
59
60 #[test]
61 fn does_not_match_f32_nan() -> Result<()> {
62 verify_that!(f32::NAN, not(is_finite()))
63 }
64
65 #[test]
66 fn matches_f64_pos_infinity() -> Result<()> {
67 verify_that!(f64::INFINITY, is_infinite())
68 }
69
70 #[test]
71 fn matches_f64_neg_infinity() -> Result<()> {
72 verify_that!(f64::NEG_INFINITY, is_infinite())
73 }
74
75 #[test]
76 fn does_not_match_f64_number() -> Result<()> {
77 verify_that!(0.0f64, not(is_infinite()))
78 }
79
80 #[test]
81 fn does_not_match_f64_nan() -> Result<()> {
82 verify_that!(f64::NAN, not(is_finite()))
83 }
84}