forked from soffes/RateLimit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountedTests.swift
56 lines (44 loc) · 1.01 KB
/
CountedTests.swift
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
//
// CountedTests.swift
// RateLimit
//
// Created by Sam Soffes on 10/20/16.
// Copyright © 2016 Sam Soffes. All rights reserved.
//
import XCTest
import RateLimit
final class CountedTests: XCTestCase {
func testCounting() {
let limiter = CountedLimiter(limit: 2)
XCTAssertEqual(0, limiter.count)
let one = expectation(description: "one")
limiter.execute {
one.fulfill()
}
XCTAssertEqual(1, limiter.count)
let two = expectation(description: "two")
limiter.execute {
two.fulfill()
}
XCTAssertEqual(2, limiter.count)
limiter.execute {
XCTFail("This shouldn't run.")
}
XCTAssertEqual(2, limiter.count)
waitForExpectations(timeout: 1)
}
func testReturn() {
let limiter = CountedLimiter(limit: 1)
let one = expectation(description: "one")
let value1 = limiter.execute { () -> Int in
one.fulfill()
return 42
}
XCTAssertEqual(42, value1)
let value2 = limiter.execute { () -> Int in
return 19
}
XCTAssertNil(value2)
waitForExpectations(timeout: 0)
}
}