Test SafeSub with int
| 124 | |
| 125 | // Test SafeSub with int |
| 126 | void TestSafeSubInt() |
| 127 | { |
| 128 | int result; |
| 129 | |
| 130 | // Test normal subtraction |
| 131 | test::require(args::SafeSub<int>(100, 50, result)); |
| 132 | test::require(result == 50); |
| 133 | std::cout << "PASS: SafeSub int normal case (100 - 50 = 50)" << std::endl; |
| 134 | |
| 135 | // Test subtraction with negative result |
| 136 | test::require(args::SafeSub<int>(50, 100, result)); |
| 137 | test::require(result == -50); |
| 138 | std::cout << "PASS: SafeSub int negative result (50 - 100 = -50)" << std::endl; |
| 139 | |
| 140 | // Test underflow detection |
| 141 | test::require_false(args::SafeSub<int>(std::numeric_limits<int>::min(), 1, result)); |
| 142 | std::cout << "PASS: SafeSub int underflow detection (INT_MIN - 1)" << std::endl; |
| 143 | |
| 144 | // Test overflow detection (negative subtraction) |
| 145 | test::require_false(args::SafeSub<int>(std::numeric_limits<int>::max(), -1, result)); |
| 146 | std::cout << "PASS: SafeSub int overflow detection (INT_MAX - (-1))" << std::endl; |
| 147 | } |
| 148 | |
| 149 | // Test SafeSub with unsigned int |
| 150 | void TestSafeSubUnsigned() |