Skip to content

Commit

Permalink
Merge pull request #357 from Zialus/master
Browse files Browse the repository at this point in the history
Improvements to Rna Transcript Tests
  • Loading branch information
masters3d committed Aug 7, 2018
2 parents 68df265 + 856f3a9 commit 0017833
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
@@ -1,5 +1,5 @@
enum TranscriptionError: Error {
case invalidNucleotide
case invalidNucleotide(String)
}

struct Nucleotide {
Expand All @@ -19,7 +19,7 @@ struct Nucleotide {
var tempText = ""
for each in self.value.characters {
if dict[each] == nil {
throw TranscriptionError.invalidNucleotide
throw TranscriptionError.invalidNucleotide("\(each) is not a valid Nucleotide")
}
tempText += dict[each] ?? ""
}
Expand Down
Expand Up @@ -23,30 +23,33 @@ class RnaTranscriptionTests: XCTestCase {
}

func testInvalidRnaComplementOfUracil() {
XCTAssertThrowsError(try Nucleotide("U").complementOfDNA())

// Uncomment to see more specific error handling
// XCTAssertThrowsError(try Nucleotide("U").complementOfDNA(), "This didn't work") { (error) in
// XCTAssertEqual(error as? RnaTranscription.TranscriptionError, RnaTranscription.TranscriptionError.invalidNucleotide)
// }
XCTAssertThrowsError(try Nucleotide("U").complementOfDNA()) { (error) in
if case let RnaTranscription.TranscriptionError.invalidNucleotide(message) = error {
XCTAssertTrue(message == "U is not a valid Nucleotide")
} else {
XCTFail("Expected error not thrown")
}
}
}

func testInvalidRnaComplementOfXXX() {
XCTAssertThrowsError(try Nucleotide("XXX").complementOfDNA())

// Uncomment to see more specific error handling
// XCTAssertThrowsError(try Nucleotide("XXX").complementOfDNA(), "This didn't work") { (error) in
// XCTAssertEqual(error as? RnaTranscription.TranscriptionError, RnaTranscription.TranscriptionError.invalidNucleotide)
// }
XCTAssertThrowsError(try Nucleotide("XXX").complementOfDNA()) { (error) in
if case let RnaTranscription.TranscriptionError.invalidNucleotide(message) = error {
XCTAssertTrue(message == "X is not a valid Nucleotide")
} else {
XCTFail("Expected error not thrown")
}
}
}

func testInvalidRnaComplementOfACGTXXXCTTAA() {
XCTAssertThrowsError(try Nucleotide("ACGTXXXCTTAA").complementOfDNA())

// Uncomment to see more specific error handling
// XCTAssertThrowsError(try Nucleotide("ACGTXXXCTTAA").complementOfDNA(), "This didn't work") { (error) in
// XCTAssertEqual(error as? RnaTranscription.TranscriptionError, RnaTranscription.TranscriptionError.invalidNucleotide)
// }
XCTAssertThrowsError(try Nucleotide("ACGTXXXCTTAA").complementOfDNA()) { error in
if case let RnaTranscription.TranscriptionError.invalidNucleotide(message) = error {
XCTAssertTrue(message == "X is not a valid Nucleotide")
} else {
XCTFail("Expected error not thrown")
}
}
}

static var allTests: [(String, (RnaTranscriptionTests) -> () throws -> Void)] {
Expand Down

0 comments on commit 0017833

Please sign in to comment.