Created
April 6, 2019 06:51
-
-
Save inamiy/bd7d82a77a4df70b3b4a367a2d014ca9 to your computer and use it in GitHub Desktop.
ReactiveSwift flipflop test
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
it("FlipFlop should work") { | |
let p = MutableProperty<Bool>(true) | |
let pInv = MutableProperty<Bool>(false) | |
let reset = MutableProperty<Bool>(false) | |
let set = MutableProperty<Bool>(false) | |
p <~ reset.producer.combineLatest(with: pInv.producer) | |
.map { !($0 || $1) } // NOR | |
.skipRepeats() | |
pInv <~ set.producer.combineLatest(with: p.producer) | |
.map { !($0 || $1) } // NOR | |
.skipRepeats() | |
print("===> reset = true") | |
reset.value = true | |
expect(p.value) == false | |
expect(pInv.value) == !p.value | |
print("===> reset = false") | |
reset.value = false | |
expect(p.value) == false | |
expect(pInv.value) == !p.value | |
print("===> set = true") | |
set.value = true | |
expect(p.value) == true | |
expect(pInv.value) == !p.value | |
print("===> set = false") | |
set.value = false | |
expect(p.value) == true | |
expect(pInv.value) == !p.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment