<commit_before>//
//  SpellerTests.swift
//  Speller
//
//  Created by Jean-Étienne on 8/11/16.
//  Copyright © 2016 Jean-Étienne. All rights reserved.
//

import XCTest

class SpellerTests: XCTestCase {

    func testSpellingWorks() {
        let spelling = Speller.spell(phrase: "Bagpipe", withSpellingAlphabet: .InternationalRadiotelephony)

        XCTAssertNotNil(spelling)
    }

    func testSpellingAllLetters() {
        let word = "Bagpipe"
        let spelling = Speller.spell(phrase: word, withSpellingAlphabet: .InternationalRadiotelephony)

        XCTAssertEqual(spelling.count, word.characters.count)
    }
    
    func testSpellingAllLettersAccuratelyWithInternationalRadiotelephony() {
        let phrase = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .InternationalRadiotelephony)
        let control = [SpelledCharacter.Match("a", "Alfa"),
                       SpelledCharacter.Match("b", "Bravo"),
                       SpelledCharacter.Match("c", "Charlie"),
                       SpelledCharacter.Match("d", "Delta"),
                       SpelledCharacter.Match("e", "Echo"),
                       SpelledCharacter.Match("f", "Foxtrot"),
                       SpelledCharacter.Match("g", "Golf"),
                       SpelledCharacter.Match("h", "Hotel"),
                       SpelledCharacter.Match("i", "India"),
                       SpelledCharacter.Match("j", "Juliett"),
                       SpelledCharacter.Match("k", "Kilo"),
                       SpelledCharacter.Match("l", "Lima"),
                       SpelledCharacter.Match("m", "Mike"),
                       SpelledCharacter.Match("n", "November"),
                       SpelledCharacter.Match("o", "Oscar"),
                       SpelledCharacter.Match("p", "Papa"),
                       SpelledCharacter.Match("q", "Quebec"),
                       SpelledCharacter.Match("r", "Romeo"),
                       SpelledCharacter.Match("s", "Sierra"),
                       SpelledCharacter.Match("t", "Tango"),
                       SpelledCharacter.Match("u", "Uniform"),
                       SpelledCharacter.Match("v", "Victor"),
                       SpelledCharacter.Match("w", "Whiskey"),
                       SpelledCharacter.Match("x", "X-ray"),
                       SpelledCharacter.Match("y", "Yankee"),
                       SpelledCharacter.Match("z", "Zulu"),
                       SpelledCharacter.Match("A", "Alfa"),
                       SpelledCharacter.Match("B", "Bravo"),
                       SpelledCharacter.Match("C", "Charlie"),
                       SpelledCharacter.Match("D", "Delta"),
                       SpelledCharacter.Match("E", "Echo"),
                       SpelledCharacter.Match("F", "Foxtrot"),
                       SpelledCharacter.Match("G", "Golf"),
                       SpelledCharacter.Match("H", "Hotel"),
                       SpelledCharacter.Match("I", "India"),
                       SpelledCharacter.Match("J", "Juliett"),
                       SpelledCharacter.Match("K", "Kilo"),
                       SpelledCharacter.Match("L", "Lima"),
                       SpelledCharacter.Match("M", "Mike"),
                       SpelledCharacter.Match("N", "November"),
                       SpelledCharacter.Match("O", "Oscar"),
                       SpelledCharacter.Match("P", "Papa"),
                       SpelledCharacter.Match("Q", "Quebec"),
                       SpelledCharacter.Match("R", "Romeo"),
                       SpelledCharacter.Match("S", "Sierra"),
                       SpelledCharacter.Match("T", "Tango"),
                       SpelledCharacter.Match("U", "Uniform"),
                       SpelledCharacter.Match("V", "Victor"),
                       SpelledCharacter.Match("W", "Whiskey"),
                       SpelledCharacter.Match("X", "X-ray"),
                       SpelledCharacter.Match("Y", "Yankee"),
                       SpelledCharacter.Match("Z", "Zulu")]

        XCTAssertEqual(spelling, control, "Spelling the latin alphabet with the International Radiotelephoney spelling alphabet has failed")
    }

    func testSpellingCzech() {
        let phrase = "<NAME>"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Czech)
        let control = [
            SpelledCharacter.Match("Č", "Cyril"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("s", "Svatopluk"),
            SpelledCharacter.Match("k", "Karel"),
            SpelledCharacter.Match("é", "Emil"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("B", "Božena"),
            SpelledCharacter.Match("u", "Urban"),
            SpelledCharacter.Match("d", "David"),
            SpelledCharacter.Match("ě", "Emil"),
            SpelledCharacter.Match("j", "Josef"),
            SpelledCharacter.Match("o", "Otakar"),
            SpelledCharacter.Match("v", "Václav"),
            SpelledCharacter.Match("i", "Ivan"),
            SpelledCharacter.Match("c", "Cyril"),
            SpelledCharacter.Match("e", "Emil")
        ]

        XCTAssertEqual(spelling, control, "Czech spelling is wrong")
    }

    func testSpellingDanish() {
        let phrase = "ægir & sørenå"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Danish)
        let control = [
            SpelledCharacter.Match("æ", "Ægir"),
            SpelledCharacter.Match("g", "Georg"),
            SpelledCharacter.Match("i", "Ida"),
            SpelledCharacter.Match("r", "Rasmus"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Description("&", "Ampersand"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("s", "Søren"),
            SpelledCharacter.Match("ø", "Øresund"),
            SpelledCharacter.Match("r", "Rasmus"),
            SpelledCharacter.Match("e", "Erik"),
            SpelledCharacter.Match("n", "Nikolaj"),
            SpelledCharacter.Match("å", "Aase")
        ]

        XCTAssertEqual(spelling, control, "Danish spelling is wrong")
    }

    func testSpellingDutch() {
        let phrase = "Rĳksmuseum"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Dutch)
        let control = [
            SpelledCharacter.Match("R", "Richard"),
            SpelledCharacter.Match("ĳ", "Ĳmuiden"),
            SpelledCharacter.Match("k", "Karel"),
            SpelledCharacter.Match("s", "Simon"),
            SpelledCharacter.Match("m", "Maria"),
            SpelledCharacter.Match("u", "Utrecht"),
            SpelledCharacter.Match("s", "Simon"),
            SpelledCharacter.Match("e", "Eduard"),
            SpelledCharacter.Match("u", "Utrecht"),
            SpelledCharacter.Match("m", "Maria")
        ]

        XCTAssertEqual(spelling, control, "Dutch spelling is wrong")
    }

    func testSpellingFinnish() {
        let phrase = "öå-äiti"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Finnish)
        let control = [
            SpelledCharacter.Match("ö", "Öljy"),
            SpelledCharacter.Match("å", "Åke"),
            SpelledCharacter.Description("-", "Hyphen-minus"),
            SpelledCharacter.Match("ä", "Äiti"),
            SpelledCharacter.Match("i", "Iivari"),
            SpelledCharacter.Match("t", "Tyyne"),
            SpelledCharacter.Match("i", "Iivari")
        ]

        XCTAssertEqual(spelling, control, "Finnish spelling is wrong")
    }

    func testSpellingFrench() {
        let phrase = "Montpellier"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .French)
        let control = [
            SpelledCharacter.Match("M", "Marcel"),
            SpelledCharacter.Match("o", "Oscar"),
            SpelledCharacter.Match("n", "Nicolas"),
            SpelledCharacter.Match("t", "Thérèse"),
            SpelledCharacter.Match("p", "Pierre"),
            SpelledCharacter.Match("e", "Eugène"),
            SpelledCharacter.Match("l", "Louis"),
            SpelledCharacter.Match("l", "Louis"),
            SpelledCharacter.Match("i", "Irma"),
            SpelledCharacter.Match("e", "Eugène"),
            SpelledCharacter.Match("r", "Raoul")
        ]

        XCTAssertEqual(spelling, control, "French spelling is wrong")
    }

    func testSpellingGerman() {
        let phrase = "Möbelträgerfüße"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .German)
        let control = [
            SpelledCharacter.Match("M", "Martha"),
            SpelledCharacter.Match("ö", "Ökonom"),
            SpelledCharacter.Match("b", "Berta"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("l", "Ludwig"),
            SpelledCharacter.Match("t", "Theodor"),
            SpelledCharacter.Match("r", "Richard"),
            SpelledCharacter.Match("ä", "Ärger"),
            SpelledCharacter.Match("g", "Gustav"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("r", "Richard"),
            SpelledCharacter.Match("f", "Friedrich"),
            SpelledCharacter.Match("ü", ["Übermut", "Übel"]),
            SpelledCharacter.Match("ß", "Eszett"),
            SpelledCharacter.Match("e", "Emil")
        ]

        XCTAssertEqual(spelling, control, "German spelling is wrong")
    }

    func testSpellingItalian() {
        let phrase = "Xilofono"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Italian)
        let control = [
            SpelledCharacter.Match("X", ["Xeres", "Xilofono"]),
            SpelledCharacter.Match("i", "Imola"),
            SpelledCharacter.Match("l", "Livorno"),
            SpelledCharacter.Match("o", "Otranto"),
            SpelledCharacter.Match("f", "Firenze"),
            SpelledCharacter.Match("o", "Otranto"),
            SpelledCharacter.Match("n", "Napoli"),
            SpelledCharacter.Match("o", "Otranto")
        ]

        XCTAssertEqual(spelling, control, "Italian spelling is wrong")
    }

    func testSpellingNorwegian() {
        let phrase = "åse, ærlig & østen"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Norwegian)
        let control = [
            SpelledCharacter.Match("å", "Åse"),
            SpelledCharacter.Match("s", "Sigrid"),
            SpelledCharacter.Match("e", "Edith"),
            SpelledCharacter.Description(",", "Comma"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("æ", "Ærlig"),<commit_msg>More unit tests for Speller<commit_after>//
//  SpellerTests.swift
//  Speller
//
//  Created by Jean-Étienne on 8/11/16.
//  Copyright © 2016 Jean-Étienne. All rights reserved.
//

import XCTest

class SpellerTests: XCTestCase {

    func testSpellingWorks() {
        let spelling = Speller.spell(phrase: "Bagpipe", withSpellingAlphabet: .InternationalRadiotelephony)

        XCTAssertNotNil(spelling)
    }

    func testSpellingAllLetters() {
        let word = "Bagpipe"
        let spelling = Speller.spell(phrase: word, withSpellingAlphabet: .InternationalRadiotelephony)

        XCTAssertEqual(spelling.count, word.characters.count)
    }
    
    func testSpellingAllLettersAccuratelyWithInternationalRadiotelephony() {
        let phrase = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .InternationalRadiotelephony)
        let control = [SpelledCharacter.Match("a", "Alfa"),
                       SpelledCharacter.Match("b", "Bravo"),
                       SpelledCharacter.Match("c", "Charlie"),
                       SpelledCharacter.Match("d", "Delta"),
                       SpelledCharacter.Match("e", "Echo"),
                       SpelledCharacter.Match("f", "Foxtrot"),
                       SpelledCharacter.Match("g", "Golf"),
                       SpelledCharacter.Match("h", "Hotel"),
                       SpelledCharacter.Match("i", "India"),
                       SpelledCharacter.Match("j", "Juliett"),
                       SpelledCharacter.Match("k", "Kilo"),
                       SpelledCharacter.Match("l", "Lima"),
                       SpelledCharacter.Match("m", "Mike"),
                       SpelledCharacter.Match("n", "November"),
                       SpelledCharacter.Match("o", "Oscar"),
                       SpelledCharacter.Match("p", "Papa"),
                       SpelledCharacter.Match("q", "Quebec"),
                       SpelledCharacter.Match("r", "Romeo"),
                       SpelledCharacter.Match("s", "Sierra"),
                       SpelledCharacter.Match("t", "Tango"),
                       SpelledCharacter.Match("u", "Uniform"),
                       SpelledCharacter.Match("v", "Victor"),
                       SpelledCharacter.Match("w", "Whiskey"),
                       SpelledCharacter.Match("x", "X-ray"),
                       SpelledCharacter.Match("y", "Yankee"),
                       SpelledCharacter.Match("z", "Zulu"),
                       SpelledCharacter.Match("A", "Alfa"),
                       SpelledCharacter.Match("B", "Bravo"),
                       SpelledCharacter.Match("C", "Charlie"),
                       SpelledCharacter.Match("D", "Delta"),
                       SpelledCharacter.Match("E", "Echo"),
                       SpelledCharacter.Match("F", "Foxtrot"),
                       SpelledCharacter.Match("G", "Golf"),
                       SpelledCharacter.Match("H", "Hotel"),
                       SpelledCharacter.Match("I", "India"),
                       SpelledCharacter.Match("J", "Juliett"),
                       SpelledCharacter.Match("K", "Kilo"),
                       SpelledCharacter.Match("L", "Lima"),
                       SpelledCharacter.Match("M", "Mike"),
                       SpelledCharacter.Match("N", "November"),
                       SpelledCharacter.Match("O", "Oscar"),
                       SpelledCharacter.Match("P", "Papa"),
                       SpelledCharacter.Match("Q", "Quebec"),
                       SpelledCharacter.Match("R", "Romeo"),
                       SpelledCharacter.Match("S", "Sierra"),
                       SpelledCharacter.Match("T", "Tango"),
                       SpelledCharacter.Match("U", "Uniform"),
                       SpelledCharacter.Match("V", "Victor"),
                       SpelledCharacter.Match("W", "Whiskey"),
                       SpelledCharacter.Match("X", "X-ray"),
                       SpelledCharacter.Match("Y", "Yankee"),
                       SpelledCharacter.Match("Z", "Zulu")]

        XCTAssertEqual(spelling, control, "Spelling the latin alphabet with the International Radiotelephoney spelling alphabet has failed")
    }

    func testSpellingCzech() {
        let phrase = "České Budějovice"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Czech)
        let control = [
            SpelledCharacter.Match("Č", "Cyril"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("s", "Svatopluk"),
            SpelledCharacter.Match("k", "Karel"),
            SpelledCharacter.Match("é", "Emil"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("B", "Božena"),
            SpelledCharacter.Match("u", "Urban"),
            SpelledCharacter.Match("d", "David"),
            SpelledCharacter.Match("ě", "Emil"),
            SpelledCharacter.Match("j", "Josef"),
            SpelledCharacter.Match("o", "Otakar"),
            SpelledCharacter.Match("v", "Václav"),
            SpelledCharacter.Match("i", "Ivan"),
            SpelledCharacter.Match("c", "Cyril"),
            SpelledCharacter.Match("e", "Emil")
        ]

        XCTAssertEqual(spelling, control, "Czech spelling is wrong")
    }

    func testSpellingDanish() {
        let phrase = "ægir & sørenå"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Danish)
        let control = [
            SpelledCharacter.Match("æ", "Ægir"),
            SpelledCharacter.Match("g", "Georg"),
            SpelledCharacter.Match("i", "Ida"),
            SpelledCharacter.Match("r", "Rasmus"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Description("&", "Ampersand"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("s", "Søren"),
            SpelledCharacter.Match("ø", "Øresund"),
            SpelledCharacter.Match("r", "Rasmus"),
            SpelledCharacter.Match("e", "Erik"),
            SpelledCharacter.Match("n", "Nikolaj"),
            SpelledCharacter.Match("å", "Aase")
        ]

        XCTAssertEqual(spelling, control, "Danish spelling is wrong")
    }

    func testSpellingDutch() {
        let phrase = "Rĳksmuseum"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Dutch)
        let control = [
            SpelledCharacter.Match("R", "Richard"),
            SpelledCharacter.Match("ĳ", "Ĳmuiden"),
            SpelledCharacter.Match("k", "Karel"),
            SpelledCharacter.Match("s", "Simon"),
            SpelledCharacter.Match("m", "Maria"),
            SpelledCharacter.Match("u", "Utrecht"),
            SpelledCharacter.Match("s", "Simon"),
            SpelledCharacter.Match("e", "Eduard"),
            SpelledCharacter.Match("u", "Utrecht"),
            SpelledCharacter.Match("m", "Maria")
        ]

        XCTAssertEqual(spelling, control, "Dutch spelling is wrong")
    }

    func testSpellingFinnish() {
        let phrase = "öå-äiti"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Finnish)
        let control = [
            SpelledCharacter.Match("ö", "Öljy"),
            SpelledCharacter.Match("å", "Åke"),
            SpelledCharacter.Description("-", "Hyphen-minus"),
            SpelledCharacter.Match("ä", "Äiti"),
            SpelledCharacter.Match("i", "Iivari"),
            SpelledCharacter.Match("t", "Tyyne"),
            SpelledCharacter.Match("i", "Iivari")
        ]

        XCTAssertEqual(spelling, control, "Finnish spelling is wrong")
    }

    func testSpellingFrench() {
        let phrase = "Montpellier"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .French)
        let control = [
            SpelledCharacter.Match("M", "Marcel"),
            SpelledCharacter.Match("o", "Oscar"),
            SpelledCharacter.Match("n", "Nicolas"),
            SpelledCharacter.Match("t", "Thérèse"),
            SpelledCharacter.Match("p", "Pierre"),
            SpelledCharacter.Match("e", "Eugène"),
            SpelledCharacter.Match("l", "Louis"),
            SpelledCharacter.Match("l", "Louis"),
            SpelledCharacter.Match("i", "Irma"),
            SpelledCharacter.Match("e", "Eugène"),
            SpelledCharacter.Match("r", "Raoul")
        ]

        XCTAssertEqual(spelling, control, "French spelling is wrong")
    }

    func testSpellingGerman() {
        let phrase = "Möbelträgerfüße"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .German)
        let control = [
            SpelledCharacter.Match("M", "Martha"),
            SpelledCharacter.Match("ö", "Ökonom"),
            SpelledCharacter.Match("b", "Berta"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("l", "Ludwig"),
            SpelledCharacter.Match("t", "Theodor"),
            SpelledCharacter.Match("r", "Richard"),
            SpelledCharacter.Match("ä", "Ärger"),
            SpelledCharacter.Match("g", "Gustav"),
            SpelledCharacter.Match("e", "Emil"),
            SpelledCharacter.Match("r", "Richard"),
            SpelledCharacter.Match("f", "Friedrich"),
            SpelledCharacter.Match("ü", ["Übermut", "Übel"]),
            SpelledCharacter.Match("ß", "Eszett"),
            SpelledCharacter.Match("e", "Emil")
        ]

        XCTAssertEqual(spelling, control, "German spelling is wrong")
    }
    
    func testSpellingGermanInFinnish() {
        let phrase = "Möbelträgerfüße"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Finnish)
        let control = [
            SpelledCharacter.Match("M", "Matti"),
            SpelledCharacter.Match("ö", "Öljy"),
            SpelledCharacter.Match("b", "Bertta"),
            SpelledCharacter.Match("e", "Eemeli"),
            SpelledCharacter.Match("l", "Lauri"),
            SpelledCharacter.Match("t", "Tyyne"),
            SpelledCharacter.Match("r", "Risto"),
            SpelledCharacter.Match("ä", "Äiti"),
            SpelledCharacter.Match("g", "Gideon"),
            SpelledCharacter.Match("e", "Eemeli"),
            SpelledCharacter.Match("r", "Risto"),
            SpelledCharacter.Match("f", "Faarao"),
            SpelledCharacter.Match("ü", "Urho"),
            SpelledCharacter.Description("ß", "Latin small letter sharp S"),
            SpelledCharacter.Match("e", "Eemeli")
        ]

        XCTAssertEqual(spelling, control, "Finnish spelling of German word is wrong")
    }
    
    func testSpellingItalian() {
        let phrase = "Xilofono"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Italian)
        let control = [
            SpelledCharacter.Match("X", ["Xeres", "Xilofono"]),
            SpelledCharacter.Match("i", "Imola"),
            SpelledCharacter.Match("l", "Livorno"),
            SpelledCharacter.Match("o", "Otranto"),
            SpelledCharacter.Match("f", "Firenze"),
            SpelledCharacter.Match("o", "Otranto"),
            SpelledCharacter.Match("n", "Napoli"),
            SpelledCharacter.Match("o", "Otranto")
        ]

        XCTAssertEqual(spelling, control, "Italian spelling is wrong")
    }

    func testSpellingNorwegian() {
        let phrase = "åse, ærlig & østen"
        let spelling = Speller.spell(phrase: phrase, withSpellingAlphabet: .Norwegian)
        let control = [
            SpelledCharacter.Match("å", "Åse"),
            SpelledCharacter.Match("s", "Sigrid"),
            SpelledCharacter.Match("e", "Edith"),
            SpelledCharacter.Description(",", "Comma"),
            SpelledCharacter.Description(" ", "Space"),
            SpelledCharacter.Match("æ", "Ærlig"),
{'fraction_non_alphanumeric': 0.14321361732465912, 'fraction_numerical': 0.0008020675519115943, 'mean_word_length': 2.0981501932633906, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1542294', 'n_tokens_mistral': 6417, 'n_tokens_neox': 6121, 'n_words': 1052}