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 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: 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"
}
29 changes: 14 additions & 15 deletions exercises/practice/rna-transcription/example/RnaTranscription.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ import Data.Vect

%default total

namespace DnaStrand
namespace DnaNucleotide
public export
data DnaStrand = A | C | T | G
data DnaNucleotide = 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 RnaNucleotide
public export
data RnaStrand = A | C | G | U
data RnaNucleotide = A | C | G | U

export
implementation Eq RnaStrand where
implementation Eq RnaNucleotide where
(==) A A = True
(==) C C = True
(==) G G = True
(==) U U = True
(==) _ _ = False


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

export
toRna : Vect n DnaStrand -> Vect n RnaStrand
toRna : Vect n DnaNucleotide -> Vect n RnaNucleotide
toRna [] = []
toRna (A :: xs) = U :: toRna xs
toRna (C :: xs) = G :: toRna xs
Expand Down
18 changes: 11 additions & 7 deletions exercises/practice/rna-transcription/src/RnaTranscription.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import Data.Vect

%default total

namespace DnaStrand
namespace DnaNucleotide
public export
data DnaStrand = Foo
data DnaNucleotide = Foo

namespace RnaStrand
namespace RnaNucleotide
public export
data RnaStrand = Bar
data RnaNucleotide = Bar

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

export
toRna : Vect n DnaStrand -> Vect n RnaStrand
implementation Show RnaNucleotide where
show x = ?RnaNucleotideShowRhs

export
toRna : Vect n DnaNucleotide -> Vect n RnaNucleotide
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 RnaNucleotide) []))
, 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 RnaNucleotide) [])"
dna = to_vect(case["input"]["dna"])

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