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

Function TestSafeAddInt

test/safe_arithmetic.cxx:80–102  ·  view source on GitHub ↗

Test SafeAdd with int

Source from the content-addressed store, hash-verified

78
79// Test SafeAdd with int
80void TestSafeAddInt()
81{
82 int result;
83
84 // Test normal addition
85 test::require(args::SafeAdd<int>(100, 200, result));
86 test::require(result == 300);
87 std::cout << "PASS: SafeAdd int normal case (100 + 200 = 300)" << std::endl;
88
89 // Test negative number handling
90 test::require(args::SafeAdd<int>(-100, 50, result));
91 test::require(result == -50);
92 std::cout << "PASS: SafeAdd int with negative (-100 + 50 = -50)" << std::endl;
93
94 // Test negative operand underflow detection
95 test::require_false(args::SafeAdd<int>(std::numeric_limits<int>::min(), -1, result));
96 std::cout << "PASS: SafeAdd int underflow detection (INT_MIN + -1)" << std::endl;
97
98 // Test int overflow
99 int max_int = std::numeric_limits<int>::max();
100 test::require_false(args::SafeAdd<int>(max_int, 1, result));
101 std::cout << "PASS: SafeAdd int overflow detection (INT_MAX + 1)" << std::endl;
102}
103
104// Test SafeMultiply with int
105void TestSafeMultiplyInt()

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected