import XCTest @testable import FocusFixer final class DebounceTests: XCTestCase { func testFirstEventIsAlwaysProcessed() { var clockValue: TimeInterval = 0 var debouncer = Debouncer(interval: 0.15, clock: { clockValue }) XCTAssertTrue(debouncer.shouldProcess()) } func testEventWithinIntervalIsSuppressed() { var clockValue: TimeInterval = 0 var debouncer = Debouncer(interval: 0.15, clock: { clockValue }) XCTAssertTrue(debouncer.shouldProcess()) clockValue += 0.05 XCTAssertFalse(debouncer.shouldProcess()) } func testEventAfterIntervalIsProcessed() { var clockValue: TimeInterval = 0 var debouncer = Debouncer(interval: 0.15, clock: { clockValue }) XCTAssertTrue(debouncer.shouldProcess()) clockValue += 0.2 XCTAssertTrue(debouncer.shouldProcess()) } func testAcceptedEventResetsTheWindow() { var clockValue: TimeInterval = 0 var debouncer = Debouncer(interval: 0.15, clock: { clockValue }) XCTAssertTrue(debouncer.shouldProcess()) clockValue += 0.2 XCTAssertTrue(debouncer.shouldProcess()) clockValue += 0.05 XCTAssertFalse(debouncer.shouldProcess()) } }