-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ⚡ WIP * 🌲 Update * 🌲 Update * 🌲 Update
- Loading branch information
Showing
3 changed files
with
108 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Verge | ||
import XCTest | ||
|
||
final class EmitterTests: XCTestCase { | ||
|
||
func testOrder() { | ||
|
||
let emitter = EventEmitter<Int>() | ||
|
||
var results_1 = [Int]() | ||
emitter.add { value in | ||
results_1.append(value) | ||
|
||
if value == 1 { | ||
emitter.accept(2) | ||
} | ||
} | ||
|
||
var results_2 = [Int]() | ||
emitter.add { value in | ||
results_2.append(value) | ||
} | ||
|
||
emitter.accept(1) | ||
|
||
XCTAssertEqual(results_1, [1, 2]) | ||
XCTAssertEqual(results_2, [1, 2]) | ||
|
||
} | ||
|
||
func testEmitsAll() { | ||
|
||
let emitter = EventEmitter<Int>() | ||
|
||
emitter.add { value in | ||
} | ||
|
||
let outputs = VergeConcurrency.UnfairLockAtomic.init([Int]()) | ||
emitter.add { value in | ||
outputs.modify({ | ||
$0.append(value) | ||
}) | ||
} | ||
|
||
let inputs = VergeConcurrency.UnfairLockAtomic.init([Int]()) | ||
DispatchQueue.concurrentPerform(iterations: 500) { i in | ||
inputs.modify { | ||
$0.append(i) | ||
} | ||
emitter.accept(i) | ||
} | ||
|
||
XCTAssertEqual(outputs.value.count, 500) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters