Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exercises/practice/protein-translation/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"MichaelBunker"
],
"contributors": [
"resu-xuniL"
],
"files": {
"solution": [
"ProteinTranslation.php"
Expand Down
97 changes: 60 additions & 37 deletions exercises/practice/protein-translation/ProteinTranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@

class ProteinTranslationTest extends TestCase
{
private ProteinTranslation $translator;

public static function setUpBeforeClass(): void
{
require_once 'ProteinTranslation.php';
}

public function setUp(): void
{
$this->translator = new ProteinTranslation();
}

/**
* uuid 2c44f7bf-ba20-43f7-a3bf-f2219c0c3f98
*/
#[TestDox('Empty RNA sequence results in no proteins')]
public function testEmptyRnaSequence(): void
{
$this->assertEquals([], $this->translator->getProteins(''));
$translator = new ProteinTranslation();
$this->assertEquals([], $translator->getProteins(''));
}

/**
Expand All @@ -34,7 +28,8 @@ public function testEmptyRnaSequence(): void
#[TestDox('Methionine RNA sequence')]
public function testMethionineRnaSequence(): void
{
$this->assertEquals(['Methionine'], $this->translator->getProteins('AUG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Methionine'], $translator->getProteins('AUG'));
}

/**
Expand All @@ -43,7 +38,8 @@ public function testMethionineRnaSequence(): void
#[TestDox('Phenylalanine RNA sequence 1')]
public function testPhenylalanineRnaSequenceOne(): void
{
$this->assertEquals(['Phenylalanine'], $this->translator->getProteins('UUU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Phenylalanine'], $translator->getProteins('UUU'));
}

/**
Expand All @@ -52,7 +48,8 @@ public function testPhenylalanineRnaSequenceOne(): void
#[TestDox('Phenylalanine RNA sequence 2')]
public function testPhenylalanineRnaSequenceTwo(): void
{
$this->assertEquals(['Phenylalanine'], $this->translator->getProteins('UUC'));
$translator = new ProteinTranslation();
$this->assertEquals(['Phenylalanine'], $translator->getProteins('UUC'));
}

/**
Expand All @@ -61,7 +58,8 @@ public function testPhenylalanineRnaSequenceTwo(): void
#[TestDox('Leucine RNA sequence 1')]
public function testLeucineRnaSequenceOne(): void
{
$this->assertEquals(['Leucine'], $this->translator->getProteins('UUA'));
$translator = new ProteinTranslation();
$this->assertEquals(['Leucine'], $translator->getProteins('UUA'));
}

/**
Expand All @@ -70,7 +68,8 @@ public function testLeucineRnaSequenceOne(): void
#[TestDox('Leucine RNA sequence 2')]
public function testLeucineRnaSequenceTwo(): void
{
$this->assertEquals(['Leucine'], $this->translator->getProteins('UUG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Leucine'], $translator->getProteins('UUG'));
}

/**
Expand All @@ -79,7 +78,8 @@ public function testLeucineRnaSequenceTwo(): void
#[TestDox('Serine RNA sequence 1')]
public function testSerineRnaSequenceOne(): void
{
$this->assertEquals(['Serine'], $this->translator->getProteins('UCU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Serine'], $translator->getProteins('UCU'));
}

/**
Expand All @@ -88,7 +88,8 @@ public function testSerineRnaSequenceOne(): void
#[TestDox('Serine RNA sequence 2')]
public function testSerineRnaSequenceTwo(): void
{
$this->assertEquals(['Serine'], $this->translator->getProteins('UCC'));
$translator = new ProteinTranslation();
$this->assertEquals(['Serine'], $translator->getProteins('UCC'));
}

/**
Expand All @@ -97,7 +98,8 @@ public function testSerineRnaSequenceTwo(): void
#[TestDox('Serine RNA sequence 3')]
public function testSerineRnaSequenceThree(): void
{
$this->assertEquals(['Serine'], $this->translator->getProteins('UCA'));
$translator = new ProteinTranslation();
$this->assertEquals(['Serine'], $translator->getProteins('UCA'));
}

/**
Expand All @@ -106,7 +108,8 @@ public function testSerineRnaSequenceThree(): void
#[TestDox('Serine RNA sequence 4')]
public function testSerineRnaSequenceFour(): void
{
$this->assertEquals(['Serine'], $this->translator->getProteins('UCG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Serine'], $translator->getProteins('UCG'));
}

/**
Expand All @@ -115,7 +118,8 @@ public function testSerineRnaSequenceFour(): void
#[TestDox('Tyrosine RNA sequence 1')]
public function testTyrosineRnaSequenceOne(): void
{
$this->assertEquals(['Tyrosine'], $this->translator->getProteins('UAU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Tyrosine'], $translator->getProteins('UAU'));
}

/**
Expand All @@ -124,7 +128,8 @@ public function testTyrosineRnaSequenceOne(): void
#[TestDox('Tyrosine RNA sequence 2')]
public function testTyrosineRnaSequenceTwo(): void
{
$this->assertEquals(['Tyrosine'], $this->translator->getProteins('UAC'));
$translator = new ProteinTranslation();
$this->assertEquals(['Tyrosine'], $translator->getProteins('UAC'));
}

/**
Expand All @@ -133,7 +138,8 @@ public function testTyrosineRnaSequenceTwo(): void
#[TestDox('Cysteine RNA sequence 1')]
public function testCysteineRnaSequenceOne(): void
{
$this->assertEquals(['Cysteine'], $this->translator->getProteins('UGU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Cysteine'], $translator->getProteins('UGU'));
}

/**
Expand All @@ -142,7 +148,8 @@ public function testCysteineRnaSequenceOne(): void
#[TestDox('Cysteine RNA sequence 2')]
public function testCysteineRnaSequenceTwo(): void
{
$this->assertEquals(['Cysteine'], $this->translator->getProteins('UGC'));
$translator = new ProteinTranslation();
$this->assertEquals(['Cysteine'], $translator->getProteins('UGC'));
}

/**
Expand All @@ -151,7 +158,8 @@ public function testCysteineRnaSequenceTwo(): void
#[TestDox('Tryptophan RNA sequence')]
public function testTryptophanRnaSequence(): void
{
$this->assertEquals(['Tryptophan'], $this->translator->getProteins('UGG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Tryptophan'], $translator->getProteins('UGG'));
}

/**
Expand All @@ -160,7 +168,8 @@ public function testTryptophanRnaSequence(): void
#[TestDox('STOP codon RNA sequence 1')]
public function testStopCodonRnaSequenceOne(): void
{
$this->assertEquals([], $this->translator->getProteins('UAA'));
$translator = new ProteinTranslation();
$this->assertEquals([], $translator->getProteins('UAA'));
}

/**
Expand All @@ -169,7 +178,8 @@ public function testStopCodonRnaSequenceOne(): void
#[TestDox('STOP codon RNA sequence 2')]
public function testStopCodonRnaSequenceTwo(): void
{
$this->assertEquals([], $this->translator->getProteins('UAG'));
$translator = new ProteinTranslation();
$this->assertEquals([], $translator->getProteins('UAG'));
}

/**
Expand All @@ -178,7 +188,8 @@ public function testStopCodonRnaSequenceTwo(): void
#[TestDox('STOP codon RNA sequence 3')]
public function testStopCodonRnaSequenceThree(): void
{
$this->assertEquals([], $this->translator->getProteins('UGA'));
$translator = new ProteinTranslation();
$this->assertEquals([], $translator->getProteins('UGA'));
}

/**
Expand All @@ -187,7 +198,8 @@ public function testStopCodonRnaSequenceThree(): void
#[TestDox('Sequence of two protein codons translates into proteins')]
public function testToCodonsTranslateToProteins(): void
{
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $this->translator->getProteins('UUUUUU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $translator->getProteins('UUUUUU'));
}

/**
Expand All @@ -196,7 +208,8 @@ public function testToCodonsTranslateToProteins(): void
#[TestDox('Sequence of two different protein codons translates into proteins')]
public function testToDifferentCodonsTranslateToProteins(): void
{
$this->assertEquals(['Leucine', 'Leucine'], $this->translator->getProteins('UUAUUG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Leucine', 'Leucine'], $translator->getProteins('UUAUUG'));
}

/**
Expand All @@ -205,9 +218,10 @@ public function testToDifferentCodonsTranslateToProteins(): void
#[TestDox('Translate RNA strand into correct protein list')]
public function testTranslateRnaStrandIntoCorrectProteinList(): void
{
$translator = new ProteinTranslation();
$this->assertEquals(
['Methionine', 'Phenylalanine', 'Tryptophan'],
$this->translator->getProteins('AUGUUUUGG')
$translator->getProteins('AUGUUUUGG')
);
}

Expand All @@ -217,7 +231,8 @@ public function testTranslateRnaStrandIntoCorrectProteinList(): void
#[TestDox('Translation stops if STOP codon at beginning of sequence')]
public function testTranslationStopsIfStopCodonAtBeginningOfSequence(): void
{
$this->assertEquals([], $this->translator->getProteins('UAGUGG'));
$translator = new ProteinTranslation();
$this->assertEquals([], $translator->getProteins('UAGUGG'));
}

/**
Expand All @@ -226,7 +241,8 @@ public function testTranslationStopsIfStopCodonAtBeginningOfSequence(): void
#[TestDox('Translation stops if STOP codon at end of two-codon sequence')]
public function testTranslationStopsIfStopCodonAtEndOfTwoCodonSequence(): void
{
$this->assertEquals(['Tryptophan'], $this->translator->getProteins('UGGUAG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Tryptophan'], $translator->getProteins('UGGUAG'));
}

/**
Expand All @@ -235,7 +251,8 @@ public function testTranslationStopsIfStopCodonAtEndOfTwoCodonSequence(): void
#[TestDox('Translation stops if STOP codon at end of three-codon sequence')]
public function testTranslationStopsIfStopCodonAtEndOfThreeCodonSequence(): void
{
$this->assertEquals(['Methionine', 'Phenylalanine'], $this->translator->getProteins('AUGUUUUAA'));
$translator = new ProteinTranslation();
$this->assertEquals(['Methionine', 'Phenylalanine'], $translator->getProteins('AUGUUUUAA'));
}

/**
Expand All @@ -244,7 +261,8 @@ public function testTranslationStopsIfStopCodonAtEndOfThreeCodonSequence(): void
#[TestDox('Translation stops if STOP codon in middle of three-codon sequence"')]
public function testTranslationStopsIfStopCodonInMiddleOfThreeCodonSequence(): void
{
$this->assertEquals(['Tryptophan'], $this->translator->getProteins('UGGUAGUGG'));
$translator = new ProteinTranslation();
$this->assertEquals(['Tryptophan'], $translator->getProteins('UGGUAGUGG'));
}

/**
Expand All @@ -253,9 +271,10 @@ public function testTranslationStopsIfStopCodonInMiddleOfThreeCodonSequence(): v
#[TestDox('Translation stops if STOP codon in middle of six-codon sequence')]
public function testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence(): void
{
$translator = new ProteinTranslation();
$this->assertEquals(
['Tryptophan', 'Cysteine', 'Tyrosine'],
$this->translator->getProteins('UGGUGUUAUUAAUGGUUU')
$translator->getProteins('UGGUGUUAUUAAUGGUUU')
);
}

Expand All @@ -265,9 +284,10 @@ public function testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence(): voi
#[TestDox('Sequence of two non-STOP codons does not translate to a STOP codon')]
public function testSequenceOfTwoNonStopCodonsDoesNotTranslateToAStopCodon(): void
{
$translator = new ProteinTranslation();
$this->assertEquals(
['Methionine', 'Methionine'],
$this->translator->getProteins('AUGAUG')
$translator->getProteins('AUGAUG')
);
}

Expand All @@ -277,9 +297,10 @@ public function testSequenceOfTwoNonStopCodonsDoesNotTranslateToAStopCodon(): vo
#[TestDox("Unknown amino acids, not part of a codon, can't translate")]
public function testUnknownAminoAcidsCantTranslate(): void
{
$translator = new ProteinTranslation();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid codon');
$this->translator->getProteins('XYZ');
$translator->getProteins('XYZ');
}


Expand All @@ -289,9 +310,10 @@ public function testUnknownAminoAcidsCantTranslate(): void
#[TestDox("Incomplete RNA sequence can't translate")]
public function testIncompleteRnaSequenceCantTranslate(): void
{
$translator = new ProteinTranslation();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid codon');
$this->translator->getProteins('AUGU');
$translator->getProteins('AUGU');
}

/**
Expand All @@ -300,6 +322,7 @@ public function testIncompleteRnaSequenceCantTranslate(): void
#[TestDox('Incomplete RNA sequence can translate if valid until a STOP codon')]
public function testIncompleteRnaSequenceCanTranslateIfValidUntilStop(): void
{
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $this->translator->getProteins('UUCUUCUAAUGGU'));
$translator = new ProteinTranslation();
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $translator->getProteins('UUCUUCUAAUGGU'));
}
}
3 changes: 2 additions & 1 deletion exercises/practice/proverb/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"MichaelBunker"
],
"contributors": [
"luciagiampieri"
"luciagiampieri",
"resu-xuniL"
],
"files": {
"solution": [
Expand Down
Loading
Loading