Skip to content

rna-transcription 1.0.0: reject invalid inputs#292

Merged
petertseng merged 2 commits intoexercism:masterfrom
petertseng:rna
May 30, 2017
Merged

rna-transcription 1.0.0: reject invalid inputs#292
petertseng merged 2 commits intoexercism:masterfrom
petertseng:rna

Conversation

@petertseng
Copy link
Copy Markdown
Member

The invalid input cases originally came from
exercism/problem-specifications#119

Today's JSON file can be found at
https://github.com/exercism/x-common/blob/master/exercises/rna-transcription/canonical-data.json

This track was already using all the valid inputs and simply needed to
add these invalid inputs.

The invalid input cases originally came from
exercism/problem-specifications#119

Today's JSON file can be found at
https://github.com/exercism/x-common/blob/master/exercises/rna-transcription/canonical-data.json

This track was already using all the valid inputs and simply needed to
add these invalid inputs.
#[ignore]
fn test_transcribes_cytosine_guanine() {
assert_eq!(dna::RibonucleicAcid::new("G"), dna::DeoxyribonucleicAcid::new("C").to_rna());
assert_eq!(Ok(dna::RibonucleicAcid::new("G")), dna::DeoxyribonucleicAcid::new("C").to_rna());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is a different approach from, say, #238 which used unwrap. Note that https://github.com/exercism/xrust/blob/master/exercises/nucleotide-codons/tests/codons.rs does use assert_eq with Ok though. I think I like this better. The difference is what happens when I return an Err when I should return Ok. With assert_eq!(Ok(...), ...):

---- test_transcribes_cytosine_guanine stdout ----
	thread 'test_transcribes_cytosine_guanine' panicked at 'assertion failed: `(left == right)` (left: `Ok(RibonucleicAcid { nucleotides: "G" })`, right: `Err(())`)', tests/rna-transcription.rs:12

With assert_eq!(..., ....unwrap());

---- test_transcribes_cytosine_guanine stdout ----
	thread 'test_transcribes_cytosine_guanine' panicked at 'called `Result::unwrap()` on an `Err` value: ()', src/libcore/result.rs:859

So why don't I go ahead and say now that I like assert_eq(Ok(...), ...) better since it shows me both sides.

Copy link
Copy Markdown
Contributor

@ijanos ijanos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using unwrap in an assert is an antipattern and we should avoid it.

@petertseng petertseng merged commit 3a8140d into exercism:master May 30, 2017
@petertseng petertseng deleted the rna branch May 30, 2017 12:25
@petertseng petertseng added the sync/tests Keep a test suite/version in sync with exercism/problem-specifications label Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sync/tests Keep a test suite/version in sync with exercism/problem-specifications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants