Skip to content

Commit 573489a

Browse files
committed
Fix Float shrinker skipping some values
1 parent 7d1709b commit 573489a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Sources/PropertyBased/Shrink+Float.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension Shrink {
2525
current = bound
2626
end = from
2727

28-
leap = (from / 2) - (bound / 2)
28+
leap = from - bound
2929
if leap.isNaN {
3030
current = .nan
3131
} else if leap.isInfinite {

Tests/PropertyBasedTests/ShrinkTests+Float.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import Testing
2424
try #require(results.count > 1)
2525
#expect(results.first == end)
2626
#expect(!results.contains(start))
27+
28+
if start > end {
29+
#expect(results.allSatisfy { $0 >= end })
30+
} else {
31+
#expect(results.allSatisfy { $0 <= end })
32+
}
2733
}
2834

2935
@Test func testShrinkWithNan() throws {
@@ -51,5 +57,9 @@ import Testing
5157

5258
let shrink5 = (20).shrink(within: 1.5...10)
5359
#expect(shrink5.current == 1.5)
60+
61+
var shrink6 = (10.0).shrink(towards: 0)
62+
_ = shrink6.next()
63+
#expect(shrink6.current == 5)
5464
}
5565
}

0 commit comments

Comments
 (0)