// Distance from the full range should always be zero. TEST_F(RangeTests, DistanceFrom_InfiniteRange) { const Range full(-kInf, kInf); EXPECT_EQ(0.0f, full.DistanceFrom(0.0f)); EXPECT_EQ(0.0f, full.DistanceFrom(1.0f)); // Note: Doesn't work when passing in kInf because kInf - kInf = NaN. // EXPECT_EQ(0.0f, full.DistanceFrom(kInf)); // EXPECT_EQ(0.0f, full.DistanceFrom(-kInf)); }
// Distance from the range should always be infinity for infinite values. TEST_F(RangeTests, DistanceFrom_Infinity) { const Range zero_one(0.0f, 1.0f); EXPECT_EQ(kInf, zero_one.DistanceFrom(kInf)); EXPECT_EQ(kInf, zero_one.DistanceFrom(-kInf)); }
// Distance from the range should be zero for elements on the border. TEST_F(RangeTests, DistanceFrom_Border) { const Range zero_one(0.0f, 1.0f); EXPECT_EQ(0.0f, zero_one.DistanceFrom(0.0f)); EXPECT_EQ(0.0f, zero_one.DistanceFrom(1.0f)); }
// Distance from the range should be match for elements outside the range. TEST_F(RangeTests, DistanceFrom_Outside) { const Range zero_one(0.0f, 1.0f); EXPECT_EQ(1.0f, zero_one.DistanceFrom(-1.0f)); EXPECT_NEAR(0.2f, zero_one.DistanceFrom(1.2f), 0.000001f); }
// Distance from the range should be zero for elements inside the range. TEST_F(RangeTests, DistanceFrom_Inside) { const Range zero_one(0.0f, 1.0f); EXPECT_EQ(0.0f, zero_one.DistanceFrom(0.0000001f)); EXPECT_EQ(0.0f, zero_one.DistanceFrom(0.5f)); EXPECT_EQ(0.0f, zero_one.DistanceFrom(0.9f)); }