This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add state-change-function support for syntax-sugar mapping
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 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
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,52 @@ | ||
// | ||
// StateFuncMappingSpec.swift | ||
// RxAutomaton | ||
// | ||
// Created by Yasuhiro Inami on 2016-11-26. | ||
// Copyright © 2016 Yasuhiro Inami. All rights reserved. | ||
// | ||
|
||
import RxSwift | ||
import RxTest | ||
import RxAutomaton | ||
import Quick | ||
import Nimble | ||
|
||
/// Tests for state-change function mapping. | ||
class StateFuncMappingSpec: QuickSpec | ||
{ | ||
override func spec() | ||
{ | ||
describe("State-change function mapping") { | ||
|
||
typealias Automaton = RxAutomaton.Automaton<CountState, CountInput> | ||
typealias NextMapping = Automaton.NextMapping | ||
|
||
let (signal, observer) = Observable<CountInput>.pipe() | ||
var automaton: Automaton? | ||
|
||
beforeEach { | ||
let mappings: [Automaton.NextMapping] = [ | ||
.increment | { $0 + 1 } | .empty(), | ||
.decrement | { $0 - 1 } | .empty(), | ||
] | ||
|
||
// strategy = `.merge` | ||
automaton = Automaton(state: 0, input: signal, mapping: reduce(mappings), strategy: .merge) | ||
} | ||
|
||
it("`.increment` and `.decrement` succeed") { | ||
expect(automaton?.state.value) == 0 | ||
observer.send(next: .increment) | ||
expect(automaton?.state.value) == 1 | ||
observer.send(next: .increment) | ||
expect(automaton?.state.value) == 2 | ||
observer.send(next: .decrement) | ||
expect(automaton?.state.value) == 1 | ||
observer.send(next: .decrement) | ||
expect(automaton?.state.value) == 0 | ||
} | ||
|
||
} | ||
} | ||
} |
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