1
exercism fetch swift nucleotide-count

Tests/LinuxMain.swift

1
2
3
4
5
6
import XCTest
@testable import NucleotideCountTests

XCTMain([
    testCase(NucleotideCountTests.allTests),
    ])

Tests/NucleotideCountTests/NucleotideCountTests.swift

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
import XCTest
@testable import NucleotideCount

class NucleotideCountTests: XCTestCase {
    func testEmptyDNAStringHasNoAdenosine() {
        let dna = DNA(strand: "")!
        let result = dna.count("A")
        let expected = 0
        XCTAssertEqual(result, expected)
    }

    func testEmptyDNAStringHasNoNucleotides() {
        let dna = DNA(strand: "")!
        let results = dna.counts()
        let expected = ["T": 0, "A": 0, "C": 0, "G": 0]
        XCTAssertEqual(results, expected)
    }

    func testRepetitiveCytidineGetsCounted() {
        let dna = DNA(strand: "CCCCC")!
        let result = dna.count("C")
        let expected = 5
        XCTAssertEqual(result, expected)
    }

    func testRepetitiveSequenceHasOnlyGuanosine() {
        let dna = DNA(strand: "GGGGGGGG")!
        let results = dna.counts()
        let expected = [ "A": 0, "T": 0, "C": 0, "G": 8 ]
        XCTAssertEqual(results, expected)
    }

    func testCountsByThymidine() {
        let dna = DNA(strand: "GGGGGTAACCCGG")!
        let result = dna.count("T")
        let expected = 1
        XCTAssertEqual(result, expected)
    }

    func testCountsANucleotideOnlyOnce() {
        let dna = DNA(strand: "CGATTGGG")!
        let result = dna.count("T")
        let expected = 2
        XCTAssertEqual(result, expected)
    }

    func testValidatesDNA() {
        XCTAssert(DNA(strand: "John") == nil )
    }

    func testCountsAllNucleotides() {
        let longStrand = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
        let dna = DNA(strand: longStrand)!
        let results = dna.counts()
        let expected = [ "A": 20, "T": 21, "C": 12, "G": 17 ]
        XCTAssertEqual(results, expected)
    }

    static var allTests: [(String, (NucleotideCountTests) -> () throws -> Void)] {
        return [
            ("testEmptyDNAStringHasNoAdenosine", testEmptyDNAStringHasNoAdenosine),
            ("testEmptyDNAStringHasNoNucleotides", testEmptyDNAStringHasNoNucleotides),
            ("testRepetitiveCytidineGetsCounted", testRepetitiveCytidineGetsCounted),
            ("testRepetitiveSequenceHasOnlyGuanosine", testRepetitiveSequenceHasOnlyGuanosine),
            ("testCountsByThymidine", testCountsByThymidine),
            ("testCountsANucleotideOnlyOnce", testCountsANucleotideOnlyOnce),
            ("testValidatesDNA", testValidatesDNA),
            ("testCountsAllNucleotides", testCountsAllNucleotides),
        ]
    }
}