Title: [241247] trunk/Tools
Revision
241247
Author
[email protected]
Date
2019-02-09 16:41:55 -0800 (Sat, 09 Feb 2019)

Log 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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (241246 => 241247)


--- trunk/Tools/ChangeLog	2019-02-09 23:16:01 UTC (rev 241246)
+++ trunk/Tools/ChangeLog	2019-02-10 00:41:55 UTC (rev 241247)
@@ -1,3 +1,17 @@
+2019-02-09  Benjamin Poulain  <[email protected]>
+
+        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):
+
 2019-02-09  Darin Adler  <[email protected]>
 
         Eliminate unnecessary String temporaries by using StringConcatenateNumbers

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp (241246 => 241247)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp	2019-02-09 23:16:01 UTC (rev 241246)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp	2019-02-10 00:41:55 UTC (rev 241247)
@@ -318,6 +318,25 @@
     EXPECT_EQ(clampTo<int32_t>(static_cast<double>(9007199254740991)), std::numeric_limits<int32_t>::max());
     EXPECT_EQ(clampTo<int32_t>(static_cast<double>(9007199254740992)), std::numeric_limits<int32_t>::max());
     EXPECT_EQ(clampTo<int32_t>(static_cast<double>(9007199254740993)), std::numeric_limits<int32_t>::max());
+
+    // Test the double at the edge of max/min and max-1/min+1.
+    double intMax = static_cast<double>(std::numeric_limits<int32_t>::max());
+    EXPECT_EQ(clampTo<int32_t>(intMax), std::numeric_limits<int32_t>::max());
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax, 0)), std::numeric_limits<int32_t>::max() - 1);
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax, std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::max());
+
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax - 1., 0)), std::numeric_limits<int32_t>::max() - 2);
+    EXPECT_EQ(clampTo<int32_t>(intMax - 1), std::numeric_limits<int32_t>::max() - 1);
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMax - 1., std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::max() - 1);
+
+    double intMin = static_cast<double>(std::numeric_limits<int32_t>::min());
+    EXPECT_EQ(clampTo<int32_t>(intMin), std::numeric_limits<int32_t>::min());
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin, 0)), std::numeric_limits<int32_t>::min() + 1);
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin, -std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::min());
+
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin + 1, 0)), std::numeric_limits<int32_t>::min() + 2);
+    EXPECT_EQ(clampTo<int32_t>(intMin + 1), std::numeric_limits<int32_t>::min() + 1);
+    EXPECT_EQ(clampTo<int32_t>(std::nextafter(intMin + 1, -std::numeric_limits<double>::max())), std::numeric_limits<int32_t>::min() + 1);
 }
 
 template<typename TargetType, typename SourceType>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to