Skip to content

Commit 70ff75d

Browse files
authored
Inline object instantiation part 2 (exercism#1030)
[no important files changed]
1 parent 0982754 commit 70ff75d

6 files changed

Lines changed: 129 additions & 88 deletions

File tree

exercises/practice/protein-translation/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"MichaelBunker"
44
],
5+
"contributors": [
6+
"resu-xuniL"
7+
],
58
"files": {
69
"solution": [
710
"ProteinTranslation.php"

exercises/practice/protein-translation/ProteinTranslationTest.php

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,19 @@
77

88
class ProteinTranslationTest extends TestCase
99
{
10-
private ProteinTranslation $translator;
11-
1210
public static function setUpBeforeClass(): void
1311
{
1412
require_once 'ProteinTranslation.php';
1513
}
1614

17-
public function setUp(): void
18-
{
19-
$this->translator = new ProteinTranslation();
20-
}
21-
2215
/**
2316
* uuid 2c44f7bf-ba20-43f7-a3bf-f2219c0c3f98
2417
*/
2518
#[TestDox('Empty RNA sequence results in no proteins')]
2619
public function testEmptyRnaSequence(): void
2720
{
28-
$this->assertEquals([], $this->translator->getProteins(''));
21+
$translator = new ProteinTranslation();
22+
$this->assertEquals([], $translator->getProteins(''));
2923
}
3024

3125
/**
@@ -34,7 +28,8 @@ public function testEmptyRnaSequence(): void
3428
#[TestDox('Methionine RNA sequence')]
3529
public function testMethionineRnaSequence(): void
3630
{
37-
$this->assertEquals(['Methionine'], $this->translator->getProteins('AUG'));
31+
$translator = new ProteinTranslation();
32+
$this->assertEquals(['Methionine'], $translator->getProteins('AUG'));
3833
}
3934

4035
/**
@@ -43,7 +38,8 @@ public function testMethionineRnaSequence(): void
4338
#[TestDox('Phenylalanine RNA sequence 1')]
4439
public function testPhenylalanineRnaSequenceOne(): void
4540
{
46-
$this->assertEquals(['Phenylalanine'], $this->translator->getProteins('UUU'));
41+
$translator = new ProteinTranslation();
42+
$this->assertEquals(['Phenylalanine'], $translator->getProteins('UUU'));
4743
}
4844

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

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

6765
/**
@@ -70,7 +68,8 @@ public function testLeucineRnaSequenceOne(): void
7068
#[TestDox('Leucine RNA sequence 2')]
7169
public function testLeucineRnaSequenceTwo(): void
7270
{
73-
$this->assertEquals(['Leucine'], $this->translator->getProteins('UUG'));
71+
$translator = new ProteinTranslation();
72+
$this->assertEquals(['Leucine'], $translator->getProteins('UUG'));
7473
}
7574

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

8585
/**
@@ -88,7 +88,8 @@ public function testSerineRnaSequenceOne(): void
8888
#[TestDox('Serine RNA sequence 2')]
8989
public function testSerineRnaSequenceTwo(): void
9090
{
91-
$this->assertEquals(['Serine'], $this->translator->getProteins('UCC'));
91+
$translator = new ProteinTranslation();
92+
$this->assertEquals(['Serine'], $translator->getProteins('UCC'));
9293
}
9394

9495
/**
@@ -97,7 +98,8 @@ public function testSerineRnaSequenceTwo(): void
9798
#[TestDox('Serine RNA sequence 3')]
9899
public function testSerineRnaSequenceThree(): void
99100
{
100-
$this->assertEquals(['Serine'], $this->translator->getProteins('UCA'));
101+
$translator = new ProteinTranslation();
102+
$this->assertEquals(['Serine'], $translator->getProteins('UCA'));
101103
}
102104

103105
/**
@@ -106,7 +108,8 @@ public function testSerineRnaSequenceThree(): void
106108
#[TestDox('Serine RNA sequence 4')]
107109
public function testSerineRnaSequenceFour(): void
108110
{
109-
$this->assertEquals(['Serine'], $this->translator->getProteins('UCG'));
111+
$translator = new ProteinTranslation();
112+
$this->assertEquals(['Serine'], $translator->getProteins('UCG'));
110113
}
111114

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

121125
/**
@@ -124,7 +128,8 @@ public function testTyrosineRnaSequenceOne(): void
124128
#[TestDox('Tyrosine RNA sequence 2')]
125129
public function testTyrosineRnaSequenceTwo(): void
126130
{
127-
$this->assertEquals(['Tyrosine'], $this->translator->getProteins('UAC'));
131+
$translator = new ProteinTranslation();
132+
$this->assertEquals(['Tyrosine'], $translator->getProteins('UAC'));
128133
}
129134

130135
/**
@@ -133,7 +138,8 @@ public function testTyrosineRnaSequenceTwo(): void
133138
#[TestDox('Cysteine RNA sequence 1')]
134139
public function testCysteineRnaSequenceOne(): void
135140
{
136-
$this->assertEquals(['Cysteine'], $this->translator->getProteins('UGU'));
141+
$translator = new ProteinTranslation();
142+
$this->assertEquals(['Cysteine'], $translator->getProteins('UGU'));
137143
}
138144

139145
/**
@@ -142,7 +148,8 @@ public function testCysteineRnaSequenceOne(): void
142148
#[TestDox('Cysteine RNA sequence 2')]
143149
public function testCysteineRnaSequenceTwo(): void
144150
{
145-
$this->assertEquals(['Cysteine'], $this->translator->getProteins('UGC'));
151+
$translator = new ProteinTranslation();
152+
$this->assertEquals(['Cysteine'], $translator->getProteins('UGC'));
146153
}
147154

148155
/**
@@ -151,7 +158,8 @@ public function testCysteineRnaSequenceTwo(): void
151158
#[TestDox('Tryptophan RNA sequence')]
152159
public function testTryptophanRnaSequence(): void
153160
{
154-
$this->assertEquals(['Tryptophan'], $this->translator->getProteins('UGG'));
161+
$translator = new ProteinTranslation();
162+
$this->assertEquals(['Tryptophan'], $translator->getProteins('UGG'));
155163
}
156164

157165
/**
@@ -160,7 +168,8 @@ public function testTryptophanRnaSequence(): void
160168
#[TestDox('STOP codon RNA sequence 1')]
161169
public function testStopCodonRnaSequenceOne(): void
162170
{
163-
$this->assertEquals([], $this->translator->getProteins('UAA'));
171+
$translator = new ProteinTranslation();
172+
$this->assertEquals([], $translator->getProteins('UAA'));
164173
}
165174

166175
/**
@@ -169,7 +178,8 @@ public function testStopCodonRnaSequenceOne(): void
169178
#[TestDox('STOP codon RNA sequence 2')]
170179
public function testStopCodonRnaSequenceTwo(): void
171180
{
172-
$this->assertEquals([], $this->translator->getProteins('UAG'));
181+
$translator = new ProteinTranslation();
182+
$this->assertEquals([], $translator->getProteins('UAG'));
173183
}
174184

175185
/**
@@ -178,7 +188,8 @@ public function testStopCodonRnaSequenceTwo(): void
178188
#[TestDox('STOP codon RNA sequence 3')]
179189
public function testStopCodonRnaSequenceThree(): void
180190
{
181-
$this->assertEquals([], $this->translator->getProteins('UGA'));
191+
$translator = new ProteinTranslation();
192+
$this->assertEquals([], $translator->getProteins('UGA'));
182193
}
183194

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

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

202215
/**
@@ -205,9 +218,10 @@ public function testToDifferentCodonsTranslateToProteins(): void
205218
#[TestDox('Translate RNA strand into correct protein list')]
206219
public function testTranslateRnaStrandIntoCorrectProteinList(): void
207220
{
221+
$translator = new ProteinTranslation();
208222
$this->assertEquals(
209223
['Methionine', 'Phenylalanine', 'Tryptophan'],
210-
$this->translator->getProteins('AUGUUUUGG')
224+
$translator->getProteins('AUGUUUUGG')
211225
);
212226
}
213227

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

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

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

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

250268
/**
@@ -253,9 +271,10 @@ public function testTranslationStopsIfStopCodonInMiddleOfThreeCodonSequence(): v
253271
#[TestDox('Translation stops if STOP codon in middle of six-codon sequence')]
254272
public function testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence(): void
255273
{
274+
$translator = new ProteinTranslation();
256275
$this->assertEquals(
257276
['Tryptophan', 'Cysteine', 'Tyrosine'],
258-
$this->translator->getProteins('UGGUGUUAUUAAUGGUUU')
277+
$translator->getProteins('UGGUGUUAUUAAUGGUUU')
259278
);
260279
}
261280

@@ -265,9 +284,10 @@ public function testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence(): voi
265284
#[TestDox('Sequence of two non-STOP codons does not translate to a STOP codon')]
266285
public function testSequenceOfTwoNonStopCodonsDoesNotTranslateToAStopCodon(): void
267286
{
287+
$translator = new ProteinTranslation();
268288
$this->assertEquals(
269289
['Methionine', 'Methionine'],
270-
$this->translator->getProteins('AUGAUG')
290+
$translator->getProteins('AUGAUG')
271291
);
272292
}
273293

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

285306

@@ -289,9 +310,10 @@ public function testUnknownAminoAcidsCantTranslate(): void
289310
#[TestDox("Incomplete RNA sequence can't translate")]
290311
public function testIncompleteRnaSequenceCantTranslate(): void
291312
{
313+
$translator = new ProteinTranslation();
292314
$this->expectException(InvalidArgumentException::class);
293315
$this->expectExceptionMessage('Invalid codon');
294-
$this->translator->getProteins('AUGU');
316+
$translator->getProteins('AUGU');
295317
}
296318

297319
/**
@@ -300,6 +322,7 @@ public function testIncompleteRnaSequenceCantTranslate(): void
300322
#[TestDox('Incomplete RNA sequence can translate if valid until a STOP codon')]
301323
public function testIncompleteRnaSequenceCanTranslateIfValidUntilStop(): void
302324
{
303-
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $this->translator->getProteins('UUCUUCUAAUGGU'));
325+
$translator = new ProteinTranslation();
326+
$this->assertEquals(['Phenylalanine', 'Phenylalanine'], $translator->getProteins('UUCUUCUAAUGGU'));
304327
}
305328
}

exercises/practice/proverb/.meta/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"MichaelBunker"
44
],
55
"contributors": [
6-
"luciagiampieri"
6+
"luciagiampieri",
7+
"resu-xuniL"
78
],
89
"files": {
910
"solution": [

0 commit comments

Comments
 (0)