Skip to content

Commit

Permalink
Update test_protein-translation.R
Browse files Browse the repository at this point in the history
function name changed
  • Loading branch information
colinleach authored Feb 3, 2024
1 parent d8f76f1 commit 1faa06f
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions exercises/practice/protein-translation/test_protein-translation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,124 @@ source('./protein-translation.R')
library(testthat)

test_that("Empty RNA sequence results in no proteins", {
expect_equal(proteins(""), NULL)
expect_equal(translate(""), NULL)
})

test_that("Methionine RNA sequence", {
expect_equal(proteins("AUG"), 'Methionine')
expect_equal(translate("AUG"), 'Methionine')
})

test_that("Phenylalanine RNA sequence 1", {
expect_equal(proteins("UUU"), 'Phenylalanine')
expect_equal(translate("UUU"), 'Phenylalanine')
})

test_that("Phenylalanine RNA sequence 2", {
expect_equal(proteins("UUC"), 'Phenylalanine')
expect_equal(translate("UUC"), 'Phenylalanine')
})

test_that("Leucine RNA sequence 1", {
expect_equal(proteins("UUA"), 'Leucine')
expect_equal(translate("UUA"), 'Leucine')
})

test_that("Leucine RNA sequence 2", {
expect_equal(proteins("UUG"), 'Leucine')
expect_equal(translate("UUG"), 'Leucine')
})

test_that("Serine RNA sequence 1", {
expect_equal(proteins("UCU"), 'Serine')
expect_equal(translate("UCU"), 'Serine')
})

test_that("Serine RNA sequence 2", {
expect_equal(proteins("UCC"), 'Serine')
expect_equal(translate("UCC"), 'Serine')
})

test_that("Serine RNA sequence 3", {
expect_equal(proteins("UCA"), 'Serine')
expect_equal(translate("UCA"), 'Serine')
})

test_that("Serine RNA sequence 4", {
expect_equal(proteins("UCG"), 'Serine')
expect_equal(translate("UCG"), 'Serine')
})

test_that("Tyrosine RNA sequence 1", {
expect_equal(proteins("UAU"), 'Tyrosine')
expect_equal(translate("UAU"), 'Tyrosine')
})

test_that("Tyrosine RNA sequence 2", {
expect_equal(proteins("UAC"), 'Tyrosine')
expect_equal(translate("UAC"), 'Tyrosine')
})

test_that("Cysteine RNA sequence 1", {
expect_equal(proteins("UGU"), 'Cysteine')
expect_equal(translate("UGU"), 'Cysteine')
})

test_that("Cysteine RNA sequence 2", {
expect_equal(proteins("UGC"), 'Cysteine')
expect_equal(translate("UGC"), 'Cysteine')
})

test_that("Tryptophan RNA sequence", {
expect_equal(proteins("UGG"), 'Tryptophan')
expect_equal(translate("UGG"), 'Tryptophan')
})

test_that("STOP codon RNA sequence 1", {
expect_equal(proteins("UAA"), c())
expect_equal(translate("UAA"), c())
})

test_that("STOP codon RNA sequence 2", {
expect_equal(proteins("UAG"), c())
expect_equal(translate("UAG"), c())
})

test_that("STOP codon RNA sequence 3", {
expect_equal(proteins("UGA"), c())
expect_equal(translate("UGA"), c())
})

test_that("Sequence of two protein codons translates into proteins", {
expect_equal(proteins("UUUUUU"), c('Phenylalanine', 'Phenylalanine'))
expect_equal(translate("UUUUUU"), c('Phenylalanine', 'Phenylalanine'))
})

test_that("Sequence of two different protein codons translates into proteins", {
expect_equal(proteins("UUAUUG"), c('Leucine', 'Leucine'))
expect_equal(translate("UUAUUG"), c('Leucine', 'Leucine'))
})

test_that("Translate RNA strand into correct protein list", {
expect_equal(proteins("AUGUUUUGG"),
expect_equal(translate("AUGUUUUGG"),
c('Methionine', 'Phenylalanine', 'Tryptophan'))
})

test_that("Translation stops if STOP codon at beginning of sequence", {
expect_equal(proteins("UAGUGG"), c())
expect_equal(translate("UAGUGG"), c())
})

test_that("Translation stops if STOP codon at end of two-codon sequence", {
expect_equal(proteins("UGGUAG"), c('Tryptophan'))
expect_equal(translate("UGGUAG"), c('Tryptophan'))
})

test_that("Translation stops if STOP codon at end of three-codon sequence", {
expect_equal(proteins("AUGUUUUAA"), c('Methionine', 'Phenylalanine'))
expect_equal(translate("AUGUUUUAA"), c('Methionine', 'Phenylalanine'))
})

test_that("Translation stops if STOP codon in middle of three-codon sequence", {
expect_equal(proteins("UGGUAGUGG"), c('Tryptophan'))
expect_equal(translate("UGGUAGUGG"), c('Tryptophan'))
})

test_that("Translation stops if STOP codon in middle of six-codon sequence", {
expect_equal(proteins("UGGUGUUAUUAAUGGUUU"),
expect_equal(translate("UGGUGUUAUUAAUGGUUU"),
c('Tryptophan', 'Cysteine', 'Tyrosine'))
})

test_that("Non-existing codon can't translate", {
expect_error(proteins("AAA"))
expect_error(translate("AAA"))
})

test_that("Unknown amino acids, not part of a codon, can't translate", {
expect_error(proteins("XYZ"))
expect_error(translate("XYZ"))
})

test_that("Incomplete RNA sequence can't translate", {
expect_error(proteins("AUGU"))
expect_error(translate("AUGU"))
})

test_that("Incomplete RNA sequence can translate if valid until a STOP codon", {
expect_equal(proteins("UUCUUCUAAUGGU"), c('Phenylalanine', 'Phenylalanine'))
expect_equal(translate("UUCUUCUAAUGGU"), c('Phenylalanine', 'Phenylalanine'))
})

0 comments on commit 1faa06f

Please sign in to comment.