MCPcopy Create free account
hub / github.com/Taywee/args / TestSafeMultiplyInt

Function TestSafeMultiplyInt

test/safe_arithmetic.cxx:105–123  ·  view source on GitHub ↗

Test SafeMultiply with int

Source from the content-addressed store, hash-verified

103
104// Test SafeMultiply with int
105void 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
126void TestSafeSubInt()

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected