25
25
//
26
26
27
27
@testable import iCookTV
28
- import Nimble
29
- import Quick
28
+ import XCTest
30
29
31
- class DataCollectionSpec : QuickSpec {
30
+ final class DataCollectionSpec : XCTestCase {
32
31
33
32
private struct TestCollection : DataCollection {
34
33
typealias DataType = Int
@@ -37,68 +36,77 @@ class DataCollectionSpec: QuickSpec {
37
36
38
37
private var dataCollection = TestCollection ( items: [ ] )
39
38
40
- override func spec( ) {
41
-
42
- beforeEach {
43
- self . dataCollection = TestCollection ( items: [ 1 , 1 , 2 , 3 , 5 , 8 ] )
44
- }
45
-
46
- describe ( " count " ) {
47
- it ( " should return the count of items " ) {
48
- expect ( self . dataCollection. count) == 6
49
- }
50
- }
51
-
52
- describe ( " subscript " ) {
53
- it ( " should return the item at index " ) {
54
- expect ( self . dataCollection [ 0 ] ) == 1
55
- expect ( self . dataCollection [ 1 ] ) == 1
56
- expect ( self . dataCollection [ 2 ] ) == 2
57
- expect ( self . dataCollection [ 3 ] ) == 3
58
- expect ( self . dataCollection [ 4 ] ) == 5
59
- expect ( self . dataCollection [ 5 ] ) == 8
60
- }
61
- }
62
-
63
- describe ( " append(_:) " ) {
64
- it ( " should append items to collection " ) {
65
- let collection = self . dataCollection. append ( [ 13 , 21 , 34 , 55 ] )
66
- expect ( self . dataCollection. count) == 6
67
- expect ( collection. count) == 10
68
- expect ( collection [ 6 ] ) == 13
69
- expect ( collection [ 7 ] ) == 21
70
- expect ( collection [ 8 ] ) == 34
71
- expect ( collection [ 9 ] ) == 55
72
- }
73
- }
74
-
75
- describe ( " insert(_:atIndex:) " ) {
76
- it ( " should insert item to collection " ) {
77
- let collection = self . dataCollection. insert ( 42 , atIndex: 3 )
78
- expect ( self . dataCollection. count) == 6
79
- expect ( collection. count) == 7
80
- expect ( collection. items) == [ 1 , 1 , 2 , 42 , 3 , 5 , 8 ]
81
- }
82
- }
83
-
84
- describe ( " deleteItem(atIndex:) " ) {
85
- it ( " should delete item at index " ) {
86
- let collection = self . dataCollection. deleteItem ( atIndex: 3 )
87
- expect ( self . dataCollection. count) == 6
88
- expect ( collection. count) == 5
89
- expect ( collection. items) == [ 1 , 1 , 2 , 5 , 8 ]
90
- }
91
- }
92
-
93
- describe ( " moveItem(fromIndex:toIndex:) " ) {
94
- it ( " should reorder the items " ) {
95
- let collection = self . dataCollection. moveItem ( fromIndex: 1 , toIndex: 4 )
96
- expect ( self . dataCollection. count) == 6
97
- expect ( collection. count) == 6
98
- expect ( collection. items) == [ 1 , 2 , 3 , 5 , 1 , 8 ]
99
- }
100
- }
39
+ override func setUp( ) {
40
+ dataCollection = TestCollection ( items: [ 1 , 1 , 2 , 3 , 5 , 8 ] )
41
+ }
42
+
43
+ func testCount( ) {
44
+ // It should return the count of items
45
+ XCTAssertEqual ( dataCollection. count, 6 )
46
+ }
47
+
48
+ func testSubscript( ) {
49
+ // It should return the item at index
50
+ XCTAssertEqual ( dataCollection [ 0 ] , 1 )
51
+ XCTAssertEqual ( dataCollection [ 1 ] , 1 )
52
+ XCTAssertEqual ( dataCollection [ 2 ] , 2 )
53
+ XCTAssertEqual ( dataCollection [ 3 ] , 3 )
54
+ XCTAssertEqual ( dataCollection [ 4 ] , 5 )
55
+ XCTAssertEqual ( dataCollection [ 5 ] , 8 )
56
+ }
57
+
58
+ func testAppendItems( ) {
59
+ // Given
60
+ let newItems = [ 13 , 21 , 34 , 55 ]
61
+
62
+ // When
63
+ let newCollection = dataCollection. append ( newItems)
64
+
65
+ // Then the original data collection should remain the same
66
+ XCTAssertEqual ( dataCollection. count, 6 )
67
+
68
+ // It should append items to the new collection
69
+ XCTAssertEqual ( newCollection. count, 10 )
70
+ XCTAssertEqual ( newCollection [ 6 ] , 13 )
71
+ XCTAssertEqual ( newCollection [ 7 ] , 21 )
72
+ XCTAssertEqual ( newCollection [ 8 ] , 34 )
73
+ XCTAssertEqual ( newCollection [ 9 ] , 55 )
74
+ }
75
+
76
+ func testInsertItemAtIndex( ) {
77
+ // When
78
+ let newCollection = dataCollection. insert ( 42 , atIndex: 3 )
79
+
80
+ // Then the original data collection should remain the same
81
+ XCTAssertEqual ( dataCollection. count, 6 )
82
+
83
+ // It should insert item to the new collection
84
+ XCTAssertEqual ( newCollection. count, 7 )
85
+ XCTAssertEqual ( newCollection. items, [ 1 , 1 , 2 , 42 , 3 , 5 , 8 ] )
86
+ }
87
+
88
+ func testDeleteItemAtIndex( ) {
89
+ // When
90
+ let newCollection = dataCollection. deleteItem ( atIndex: 3 )
91
+
92
+ // Then the original data collection should remain the same
93
+ XCTAssertEqual ( dataCollection. count, 6 )
94
+
95
+ // It should delete item at index in the new collection
96
+ XCTAssertEqual ( newCollection. count, 5 )
97
+ XCTAssertEqual ( newCollection. items, [ 1 , 1 , 2 , 5 , 8 ] )
98
+ }
99
+
100
+ func testMoveItemFromIndexToIndex( ) {
101
+ // When
102
+ let newCollection = dataCollection. moveItem ( fromIndex: 1 , toIndex: 4 )
103
+
104
+ // Then the original data collection should remain the same
105
+ XCTAssertEqual ( dataCollection. count, 6 )
101
106
107
+ // It should reorder the items in the new collection
108
+ XCTAssertEqual ( newCollection. count, 6 )
109
+ XCTAssertEqual ( newCollection. items, [ 1 , 2 , 3 , 5 , 1 , 8 ] )
102
110
}
103
111
104
112
}
0 commit comments