[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)
- [lmi-commits] [lmi] master updated (876d4b5b -> 50009ece), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e986f0c9 02/10: Specify types more explicitly in unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master a6f2830d 01/10: Explain the necessity of a certain cast, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 3c9845b4 06/10: State the purpose of a particular unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 8f5b6960 04/10: Demonstrate object sizes in unit test,
Greg Chicares <=
- [lmi-commits] [lmi] master 1744d568 07/10: Regularize every mention of nextafter(), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e711587c 08/10: Expunge a workaround for an obsolete compiler, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 168e9a70 03/10: Specify a constant more clearly, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 7258e4ae 05/10: Establish and test explicit postconditions, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 50009ece 10/10: x⋅(1+ε) ≢ nextafter(x) [264], Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e7278f90 09/10: Add some functions to complement std::nextafter(), Greg Chicares, 2022/06/20