[UPDATE] Tests

This commit is contained in:
Yannick Loriot 2015-11-12 19:21:13 +01:00
parent c2cee9866e
commit ca87c14af8
5 changed files with 54 additions and 7 deletions

View File

@ -430,6 +430,7 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
INFOPLIST_FILE = Splitflap/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -451,6 +452,7 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
INFOPLIST_FILE = Splitflap/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;

View File

@ -29,8 +29,8 @@ import XCTest
class TokenGeneratorTests: XCTestCase {
func testCurrentElement() {
let nilGenerator = TokenGenerator(tokens: [])
XCTAssertNil(nilGenerator.currentElement)
let emptyGenerator = TokenGenerator(tokens: [])
XCTAssertNil(emptyGenerator.currentElement)
let oneElementGenerator = TokenGenerator(tokens: ["a"])
XCTAssertEqual(oneElementGenerator.currentElement, "a")
@ -38,4 +38,39 @@ class TokenGeneratorTests: XCTestCase {
let nElementsGenerator = TokenGenerator(tokens: ["a", "b", "c", "d"])
XCTAssertEqual(nElementsGenerator.currentElement, "a")
}
func testNext() {
let emptyGenerator = TokenGenerator(tokens: [])
XCTAssertNil(emptyGenerator.currentElement)
let nilElement = emptyGenerator.next()
XCTAssertNil(nilElement)
XCTAssertNil(emptyGenerator.currentElement)
let oneElementGenerator = TokenGenerator(tokens: ["a"])
let aElement = oneElementGenerator.next()
XCTAssertEqual(aElement, "a")
XCTAssertEqual(oneElementGenerator.currentElement, "a")
let twoElementsGenerator = TokenGenerator(tokens: ["a", "b"])
var twoElement = twoElementsGenerator.next()
XCTAssertEqual(twoElement, "b")
XCTAssertEqual(twoElementsGenerator.currentElement, "b")
twoElement = twoElementsGenerator.next()
XCTAssertEqual(twoElement, "a")
XCTAssertEqual(twoElementsGenerator.currentElement, "a")
}
func testFirstToken() {
let emptyGenerator = TokenGenerator(tokens: [])
XCTAssertNil(emptyGenerator.firstToken)
let oneElementGenerator = TokenGenerator(tokens: ["a"])
XCTAssertEqual(oneElementGenerator.firstToken, "a")
let nElementsGenerator = TokenGenerator(tokens: ["a", "b", "c", "d"])
nElementsGenerator.next()
XCTAssertEqual(nElementsGenerator.firstToken, "a")
}
}

View File

@ -1,6 +1,6 @@
![Splitflap](http://yannickloriot.com/resources/splitflap-logo.gif)
[![Supported Platforms](https://cocoapod-badges.herokuapp.com/p/Splitflap/badge.svg)](http://cocoadocs.org/docsets/Splitflap/) [![Version](https://cocoapod-badges.herokuapp.com/v/Splitflap/badge.svg)](http://cocoadocs.org/docsets/Splitflap/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Supported Platforms](https://cocoapod-badges.herokuapp.com/p/Splitflap/badge.svg)](http://cocoadocs.org/docsets/Splitflap/) [![Version](https://cocoapod-badges.herokuapp.com/v/Splitflap/badge.svg)](http://cocoadocs.org/docsets/Splitflap/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Build Status](https://travis-ci.org/yannickl/Splitflap.svg?branch=master)](https://travis-ci.org/yannickl/Splitflap)
Splitflap is a simple to use component to present changeable alphanumeric text like often used as a public transport timetable in airports or railway stations or with some flip clocks.

View File

@ -184,7 +184,7 @@ final class FlapView: UIView {
}
/// Display the given token. If animated it rotate the flaps.
private func updateWithToken(token: String, animated: Bool) {
private func updateWithToken(token: String?, animated: Bool) {
let topBack = animationTime == .Tic ? topTicTile : topTacTile
let bottomBack = animationTime == .Tic ? bottomTicTile : bottomTacTile
let topFront = animationTime == .Tic ? topTacTile : topTicTile

View File

@ -41,7 +41,8 @@ final class TokenGenerator: GeneratorType {
// MARK: - Implementing GeneratorType
private(set) var currentIndex = 0
/// Current element index
private var currentIndex = 0
/// Returns the current element of the generator, nil otherwise.
var currentElement: Element? {
@ -63,7 +64,15 @@ final class TokenGenerator: GeneratorType {
}
}
/// Advance to the next element and return it, or `nil` if no next.
/// element exists.
func next() -> Element? {
let tokenCount = tokens.count
guard tokenCount > 0 else {
return nil
}
currentIndex = (currentIndex + 1) % tokens.count
return tokens[currentIndex]
@ -71,9 +80,10 @@ final class TokenGenerator: GeneratorType {
// MARK: - Convenience Methods
var firstToken: String {
/// Returns the first token, or `nil` if no token.
var firstToken: String? {
get {
return tokens.first ?? ""
return tokens.first
}
}
}