apple / apple/swift-async-algorithms

Debounce behaving weirdly in proposed unit test

Open
#299 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
226
Avg merge
10d 3h
Merged PRs (30d)
1

Description

I'd like to propose this additional unit test for `debounce`, which I think should be fixed before the final 1.0.0 release:

```swift
func test_debounce() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"ab--cd-e-f---gh|"
$0.inputs[0].debounce(for: .steps(3), clock: $0.clock)
"------------f--[h|]"
}
}
```

The test currently fails as:
> ```
> failed - Validation failure:
> Expected:
> ------------f--[h|]
> Actual:
> ----b-------c--[dh|]
> ```

That actual output can't possibly be right, can it?

Side note, if it helps to debug this…

Curiously, the test passes if _only slightly_ tweaking the **input**:

```diff
-"ab--cd-e-f---gh|"
+"ab-c-d-e-f---gh|"
```

Contributor guide

Open the contributing guide

Research direction

Start with the proposed test_debounce case in issue #299 and run it with the input "ab--cd-e-f---gh|". Compare the expected and actual validation traces, then repeat with the slightly changed input from the issue to isolate the timing difference. Done means debounce produces the intended trace consistently and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.