Skip to content

Commit d2f8617

Browse files
author
Olcay Taner YILDIZ
committed
Added toCapital method.
1 parent ff90864 commit d2f8617

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/Dictionary/Word.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ open class Word : Comparable, Equatable, Hashable{
8282
public static func substringFrom(s: String, ch: String) -> String{
8383
return String(s[s.range(of: ch)!.upperBound...])
8484
}
85+
86+
public static func toCapital(s: String) -> String{
87+
var result : String = Word.uppercase(s: String(Word.charAt(s: s, i: 0)))
88+
for i in 1..<s.count{
89+
result += String(Word.charAt(s: s, i: i))
90+
}
91+
return result
92+
}
8593

8694
public static func uppercase(s: String) -> String{
8795
var result : String = ""

Tests/DictionaryTests/WordTest.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ final class WordTest: XCTestCase {
1414
XCTAssertEqual(6, word.charCount())
1515
}
1616

17+
func testToCapital(){
18+
var word : Word = Word(name: "ali")
19+
XCTAssertEqual("Ali", Word.toCapital(s: word.getName()))
20+
word = Word(name: "ilginç")
21+
XCTAssertEqual("İlginç", Word.toCapital(s: word.getName()))
22+
word = Word(name: "ç")
23+
XCTAssertEqual("Ç", Word.toCapital(s: word.getName()))
24+
}
25+
1726
func testIsCapital(){
1827
XCTAssertFalse(Word.isCapital(surfaceForm: "ali"))
1928
XCTAssertTrue(Word.isCapital(surfaceForm: "Ali"))

0 commit comments

Comments
 (0)