⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 241247 in webkit


Ignore:
Timestamp:
Feb 9, 2019, 4:41:55 PM (8 years ago)
Author:
benjamin@webkit.org
Message:

Add more tests for clampTo<>()
https://bugs.webkit.org/show_bug.cgi?id=194462

Reviewed by Geoffrey Garen.

Darin suggested to test the very last floating point number
at the boundaries when truncating to integer.
I added test for max/min and max-1/min-1.

  • TestWebKitAPI/Tests/WTF/MathExtras.cpp:

(TestWebKitAPI::TEST):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r241245 r241247  
     12019-02-09  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Add more tests for clampTo<>()
     4        https://bugs.webkit.org/show_bug.cgi?id=194462
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Darin suggested to test the very last floating point number
     9        at the boundaries when truncating to integer.
     10        I added test for max/min and max-1/min-1.
     11
     12        * TestWebKitAPI/Tests/WTF/MathExtras.cpp:
     13        (TestWebKitAPI::TEST):
     14
    1152019-02-09  Darin Adler  <darin@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp

    r241192 r241247  
    319319    EXPECT_EQ(clampTo<int32_t>(static_cast<double>(9007199254740992)), std::numeric_limits<int32_t>::max());
    320320    EXPECT_EQ(clampTo<int32_t>(static_cast<double>(9007199254740993)), std::numeric_limits<int32_t>::max());
     321
     322    // Test the double at the edge of max/min and max-1/min+1.
     323    double intMax = static_cast<double>(std::numeric_limits<int32_t>::max());
     324    EXPECT_EQ(clampTo<int32_t>(intMax), std::numeric_limits<int32_t>::max());
     325    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax, 0)), std::numeric_limits<int32_t>::max() - 1);
     326    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax, std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::max());
     327
     328    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax - 1., 0)), std::numeric_limits<int32_t>::max() - 2);
     329    EXPECT_EQ(clampTo<int32_t>(intMax - 1), std::numeric_limits<int32_t>::max() - 1);
     330    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax - 1., std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::max() - 1);
     331
     332    double intMin = static_cast<double>(std::numeric_limits<int32_t>::min());
     333    EXPECT_EQ(clampTo<int32_t>(intMin), std::numeric_limits<int32_t>::min());
     334    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin, 0)), std::numeric_limits<int32_t>::min() + 1);
     335    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin, -std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::min());
     336
     337    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin + 1, 0)), std::numeric_limits<int32_t>::min() + 2);
     338    EXPECT_EQ(clampTo<int32_t>(intMin + 1), std::numeric_limits<int32_t>::min() + 1);
     339    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin + 1, -std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::min() + 1);
    321340}
    322341
Note: See TracChangeset for help on using the changeset viewer.