Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync and re-implement rna-transcription #169

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 1 deletion exercises/practice/rna-transcription/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"liarokapisv"
],
"contributors": [
"keiravillekode",
"ktosiek",
"NobbZ",
"yurrriq"
Expand All @@ -20,5 +21,5 @@
},
"blurb": "Given a DNA strand, return its RNA Complement Transcription.",
"source": "Hyperphysics",
"source_url": "http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
"source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
}
19 changes: 9 additions & 10 deletions exercises/practice/rna-transcription/example/RnaTranscription.idr
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ namespace DnaStrand
public export
data DnaStrand = A | C | T | G

export
implementation Eq DnaStrand where
(==) A A = True
(==) C C = True
(==) T T = True
(==) G G = True
(==) _ _ = False

namespace RnaStrand
namespace RnaStrand
public export
data RnaStrand = A | C | G | U

Expand All @@ -27,7 +19,14 @@ implementation Eq RnaStrand where
(==) G G = True
(==) U U = True
(==) _ _ = False


export
implementation Show RnaStrand where
show A = "A"
show C = "C"
show G = "G"
show U = "U"

export
toRna : Vect n DnaStrand -> Vect n RnaStrand
toRna [] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ namespace DnaStrand
public export
data DnaStrand = Foo

namespace RnaStrand
namespace RnaStrand
public export
data RnaStrand = Bar

export
implementation Eq RnaStrand where
(==) x y = ?RnaStrandEqRhs

export
implementation Show RnaStrand where
show x = ?RnaStrandShowRhs

export
toRna : Vect n DnaStrand -> Vect n RnaStrand
toRna = ?toRna_rhs
41 changes: 19 additions & 22 deletions exercises/practice/rna-transcription/test/src/Main.idr
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
module Main

import Data.Vect
import RnaTranscription
import System
import Tester
import Tester.Runner

assertCase : Eq b => (a -> b) -> (String, a, b) -> IO ()
assertCase fn (desc,given,expected) = do
putStrLn desc
if fn given == expected
then putStrLn " Test Passed"
else do
putStrLn " Test Failed"
exitFailure

import RnaTranscription
import Data.Vect

testCases : List (n : Nat ** (String, Vect n DnaStrand, Vect n RnaStrand))
testCases = [(_ ** ("Empty RNA sequence", [], [])),
(_ ** ("RNA complement of cytosine is guanine", [C], [G])),
(_ ** ("RNA complement of guanine is cytosine", [G], [C])),
(_ ** ("RNA complement of thymine is adenine", [T], [A])),
(_ ** ("RNA complement of adenine is uracil", [A], [U])),
(_ ** ("RNA complement", [A,C,G,T,G,G,T,C,T,T,A,A], [U,G,C,A,C,C,A,G,A,A,U,U]))]
tests : List Test
tests =
[ test "Empty RNA sequence" (assertEq (toRna []) (the (Vect 0 RnaStrand) []))
, test "RNA complement of cytosine is guanine" (assertEq (toRna [C]) [G])
, test "RNA complement of guanine is cytosine" (assertEq (toRna [G]) [C])
, test "RNA complement of thymine is adenine" (assertEq (toRna [T]) [A])
, test "RNA complement of adenine is uracil" (assertEq (toRna [A]) [U])
, test "RNA complement" (assertEq (toRna [A, C, G, T, G, G, T, C, T, T, A, A]) [U, G, C, A, C, C, A, G, A, A, U, U])
]

export
main : IO ()
main = traverse_ testCase' testCases
where testCase' : (n : Nat ** (String, Vect n DnaStrand, Vect n RnaStrand)) -> IO ()
testCase' (x ** pf) = assertCase toRna pf

main = do
success <- runTests tests
if success
then putStrLn "All tests passed"
else exitFailure
1 change: 1 addition & 0 deletions exercises/practice/rna-transcription/test/test.ipkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rna-transcription-test
depends = rna-transcription
, tester
main = Main
executable = "rna-transcription-test"
sourcedir = "src"
15 changes: 15 additions & 0 deletions generators/exercises/rna_transcription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

def header():
return "import Data.Vect\n"

def generate_test(case):
def to_vect(proteins):
return str(list(proteins)).replace("'", "")

property = case["property"]
expected = to_vect(case["expected"])
if expected == "[]":
expected = "(the (Vect 0 RnaStrand) [])"
Copy link
Contributor Author

@keiravillekode keiravillekode Jul 26, 2024

Choose a reason for hiding this comment

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

Without this, a student can change

toRna : Vect n DnaStrand -> Vect n RnaStrand

to

toRna : List DnaStrand -> List RnaStrand

and provide a solution using lists.

It isn't a major problem - when a student cheats, they are only cheating themselves - but we eliminate this kind of cheating by expecting a Vect

There are still other ways of cheating like defining Eq RnaStrand to always return True

dna = to_vect(case["input"]["dna"])

return f'assertEq ({property} {dna}) {expected}'