lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 8f5b6960 04/10: Demonstrate object sizes in u


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 8f5b6960 04/10: Demonstrate object sizes in unit test
Date: Mon, 20 Jun 2022 19:16:21 -0400 (EDT)

branch: master
commit 8f5b696046676129b5ba3f0e9666d0260c1a560c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Demonstrate object sizes in unit test
    
    These tests cannot fail; their purpose is to demonstrate the sizes of
    the argument and return value of u_abs() in different cases.
---
 math_functions_test.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index f9b78fa3..cf561463 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -32,6 +32,7 @@
 
 #include <algorithm>                    // min()
 #include <cfloat>                       // DBL_EPSILON
+#include <climits>                      // CHAR_BIT
 #include <cmath>                        // fabs(), isnan(), pow()
 #include <cstdint>
 #include <iomanip>
@@ -591,11 +592,17 @@ void test_u_abs()
     std::uint8_t additive_inverse_of_int8_min {u_abs(int8_min)};
     LMI_TEST_EQUAL(128U, additive_inverse_of_int8_min);
 
-    LMI_TEST_EQUAL(128U, u_abs(int8_min));
+    static_assert(8 == CHAR_BIT);
+
+    LMI_TEST_EQUAL  (1   , sizeof       int8_min );
+    LMI_TEST_EQUAL  (1   , sizeof u_abs(int8_min));
+    LMI_TEST_EQUAL  (128U,        u_abs(int8_min));
 
     // Incidentally, INT8_MIN is not of type std::int8_t, because it
     // is converted according to the integer promotions.
-    LMI_TEST_EQUAL(128U, u_abs(INT8_MIN));
+    LMI_TEST_UNEQUAL(1   , sizeof       INT8_MIN );
+    LMI_TEST_UNEQUAL(1   , sizeof u_abs(INT8_MIN));
+    LMI_TEST_EQUAL  (128U,        u_abs(INT8_MIN));
 
     // Test all 256 possibilities.
     for(std::int16_t j = int8_min; j <= int8_max; ++j)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]