Test SafeMultiply with int
| 103 | |
| 104 | // Test SafeMultiply with int |
| 105 | void TestSafeMultiplyInt() |
| 106 | { |
| 107 | int result; |
| 108 | |
| 109 | // Test normal multiplication |
| 110 | test::require(args::SafeMultiply<int>(10, 20, result)); |
| 111 | test::require(result == 200); |
| 112 | std::cout << "PASS: SafeMultiply int normal case (10 * 20 = 200)" << std::endl; |
| 113 | |
| 114 | // Test multiplication overflow |
| 115 | int max_int = std::numeric_limits<int>::max(); |
| 116 | test::require_false(args::SafeMultiply<int>(max_int, 2, result)); |
| 117 | std::cout << "PASS: SafeMultiply int overflow detection (INT_MAX * 2)" << std::endl; |
| 118 | |
| 119 | // Test negative multiplication |
| 120 | test::require(args::SafeMultiply<int>(-10, 20, result)); |
| 121 | test::require(result == -200); |
| 122 | std::cout << "PASS: SafeMultiply int negative (-10 * 20 = -200)" << std::endl; |
| 123 | } |
| 124 | |
| 125 | // Test SafeSub with int |
| 126 | void TestSafeSubInt() |