Open kenthumphries opened 9 years ago
Busy writing simple tests as part of the CocoaPods Test Jam!
Created the following test:
- (void)testLocationInRangeMax { UInt64 midLocation = UINT64_MAX / 2; UInt64 maxLength = UINT64_MAX; DDRange maxRange = DDMakeRange(midLocation, maxLength); XCTAssertFalse(DDLocationInRange(midLocation + maxLength + 1, maxRange)); XCTAssertTrue(DDLocationInRange(midLocation, maxRange)); XCTAssertFalse(DDLocationInRange(midLocation - 1, maxRange)); XCTAssertFalse(DDLocationInRange(midLocation - 2, maxRange)); }
The first and last assertions will fail.
The third assertion passes only by chance.
=> DDLocationInRange(midLocation - 1, maxRange) => loc - range.location < range.length => midLocation -1 - midLocation < maxLength => (UINT64_MAX / 2) - 1 - (UINT64_MAX / 2) < UINT64_MAX => -1 < range.length => UINT64_MAX < UINT64_MAX // Since we're dealing with unsigned ints, -1 wraps back round to UNIT64_MAX => Return False
I won't commit this test as it will fail until DDRange is adjusted to take care of UINT64_MAX border cases. :)
Busy writing simple tests as part of the CocoaPods Test Jam!
Created the following test:
The first and last assertions will fail.
The third assertion passes only by chance.
I won't commit this test as it will fail until DDRange is adjusted to take care of UINT64_MAX border cases. :)