Skip to content

Instantly share code, notes, and snippets.

@inamiy
Created April 6, 2019 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inamiy/bd7d82a77a4df70b3b4a367a2d014ca9 to your computer and use it in GitHub Desktop.
Save inamiy/bd7d82a77a4df70b3b4a367a2d014ca9 to your computer and use it in GitHub Desktop.
ReactiveSwift flipflop test
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