Skip to content

Commit 1b7a0f5

Browse files
committed
add unit tests
1 parent 64627c3 commit 1b7a0f5

File tree

3 files changed

+54
-178
lines changed

3 files changed

+54
-178
lines changed

Conjugar.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
03533491228B7B0900046CCC /* UserDefaultsGetterSetterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03533490228B7B0900046CCC /* UserDefaultsGetterSetterTests.swift */; };
1011
035C646F22299A7E001ECC02 /* RatingsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035C646E22299A7E001ECC02 /* RatingsFetcher.swift */; };
1112
038E03132270A868005CFC96 /* IntExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03122270A868005CFC96 /* IntExtensionTests.swift */; };
1213
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */; };
@@ -157,6 +158,7 @@
157158
/* End PBXCopyFilesBuildPhase section */
158159

159160
/* Begin PBXFileReference section */
161+
03533490228B7B0900046CCC /* UserDefaultsGetterSetterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsGetterSetterTests.swift; sourceTree = "<group>"; };
160162
035C646E22299A7E001ECC02 /* RatingsFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingsFetcher.swift; sourceTree = "<group>"; };
161163
038E03122270A868005CFC96 /* IntExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntExtensionTests.swift; sourceTree = "<group>"; };
162164
038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGameCenterTests.swift; sourceTree = "<group>"; };
@@ -438,6 +440,7 @@
438440
038E0323227617FC005CFC96 /* UIApplicationExtensionTests.swift */,
439441
038E031922711B76005CFC96 /* UIViewControllerExtensionsTests.swift */,
440442
038E032122760A40005CFC96 /* UIViewExtensionsTests.swift */,
443+
03533490228B7B0900046CCC /* UserDefaultsGetterSetterTests.swift */,
441444
);
442445
path = Utils;
443446
sourceTree = "<group>";
@@ -874,6 +877,7 @@
874877
038E032A227CD8B7005CFC96 /* UIAlertControllerExtensionTests.swift in Sources */,
875878
E198F9051F5D7CB200BAF553 /* ConjugatorTests.swift in Sources */,
876879
E1EC70F22198A10B00872787 /* UIViewControllerExtensions.swift in Sources */,
880+
03533491228B7B0900046CCC /* UserDefaultsGetterSetterTests.swift in Sources */,
877881
038E0330228B0429005CFC96 /* TenseTests.swift in Sources */,
878882
E14589F41F5B7BB000EEF141 /* BrowseInfoVCTests.swift in Sources */,
879883
E14589F61F5B7E9D00EEF141 /* VerbVCTests.swift in Sources */,

ConjugarTests/Models/TenseTests.swift

+28-178
Original file line numberDiff line numberDiff line change
@@ -10,199 +10,49 @@ import XCTest
1010
@testable import Conjugar
1111

1212
class TenseTests: XCTestCase {
13-
func testDisplayName() {
14-
var tense: Tense = .infinitivo
15-
XCTAssertEqual(tense.displayName, "infinitivo")
16-
tense = .translation
17-
XCTAssertEqual(tense.displayName, "translation")
18-
tense = .gerundio
19-
XCTAssertEqual(tense.displayName, "gerundio")
20-
tense = .participio
21-
XCTAssertEqual(tense.displayName, "participio")
22-
tense = .raízFutura
23-
XCTAssertEqual(tense.displayName, "raíz futura")
24-
tense = .imperativoPositivo
25-
XCTAssertEqual(tense.displayName, "imperativo positivo")
26-
tense = .imperativoNegativo
27-
XCTAssertEqual(tense.displayName, "imperativo negativo")
28-
tense = .presenteDeIndicativo
29-
XCTAssertEqual(tense.displayName, "presente de indicativo")
30-
tense = .pretérito
31-
XCTAssertEqual(tense.displayName, "pretérito")
32-
tense = .imperfectoDeIndicativo
33-
XCTAssertEqual(tense.displayName, "imperfecto de indicativo")
34-
tense = .futuroDeIndicativo
35-
XCTAssertEqual(tense.displayName, "futuro de indicativo")
36-
tense = .condicional
37-
XCTAssertEqual(tense.displayName, "condicional")
38-
tense = .presenteDeSubjuntivo
39-
XCTAssertEqual(tense.displayName, "presente de subjuntivo")
40-
tense = .imperfectoDeSubjuntivo1
41-
XCTAssertEqual(tense.displayName, "imperfecto de subjuntivo 1")
42-
tense = .imperfectoDeSubjuntivo2
43-
XCTAssertEqual(tense.displayName, "imperfecto de subjuntivo 2")
44-
tense = .futuroDeSubjuntivo
45-
XCTAssertEqual(tense.displayName, "futuro de subjuntivo")
46-
tense = .perfectoDeIndicativo
47-
XCTAssertEqual(tense.displayName, "perfecto de indicativo")
48-
tense = .pretéritoAnterior
49-
XCTAssertEqual(tense.displayName, "pretérito anterior")
50-
tense = .pluscuamperfectoDeIndicativo
51-
XCTAssertEqual(tense.displayName, "pluscuamperfecto de indicativo")
52-
tense = .futuroPerfecto
53-
XCTAssertEqual(tense.displayName, "futuro perfecto")
54-
tense = .condicionalCompuesto
55-
XCTAssertEqual(tense.displayName, "condicional compuesto")
56-
tense = .perfectoDeSubjuntivo
57-
XCTAssertEqual(tense.displayName, "perfecto de subjuntivo")
58-
tense = .pluscuamperfectoDeSubjuntivo1
59-
XCTAssertEqual(tense.displayName, "pluscuamperfecto de subjuntivo 1")
60-
tense = .pluscuamperfectoDeSubjuntivo2
61-
XCTAssertEqual(tense.displayName, "pluscuamperfecto de subjuntivo 2")
13+
func testDisplayNames() {
14+
[(Tense.infinitivo, "infinitivo"), (.translation, "translation"), (.gerundio, "gerundio"), (.participio, "participio"), (.raízFutura, "raíz futura"), (.imperativoPositivo, "imperativo positivo"), (.imperativoNegativo, "imperativo negativo"), (.presenteDeIndicativo, "presente de indicativo"), (.pretérito, "pretérito"), (.imperfectoDeIndicativo, "imperfecto de indicativo"), (.futuroDeIndicativo, "futuro de indicativo"), (.condicional, "condicional"), (.presenteDeSubjuntivo, "presente de subjuntivo"), (.imperfectoDeSubjuntivo1, "imperfecto de subjuntivo 1"), (.imperfectoDeSubjuntivo2, "imperfecto de subjuntivo 2"), (.futuroDeSubjuntivo, "futuro de subjuntivo"), (.perfectoDeIndicativo, "perfecto de indicativo"), (.pretéritoAnterior, "pretérito anterior"), (.pluscuamperfectoDeIndicativo, "pluscuamperfecto de indicativo"), (.futuroPerfecto, "futuro perfecto"), (.condicionalCompuesto, "condicional compuesto"), (.perfectoDeSubjuntivo, "perfecto de subjuntivo"), (.pluscuamperfectoDeSubjuntivo1, "pluscuamperfecto de subjuntivo 1"), (.pluscuamperfectoDeSubjuntivo2, "pluscuamperfecto de subjuntivo 2")].forEach {
15+
testDisplayName(tense: $0.0, displayName: $0.1)
16+
}
6217
}
6318

64-
func testTitleCaseName() {
65-
var tense: Tense = .infinitivo
66-
XCTAssertEqual(tense.titleCaseName, "Infinitivo")
67-
tense = .translation
68-
XCTAssertEqual(tense.titleCaseName, "Translation")
69-
tense = .gerundio
70-
XCTAssertEqual(tense.titleCaseName, "Gerundio")
71-
tense = .participio
72-
XCTAssertEqual(tense.titleCaseName, "Participio")
73-
tense = .raízFutura
74-
XCTAssertEqual(tense.titleCaseName, "Raíz Futura")
75-
tense = .imperativoPositivo
76-
XCTAssertEqual(tense.titleCaseName, "Imperativo Positivo")
77-
tense = .imperativoNegativo
78-
XCTAssertEqual(tense.titleCaseName, "Imperativo Negativo")
79-
tense = .presenteDeIndicativo
80-
XCTAssertEqual(tense.titleCaseName, "Presente de Indicativo")
81-
tense = .pretérito
82-
XCTAssertEqual(tense.titleCaseName, "Pretérito")
83-
tense = .imperfectoDeIndicativo
84-
XCTAssertEqual(tense.titleCaseName, "Imperfecto de Indicativo")
85-
tense = .futuroDeIndicativo
86-
XCTAssertEqual(tense.titleCaseName, "Futuro de Indicativo")
87-
tense = .condicional
88-
XCTAssertEqual(tense.titleCaseName, "Condicional")
89-
tense = .presenteDeSubjuntivo
90-
XCTAssertEqual(tense.titleCaseName, "Presente de Subjuntivo")
91-
tense = .imperfectoDeSubjuntivo1
92-
XCTAssertEqual(tense.titleCaseName, "Imperfecto de Subjuntivo 1")
93-
tense = .imperfectoDeSubjuntivo2
94-
XCTAssertEqual(tense.titleCaseName, "Imperfecto de Subjuntivo 2")
95-
tense = .futuroDeSubjuntivo
96-
XCTAssertEqual(tense.titleCaseName, "Futuro de Subjuntivo")
97-
tense = .perfectoDeIndicativo
98-
XCTAssertEqual(tense.titleCaseName, "Perfecto de Indicativo")
99-
tense = .pretéritoAnterior
100-
XCTAssertEqual(tense.titleCaseName, "Pretérito Anterior")
101-
tense = .pluscuamperfectoDeIndicativo
102-
XCTAssertEqual(tense.titleCaseName, "Pluscuamperfecto de Indicativo")
103-
tense = .futuroPerfecto
104-
XCTAssertEqual(tense.titleCaseName, "Futuro Perfecto")
105-
tense = .condicionalCompuesto
106-
XCTAssertEqual(tense.titleCaseName, "Condicional Compuesto")
107-
tense = .perfectoDeSubjuntivo
108-
XCTAssertEqual(tense.titleCaseName, "Perfecto de Subjuntivo")
109-
tense = .pluscuamperfectoDeSubjuntivo1
110-
XCTAssertEqual(tense.titleCaseName, "Pluscuamperfecto de Subjuntivo 1")
111-
tense = .pluscuamperfectoDeSubjuntivo2
112-
XCTAssertEqual(tense.titleCaseName, "Pluscuamperfecto de Subjuntivo 2")
113-
tense = .futuroPerfectoDeSubjuntivo
114-
XCTAssertEqual(tense.titleCaseName, "Futuro Perfecto de Subjuntivo")
19+
private func testDisplayName(tense: Tense, displayName: String) {
20+
XCTAssertEqual(tense.displayName, displayName)
11521
}
11622

117-
func testHaberTenseForCompoundTense() {
118-
var tense: Tense = .perfectoDeIndicativo
119-
var result = tense.haberTenseForCompoundTense()
120-
switch result {
121-
case .success(let haberTense):
122-
XCTAssertEqual(haberTense, .presenteDeIndicativo)
123-
case .failure(_):
124-
XCTFail("No haber tense found for \(tense.displayName).")
125-
}
126-
127-
tense = .pretéritoAnterior
128-
result = tense.haberTenseForCompoundTense()
129-
switch result {
130-
case .success(let haberTense):
131-
XCTAssertEqual(haberTense, .pretérito)
132-
case .failure(_):
133-
XCTFail("No haber tense found for \(tense.displayName).")
134-
}
135-
136-
tense = .pluscuamperfectoDeIndicativo
137-
result = tense.haberTenseForCompoundTense()
138-
switch result {
139-
case .success(let haberTense):
140-
XCTAssertEqual(haberTense, .imperfectoDeIndicativo)
141-
case .failure(_):
142-
XCTFail("No haber tense found for \(tense.displayName).")
143-
}
144-
145-
tense = .futuroPerfecto
146-
result = tense.haberTenseForCompoundTense()
147-
switch result {
148-
case .success(let haberTense):
149-
XCTAssertEqual(haberTense, .futuroDeIndicativo)
150-
case .failure(_):
151-
XCTFail("No haber tense found for \(tense.displayName).")
152-
}
153-
154-
tense = .condicionalCompuesto
155-
result = tense.haberTenseForCompoundTense()
156-
switch result {
157-
case .success(let haberTense):
158-
XCTAssertEqual(haberTense, .condicional)
159-
case .failure(_):
160-
XCTFail("No haber tense found for \(tense.displayName).")
161-
}
162-
163-
tense = .perfectoDeSubjuntivo
164-
result = tense.haberTenseForCompoundTense()
165-
switch result {
166-
case .success(let haberTense):
167-
XCTAssertEqual(haberTense, .presenteDeSubjuntivo)
168-
case .failure(_):
169-
XCTFail("No haber tense found for \(tense.displayName).")
23+
func testTitleCaseNames() {
24+
[(Tense.infinitivo, "Infinitivo"), (.translation, "Translation"), (.gerundio, "Gerundio"), (.participio, "Participio"), (.raízFutura, "Raíz Futura"), (.imperativoPositivo, "Imperativo Positivo"), (.imperativoNegativo, "Imperativo Negativo"), (.presenteDeIndicativo, "Presente de Indicativo"), (.pretérito, "Pretérito"), (.imperfectoDeIndicativo, "Imperfecto de Indicativo"), (.futuroDeIndicativo, "Futuro de Indicativo"), (.condicional, "Condicional"), (.presenteDeSubjuntivo, "Presente de Subjuntivo"), (.imperfectoDeSubjuntivo1, "Imperfecto de Subjuntivo 1"), (.imperfectoDeSubjuntivo2, "Imperfecto de Subjuntivo 2"), (.futuroDeSubjuntivo, "Futuro de Subjuntivo"), (.perfectoDeIndicativo, "Perfecto de Indicativo"), (.pretéritoAnterior, "Pretérito Anterior"), (.pluscuamperfectoDeIndicativo, "Pluscuamperfecto de Indicativo"), (.futuroPerfecto, "Futuro Perfecto"), (.condicionalCompuesto, "Condicional Compuesto"), (.perfectoDeSubjuntivo, "Perfecto de Subjuntivo"), (.pluscuamperfectoDeSubjuntivo1, "Pluscuamperfecto de Subjuntivo 1"), (.pluscuamperfectoDeSubjuntivo2, "Pluscuamperfecto de Subjuntivo 2")].forEach {
25+
testTitleCaseName(tense: $0.0, titleCaseName: $0.1)
17026
}
27+
}
17128

172-
tense = .pluscuamperfectoDeSubjuntivo1
173-
result = tense.haberTenseForCompoundTense()
174-
switch result {
175-
case .success(let haberTense):
176-
XCTAssertEqual(haberTense, .imperfectoDeSubjuntivo1)
177-
case .failure(_):
178-
XCTFail("No haber tense found for \(tense.displayName).")
179-
}
29+
private func testTitleCaseName(tense: Tense, titleCaseName: String) {
30+
XCTAssertEqual(tense.titleCaseName, titleCaseName)
31+
}
18032

181-
tense = .pluscuamperfectoDeSubjuntivo2
182-
result = tense.haberTenseForCompoundTense()
183-
switch result {
184-
case .success(let haberTense):
185-
XCTAssertEqual(haberTense, .imperfectoDeSubjuntivo2)
186-
case .failure(_):
187-
XCTFail("No haber tense found for \(tense.displayName).")
33+
func testHaberTensesForCompoundTenses() {
34+
// The following line uses as much type inference as the compiler allows.
35+
[(Tense.perfectoDeIndicativo, .presenteDeIndicativo), (.pretéritoAnterior, .pretérito), (.pluscuamperfectoDeIndicativo, .imperfectoDeIndicativo), (.futuroPerfecto, .futuroDeIndicativo), (.condicionalCompuesto, .condicional), (.perfectoDeSubjuntivo, .presenteDeSubjuntivo), (.pluscuamperfectoDeSubjuntivo1, .imperfectoDeSubjuntivo1), (.pluscuamperfectoDeSubjuntivo2, .imperfectoDeSubjuntivo1), (Tense.futuroPerfectoDeSubjuntivo, Tense.futuroDeSubjuntivo)].forEach {
36+
testHaberTenseForCompoundTense(compoundTense: $0.0, haberTense: $0.1)
18837
}
18938

190-
tense = .futuroPerfectoDeSubjuntivo
191-
result = tense.haberTenseForCompoundTense()
39+
let notACompoundTense: Tense = .infinitivo
40+
let result = notACompoundTense.haberTenseForCompoundTense()
19241
switch result {
19342
case .success(let haberTense):
194-
XCTAssertEqual(haberTense, .futuroDeSubjuntivo)
195-
case .failure(_):
196-
XCTFail("No haber tense found for \(tense.displayName).")
43+
XCTFail("Haber form \(haberTense.displayName) incorrectly found for tense \(notACompoundTense.displayName).")
44+
case .failure:
45+
break
19746
}
47+
}
19848

199-
tense = .infinitivo
200-
result = tense.haberTenseForCompoundTense()
49+
private func testHaberTenseForCompoundTense(compoundTense: Tense, haberTense: Tense) {
50+
let result = compoundTense.haberTenseForCompoundTense()
20151
switch result {
20252
case .success(let haberTense):
203-
XCTFail("Haber form \(haberTense.displayName) incorrectly found for tense \(tense.displayName).")
204-
case .failure(_):
205-
break
53+
XCTAssertEqual(haberTense, haberTense)
54+
case .failure:
55+
XCTFail("No haber tense found for \(compoundTense.displayName).")
20656
}
20757
}
20858
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UserDefaultsGetterSetterTests.swift
3+
// ConjugarTests
4+
//
5+
// Created by Joshua Adams on 5/14/19.
6+
// Copyright © 2019 Josh Adams. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Conjugar
11+
12+
class UserDefaultsGetterSetterTests: XCTestCase {
13+
func testGetAndSet() {
14+
let settings = Settings(getterSetter: UserDefaultsGetterSetter())
15+
let savedRegion = settings.region
16+
settings.region = .spain
17+
XCTAssertEqual(settings.region, .spain)
18+
settings.region = .latinAmerica
19+
XCTAssertEqual(settings.region, .latinAmerica)
20+
settings.region = savedRegion
21+
}
22+
}

0 commit comments

Comments
 (0)