/
MPSTickerTest.m
91 lines (75 loc) · 2.79 KB
/
MPSTickerTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// MPSTickerTest.m
// RACTest
//
// Created by Christopher Bowns on 1/31/14.
// Copyright (c) 2014 Mechanical Pants. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "MPSTicker.h"
@interface MPSTickerTest : XCTestCase
@end
@implementation MPSTickerTest
- (void)setUp
{
[super setUp];
// Put setup code here; it will be run once, before the first test case.
}
- (void)tearDown
{
// Put teardown code here; it will be run once, after the last test case.
[super tearDown];
}
#pragma mark - Tests
#pragma mark Initialization
- (void)testDefaultInitialization
{
MPSTicker *ticker = [[MPSTicker alloc] init];
XCTAssertTrue(ticker.accumulateEnabled, @"Ticker accumulation should be enabled after initialization.");
RACSignal *accumulateSignal = ticker.accumulateSignal;
XCTAssertNotNil(accumulateSignal, @"Accumulate signal should be an object");
XCTAssertTrue([[accumulateSignal class] isSubclassOfClass:[RACSignal class]], @"Accumulate signal should be a RACSignal.");
}
- (void)testDesignatedInitializer
{
RACSignal *customTick = [[RACSignal alloc] startWith:@(0)];
MPSTicker *ticker = [[MPSTicker alloc] initWithTickSource:customTick];
RACSignal *tickSignal = ticker.accumulateSignal;
XCTAssertNotNil(tickSignal, @"Accumulate signal should be an object");
XCTAssertTrue([[tickSignal class] isSubclassOfClass:[RACSignal class]], @"Accumulate signal should be a RACSignal.");
}
- (void)testFirstTickValue
{
// Create a custom tick with one value to send.
NSUInteger firstValue = 1;
RACSignal *customTick = [RACSignal return:@(firstValue)];
MPSTicker *ticker = [[MPSTicker alloc] initWithTickSource:customTick];
// Manually subscribe to verify we got back the value we expected.
// (It should be one accumulated value.)
BOOL success = NO;
NSError *error = nil;
id value = [ticker.accumulateSignal asynchronousFirstOrDefault:nil success:&success error:&error];
if (!success) {
XCTAssertTrue(success, @"Signal failed to return a value. Error: %@", error);
} else {
XCTAssertNotNil(value, @"Signal returned a nil value.");
XCTAssertEqualObjects(@(firstValue), value, @"Signal returned an unexpected value of %@, should be %i", value, firstValue);
}
}
/// Tests the default ticker's built-in timer.
/// This test takes a second to run as a result.
- (void)testTimerAccumulatingTicks
{
NSUInteger firstValue = 1;
MPSTicker *ticker = [[MPSTicker alloc] init];
BOOL success = NO;
NSError *error = nil;
id value = [ticker.accumulateSignal asynchronousFirstOrDefault:nil success:&success error:&error];
if (!success) {
XCTAssertTrue(success, @"Signal failed to return a value. Error: %@", error);
} else {
XCTAssertNotNil(value, @"Signal returned a nil value.");
XCTAssertEqualObjects(@(firstValue), value, @"Signal returned an unexpected value of %@, should be %i", value, firstValue);
}
}
@end