Skip to content

Commit f254d21

Browse files
authored
rna-transcription: add test to avoid cheesing (#2151)
In the normal tests for this exercise, we compare two RNA instances. If the user defines RNA as an empty struct, those instances will always compare equal. This is prevented with the new test to make sure different RNA don't compare equal. Forum post: https://forum.exercism.org/t/successful-null-solution-for-rna-transcription/63064
1 parent e0e91f3 commit f254d21

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

exercises/practice/rna-transcription/.meta/test_template.tera

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
use rna_transcription::{Dna, Rna};
2+
3+
{#-
4+
We usually do not add additional tests directly in the template.
5+
In this case however, the structure of the tests is different from the
6+
regular ones. Accommodating that in the template would be complicated
7+
and unnecessary. We also want to test this early, so that users don't
8+
make it through basically all tests without doing anything.
9+
#}
10+
11+
#[test]
12+
#[ignore]
13+
fn different_rna_are_different() {
14+
let a = Rna::new("G").unwrap();
15+
let b = Rna::new("UGCACCAGAAUU").unwrap();
16+
assert_ne!(a, b);
17+
}
18+
219
{% for test in cases %}
320
#[test]
421
#[ignore]

exercises/practice/rna-transcription/tests/rna_transcription.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
use rna_transcription::{Dna, Rna};
22

33
#[test]
4+
fn different_rna_are_different() {
5+
let a = Rna::new("G").unwrap();
6+
let b = Rna::new("UGCACCAGAAUU").unwrap();
7+
assert_ne!(a, b);
8+
}
9+
10+
#[test]
11+
#[ignore]
412
fn empty_rna_sequence() {
513
let input = "";
614
let output = Dna::new(input).unwrap().into_rna();

0 commit comments

Comments
 (0)