Skip to content

Commit

Permalink
add unit tests; fix placement of acute accent
Browse files Browse the repository at this point in the history
  • Loading branch information
vermont42 committed May 14, 2019
1 parent 858b211 commit 64627c3
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Conjugar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
038E032A227CD8B7005CFC96 /* UIAlertControllerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E0329227CD8B7005CFC96 /* UIAlertControllerExtensionTests.swift */; };
038E032C228A1E49005CFC96 /* ConjugationResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E032B228A1E49005CFC96 /* ConjugationResultTests.swift */; };
038E032E228A2F18005CFC96 /* PersonNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E032D228A2F18005CFC96 /* PersonNumberTests.swift */; };
038E0330228B0429005CFC96 /* TenseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E032F228B0429005CFC96 /* TenseTests.swift */; };
E10178021F3F753400F0BC97 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10178011F3F753400F0BC97 /* UIViewExtensions.swift */; };
E107B08B1EB66CE6004C5E91 /* verbs.xml in Resources */ = {isa = PBXBuildFile; fileRef = E107B08A1EB66CE6004C5E91 /* verbs.xml */; };
E107B0921EB66F28004C5E91 /* VerbParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = E107B0911EB66F28004C5E91 /* VerbParser.swift */; };
Expand Down Expand Up @@ -171,6 +172,7 @@
038E0329227CD8B7005CFC96 /* UIAlertControllerExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIAlertControllerExtensionTests.swift; sourceTree = "<group>"; };
038E032B228A1E49005CFC96 /* ConjugationResultTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConjugationResultTests.swift; sourceTree = "<group>"; };
038E032D228A2F18005CFC96 /* PersonNumberTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonNumberTests.swift; sourceTree = "<group>"; };
038E032F228B0429005CFC96 /* TenseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TenseTests.swift; sourceTree = "<group>"; };
E10178011F3F753400F0BC97 /* UIViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtensions.swift; sourceTree = "<group>"; };
E107B08A1EB66CE6004C5E91 /* verbs.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = verbs.xml; sourceTree = "<group>"; };
E107B0911EB66F28004C5E91 /* VerbParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerbParser.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -485,6 +487,7 @@
E1DC939421B5836400DD4048 /* QuizTests.swift */,
038E032B228A1E49005CFC96 /* ConjugationResultTests.swift */,
038E032D228A2F18005CFC96 /* PersonNumberTests.swift */,
038E032F228B0429005CFC96 /* TenseTests.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -871,6 +874,7 @@
038E032A227CD8B7005CFC96 /* UIAlertControllerExtensionTests.swift in Sources */,
E198F9051F5D7CB200BAF553 /* ConjugatorTests.swift in Sources */,
E1EC70F22198A10B00872787 /* UIViewControllerExtensions.swift in Sources */,
038E0330228B0429005CFC96 /* TenseTests.swift in Sources */,
E14589F41F5B7BB000EEF141 /* BrowseInfoVCTests.swift in Sources */,
E14589F61F5B7E9D00EEF141 /* VerbVCTests.swift in Sources */,
038E031C2271E239005CFC96 /* AnalyticsServiceableTests.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions Conjugar/Conjugator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Conjugator {
}
if let conjugation = verb[conjugationKey] {
return .success(conjugation)
} else if [.presenteDeIndicativo, .preterito, .imperfectoDeIndicativo, .presenteDeSubjuntivo, .gerundio, .participio].contains(tense) {
} else if [.presenteDeIndicativo, .pretérito, .imperfectoDeIndicativo, .presenteDeSubjuntivo, .gerundio, .participio].contains(tense) {
guard let parent = verb[Conjugator.parent] else {
fatalError("verb[\(Conjugator.parent) was nil.")
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class Conjugator {
guard let parent = verb[Conjugator.parent] else {
fatalError("verb[\(Conjugator.parent) was nil.")
}
guard case .success(let parentStem) = conjugateRecursively(infinitive: parent, tense: .preterito, personNumber: .thirdPlural) else {
guard case .success(let parentStem) = conjugateRecursively(infinitive: parent, tense: .pretérito, personNumber: .thirdPlural) else {
fatalError("parentStem was nil.")
}
let trim = verb[Conjugator.trim] ?? ""
Expand All @@ -227,7 +227,7 @@ class Conjugator {
stemWithRon = parentStem.replaceFirstOccurence(of: trim, with: stem)
}
} else {
guard case .success(let nonDefectiveStemWithRon) = conjugateRecursively(infinitive: infinitive, tense: .preterito, personNumber: .thirdPlural) else {
guard case .success(let nonDefectiveStemWithRon) = conjugateRecursively(infinitive: infinitive, tense: .pretérito, personNumber: .thirdPlural) else {
fatalError("nonDefectiveStemWithRon was nil.")
}
stemWithRon = nonDefectiveStemWithRon
Expand All @@ -248,7 +248,7 @@ class Conjugator {
stem = stemWithoutLastChar + accentedLastChar
}
return .success(stem + endingFor(tense: tense, personNumber: personNumber))
} else if [.perfectoDeIndicativo, .preteritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo].contains(tense) {
} else if [.perfectoDeIndicativo, .pretéritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo].contains(tense) {
let haberTenseResult = tense.haberTenseForCompoundTense()
let haberTense: Tense
switch haberTenseResult {
Expand Down
14 changes: 7 additions & 7 deletions Conjugar/Quiz.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class Quiz {
questions.append(($0, .futuroDeIndicativo, personNumber()))
}
for _ in 0...7 {
questions.append((irregularPreteritoVerb, .preterito, personNumber()))
questions.append((irregularPreteritoVerb, .pretérito, personNumber()))
}
for _ in 0...8 {
questions.append((allRegularVerb, .preterito, personNumber()))
questions.append((allRegularVerb, .pretérito, personNumber()))
}
case .moderate:
[regularArVerb, regularArVerb, regularIrVerb, regularErVerb].forEach {
Expand Down Expand Up @@ -179,10 +179,10 @@ class Quiz {
questions.append(($0, .imperfectoDeIndicativo, personNumber()))
}
for _ in 0...2 {
questions.append((irregularPreteritoVerb, .preterito, personNumber()))
questions.append((irregularPreteritoVerb, .pretérito, personNumber()))
}
[regularArVerb, regularIrVerb, regularErVerb].forEach {
questions.append(($0, .preterito, personNumber()))
questions.append(($0, .pretérito, personNumber()))
}
for _ in 0...2 {
questions.append((irregularPresenteDeSubjuntivoVerb, .presenteDeSubjuntivo, personNumber()))
Expand Down Expand Up @@ -223,10 +223,10 @@ class Quiz {
questions.append((irregularPresenteDeIndicativoVerb, .presenteDeIndicativo, personNumber()))
}
for _ in 0...2 {
questions.append((irregularPreteritoVerb, .preterito, personNumber()))
questions.append((irregularPreteritoVerb, .pretérito, personNumber()))
}
[regularArVerb, regularIrVerb, regularErVerb].forEach {
questions.append(($0, .preterito, personNumber()))
questions.append(($0, .pretérito, personNumber()))
}
for _ in 0...1 {
questions.append((irregularImperfectoVerb, .imperfectoDeIndicativo, personNumber()))
Expand Down Expand Up @@ -261,7 +261,7 @@ class Quiz {
}
questions.append((allRegularVerb, .imperativoPositivo, personNumber(skipYo: true, skipTu: true)))
questions.append((allRegularVerb, .imperativoNegativo, personNumber(skipYo: true, skipTu: true)))
[.perfectoDeIndicativo, .preteritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo].forEach {
[.perfectoDeIndicativo, .pretéritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo].forEach {
questions.append((regularOrIrregularParticipioVerb, $0, personNumber()))
}
}
Expand Down
30 changes: 15 additions & 15 deletions Conjugar/Tense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum Tense: String, CaseIterable {
case imperativoNegativo = "ni"

case presenteDeIndicativo = "pr"
case preterito = "pt"
case pretérito = "pt"
case imperfectoDeIndicativo = "ii"
case futuroDeIndicativo = "fu"
case condicional = "co"
Expand All @@ -29,7 +29,7 @@ enum Tense: String, CaseIterable {
case futuroDeSubjuntivo = "fv"

case perfectoDeIndicativo = "pi"
case preteritoAnterior = "pa"
case pretéritoAnterior = "pa"
case pluscuamperfectoDeIndicativo = "fi"
case futuroPerfecto = "fp"
case condicionalCompuesto = "cc"
Expand All @@ -48,9 +48,9 @@ enum Tense: String, CaseIterable {
return 0
case .imperativoPositivo, .imperativoNegativo:
return 5 + extraConjugation
case .presenteDeIndicativo, .preterito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional,
case .presenteDeIndicativo, .pretérito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional,
.presenteDeSubjuntivo, .imperfectoDeSubjuntivo1, .imperfectoDeSubjuntivo2, .futuroDeSubjuntivo,
.perfectoDeIndicativo, .preteritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto,
.perfectoDeIndicativo, .pretéritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto,
.condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1,
.pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo:
return 6 + extraConjugation
Expand All @@ -62,9 +62,9 @@ enum Tense: String, CaseIterable {
case .imperativoPositivo, .imperativoNegativo,
.infinitivo, .translation, .gerundio, .participio, .raízFutura:
return false
case .presenteDeIndicativo, .preterito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional,
case .presenteDeIndicativo, .pretérito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional,
.presenteDeSubjuntivo, .imperfectoDeSubjuntivo1, .imperfectoDeSubjuntivo2, .futuroDeSubjuntivo,
.perfectoDeIndicativo, .preteritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto,
.perfectoDeIndicativo, .pretéritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto,
.condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1,
.pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo:
return true
Expand All @@ -89,7 +89,7 @@ enum Tense: String, CaseIterable {
return "imperativo negativo"
case .presenteDeIndicativo:
return "presente de indicativo"
case .preterito:
case .pretérito:
return "pretérito"
case .imperfectoDeIndicativo:
return "imperfecto de indicativo"
Expand All @@ -107,8 +107,8 @@ enum Tense: String, CaseIterable {
return "futuro de subjuntivo"
case .perfectoDeIndicativo:
return "perfecto de indicativo"
case .preteritoAnterior:
return "préterito anterior"
case .pretéritoAnterior:
return "pretérito anterior"
case .pluscuamperfectoDeIndicativo:
return "pluscuamperfecto de indicativo"
case .futuroPerfecto:
Expand Down Expand Up @@ -144,7 +144,7 @@ enum Tense: String, CaseIterable {
return "Imperativo Negativo"
case .presenteDeIndicativo:
return "Presente de Indicativo"
case .preterito:
case .pretérito:
return "Pretérito"
case .imperfectoDeIndicativo:
return "Imperfecto de Indicativo"
Expand All @@ -162,8 +162,8 @@ enum Tense: String, CaseIterable {
return "Futuro de Subjuntivo"
case .perfectoDeIndicativo:
return "Perfecto de Indicativo"
case .preteritoAnterior:
return "Préterito Anterior"
case .pretéritoAnterior:
return "Pretérito Anterior"
case .pluscuamperfectoDeIndicativo:
return "Pluscuamperfecto de Indicativo"
case .futuroPerfecto:
Expand All @@ -185,8 +185,8 @@ enum Tense: String, CaseIterable {
switch self {
case .perfectoDeIndicativo:
return .success(.presenteDeIndicativo)
case .preteritoAnterior:
return .success(.preterito)
case .pretéritoAnterior:
return .success(.pretérito)
case .pluscuamperfectoDeIndicativo:
return .success(.imperfectoDeIndicativo)
case .futuroPerfecto:
Expand All @@ -206,5 +206,5 @@ enum Tense: String, CaseIterable {
}
}

static let conjugatedTenses: [Tense] = [.presenteDeIndicativo, .preterito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional, .presenteDeSubjuntivo, .imperfectoDeSubjuntivo1, .imperfectoDeSubjuntivo2, .futuroDeSubjuntivo, .imperativoPositivo, .imperativoNegativo, .perfectoDeIndicativo, .preteritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo]
static let conjugatedTenses: [Tense] = [.presenteDeIndicativo, .pretérito, .imperfectoDeIndicativo, .futuroDeIndicativo, .condicional, .presenteDeSubjuntivo, .imperfectoDeSubjuntivo1, .imperfectoDeSubjuntivo2, .futuroDeSubjuntivo, .imperativoPositivo, .imperativoNegativo, .perfectoDeIndicativo, .pretéritoAnterior, .pluscuamperfectoDeIndicativo, .futuroPerfecto, .condicionalCompuesto, .perfectoDeSubjuntivo, .pluscuamperfectoDeSubjuntivo1, .pluscuamperfectoDeSubjuntivo2, .futuroPerfectoDeSubjuntivo]
}
26 changes: 13 additions & 13 deletions Conjugar/VerbParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ class VerbParser: NSObject, XMLParserDelegate {
if let tp = attributeDict[PersonNumber.thirdPlural.rawValue + Tense.presenteDeIndicativo.rawValue] {
currentConjugations[PersonNumber.thirdPlural.rawValue + Tense.presenteDeIndicativo.rawValue] = tp
}
if let fs = attributeDict[PersonNumber.firstSingular.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.firstSingular.rawValue + Tense.preterito.rawValue] = fs
if let fs = attributeDict[PersonNumber.firstSingular.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.firstSingular.rawValue + Tense.pretérito.rawValue] = fs
}
if let ss = attributeDict[PersonNumber.secondSingularTu.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.secondSingularTu.rawValue + Tense.preterito.rawValue] = ss
currentConjugations[PersonNumber.secondSingularVos.rawValue + Tense.preterito.rawValue] = ss
if let ss = attributeDict[PersonNumber.secondSingularTu.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.secondSingularTu.rawValue + Tense.pretérito.rawValue] = ss
currentConjugations[PersonNumber.secondSingularVos.rawValue + Tense.pretérito.rawValue] = ss
}
if let ts = attributeDict[PersonNumber.thirdSingular.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.thirdSingular.rawValue + Tense.preterito.rawValue] = ts
if let ts = attributeDict[PersonNumber.thirdSingular.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.thirdSingular.rawValue + Tense.pretérito.rawValue] = ts
}
if let fp = attributeDict[PersonNumber.firstPlural.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.firstPlural.rawValue + Tense.preterito.rawValue] = fp
if let fp = attributeDict[PersonNumber.firstPlural.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.firstPlural.rawValue + Tense.pretérito.rawValue] = fp
}
if let sp = attributeDict[PersonNumber.secondPlural.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.secondPlural.rawValue + Tense.preterito.rawValue] = sp
if let sp = attributeDict[PersonNumber.secondPlural.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.secondPlural.rawValue + Tense.pretérito.rawValue] = sp
}
if let tp = attributeDict[PersonNumber.thirdPlural.rawValue + Tense.preterito.rawValue] {
currentConjugations[PersonNumber.thirdPlural.rawValue + Tense.preterito.rawValue] = tp
if let tp = attributeDict[PersonNumber.thirdPlural.rawValue + Tense.pretérito.rawValue] {
currentConjugations[PersonNumber.thirdPlural.rawValue + Tense.pretérito.rawValue] = tp
}
if let fs = attributeDict[PersonNumber.firstSingular.rawValue + Tense.imperfectoDeIndicativo.rawValue] {
currentConjugations[PersonNumber.firstSingular.rawValue + Tense.imperfectoDeIndicativo.rawValue] = fs
Expand Down
2 changes: 1 addition & 1 deletion ConjugarTests/Models/ConjugatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ConjugatorTests: XCTestCase {
XCTFail("One-letter words cannot be conjugated.")
}

result = Conjugator.shared.conjugate(infinitive: "tango 💃🏻", tense: .preterito, personNumber: .thirdPlural)
result = Conjugator.shared.conjugate(infinitive: "tango 💃🏻", tense: .pretérito, personNumber: .thirdPlural)
switch result {
case .failure:
break
Expand Down
Loading

0 comments on commit 64627c3

Please sign in to comment.