-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotesTests.swift
More file actions
219 lines (201 loc) · 8.15 KB
/
Copy pathNotesTests.swift
File metadata and controls
219 lines (201 loc) · 8.15 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import XCTest
@testable import Note_It
class NotesTests: XCTestCase {
override func tearDown() {
let notes = Notes.sharedInstance
notes.clearList()
super.tearDown()
}
func testAddSingleNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
XCTAssertEqual(notes.count, 1)
} catch {
XCTFail()
}
}
func testAddMultipleNotes() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
} catch {
XCTFail()
}
}
func testRetrieveSingleNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
let note = try notes.getNote(atIndex: 0)
XCTAssertEqual(note.title, "Note One")
XCTAssertEqual(note.text, "Details of note one")
} catch {
XCTFail()
}
}
func testRetrieveLastNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
let note = try notes.getNote(atIndex: 2)
XCTAssertEqual(note.title, "Note Three")
XCTAssertEqual(note.text, "Details of note three")
} catch {
XCTFail()
}
}
func testRetrieveInvalidNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
let _ = try notes.getNote(atIndex: 3)
XCTFail()
} catch NoteError.outOfRange(let index) {
XCTAssertEqual(index, 3, "the exception shound pass array index 3")
} catch {
XCTFail()
}
}
func testRemoveOnlyNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
XCTAssertEqual(notes.count, 1)
try notes.remove(at: 0)
XCTAssertEqual(notes.count, 0)
} catch {
XCTFail()
}
}
func testRemoveLastNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
try notes.remove(at: 2)
XCTAssertEqual(notes.count, 2)
} catch {
XCTFail()
}
}
func testRemoveInvalidNote() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
try notes.remove(at: 3)
XCTFail()
} catch NoteError.outOfRange(let index) {
XCTAssertEqual(notes.count, 3)
XCTAssertEqual(index, 3, "the exception shound pass array index 3")
} catch {
XCTFail()
}
}
func testInsertAtFirstIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
let note = Note(title: "Note Zero", text: "Details of note zero")
try notes.insert(note: note, at: 0)
XCTAssertEqual(notes.count, 4)
} catch {
XCTFail()
}
}
func testInsertAtLastIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
let note = Note(title: "Note Four", text: "Details of note four")
try notes.insert(note: note, at: 3)
XCTAssertEqual(notes.count, 4)
} catch {
XCTFail()
}
}
func testInsertAtInvalidIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
let note = Note(title: "Note Five", text: "Details of note five")
try notes.insert(note: note, at: 4)
XCTFail()
} catch NoteError.outOfRange(let index) {
XCTAssertEqual(notes.count, 3)
XCTAssertEqual(index, 4, "the exception shound pass array index 4")
} catch {
XCTFail()
}
}
func testUpdateFirstIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
XCTAssertEqual(notes.count, 1)
var note = Note(title: "Note One Update", text: "Updated details of note one")
try notes.update(note: note, at: 0)
XCTAssertEqual(notes.count, 1)
note = try notes.getNote(atIndex: 0)
XCTAssertEqual(note.title, "Note One Update")
XCTAssertEqual(note.text, "Updated details of note one")
} catch {
XCTFail()
}
}
func testUpdateLastIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
var note = Note(title: "Note Three Update", text: "Updated details of note three")
try notes.update(note: note, at: 2)
XCTAssertEqual(notes.count, 3)
note = try notes.getNote(atIndex: 2)
XCTAssertEqual(note.title, "Note Three Update")
XCTAssertEqual(note.text, "Updated details of note three")
} catch {
XCTFail()
}
}
func testUpdateInvalidIndex() {
let notes = Notes.sharedInstance
do {
try notes.add(note: Note(title: "Note One", text: "Details of note one"))
try notes.add(note: Note(title: "Note Two", text: "Details of note two"))
try notes.add(note: Note(title: "Note Three", text: "Details of note three"))
XCTAssertEqual(notes.count, 3)
let note = Note(title: "Note Four Update", text: "Updated details of note four")
try notes.update(note: note, at: 3)
XCTFail()
} catch NoteError.outOfRange(let index) {
XCTAssertEqual(notes.count, 3)
XCTAssertEqual(index, 3)
} catch {
XCTFail()
}
}
}