exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs

commit 6f05e2607b226a9cdae9ee76e2f4a5fa8c38c40d
parent 162eb3e5be496c92c17899e418140ce7605ded4d
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Sat, 27 Nov 2021 16:16:50 +0000

add nucelotide-count

Diffstat:
Anucleotide-count/.exercism/config.json | 24++++++++++++++++++++++++
Anucleotide-count/.exercism/metadata.json | 2++
Anucleotide-count/HELP.md | 36++++++++++++++++++++++++++++++++++++
Anucleotide-count/NucleotideCount.pm | 12++++++++++++
Anucleotide-count/README.md | 43+++++++++++++++++++++++++++++++++++++++++++
Anucleotide-count/nucleotide-count.t | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 208 insertions(+), 0 deletions(-)

diff --git a/nucleotide-count/.exercism/config.json b/nucleotide-count/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", + "authors": [ + "bentglasstube" + ], + "contributors": [ + "kytrinyx", + "m-dango", + "rfilipo" + ], + "files": { + "solution": [ + "NucleotideCount.pm" + ], + "test": [ + "nucleotide-count.t" + ], + "example": [ + ".meta/solutions/NucleotideCount.pm" + ] + }, + "source": "The Calculating DNA Nucleotides_problem at Rosalind", + "source_url": "http://rosalind.info/problems/dna/" +} diff --git a/nucleotide-count/.exercism/metadata.json b/nucleotide-count/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"perl5","exercise":"nucleotide-count","id":"67af13f8f2e24fd784b7dd2f2745e12d","url":"https://exercism.org/tracks/perl5/exercises/nucleotide-count","handle":"confidentidiot","is_requester":true,"auto_approve":false} +\ No newline at end of file diff --git a/nucleotide-count/HELP.md b/nucleotide-count/HELP.md @@ -0,0 +1,35 @@ +# Help + +## Running the tests + +There is a Perl 5 script with the extension `.t`, which will be used to test +your solution. You can run through the tests by using the command: + +```bash +`prove .` +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit NucleotideCount.pm` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. +\ No newline at end of file diff --git a/nucleotide-count/NucleotideCount.pm b/nucleotide-count/NucleotideCount.pm @@ -0,0 +1,12 @@ +package NucleotideCount; +use strict; +use warnings; +use Exporter qw<import>; +our @EXPORT_OK = qw<count_nucleotides>; + +sub count_nucleotides { + my ($strand) = @_; + return undef; +} + +1; diff --git a/nucleotide-count/README.md b/nucleotide-count/README.md @@ -0,0 +1,42 @@ +# Nucleotide Count + +Welcome to Nucleotide Count on Exercism's Perl 5 Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed. All known life depends on DNA! + +> Note: You do not need to understand anything about nucleotides or DNA to complete this exercise. + +DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine. A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important! +We call the order of these nucleotides in a bit of DNA a "DNA sequence". + +We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides. +'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' for thymine. + +Given a string representing a DNA sequence, count how many of each nucleotide is present. +If the string contains characters that aren't A, C, G, or T then it is invalid and you should signal an error. + +For example: + +``` +"GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2 +"INVALID" -> error +``` + +## Source + +### Created by + +- @bentglasstube + +### Contributed to by + +- @kytrinyx +- @m-dango +- @rfilipo + +### Based on + +The Calculating DNA Nucleotides_problem at Rosalind - http://rosalind.info/problems/dna/ +\ No newline at end of file diff --git a/nucleotide-count/nucleotide-count.t b/nucleotide-count/nucleotide-count.t @@ -0,0 +1,91 @@ +#!/usr/bin/env perl +use Test2::V0; +use JSON::PP; +use constant JSON => JSON::PP->new; + +use FindBin qw<$Bin>; +use lib $Bin, "$Bin/local/lib/perl5"; + +use NucleotideCount qw<count_nucleotides>; + +my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; +plan 6; + +imported_ok qw<count_nucleotides> or bail_out; + +for my $case (@test_cases) { + if ( $case->{expected}{error} ) { + like dies( sub { count_nucleotides( $case->{input}{strand} ) } ), + qr/$case->{expected}{error}/, $case->{description}; + } + else { + is count_nucleotides( $case->{input}{strand} ), + $case->{expected}, $case->{description}; + } +} + +__DATA__ +[ + { + "description": "empty strand", + "expected": { + "A": 0, + "C": 0, + "G": 0, + "T": 0 + }, + "input": { + "strand": "" + }, + "property": "nucleotideCounts" + }, + { + "description": "can count one nucleotide in single-character input", + "expected": { + "A": 0, + "C": 0, + "G": 1, + "T": 0 + }, + "input": { + "strand": "G" + }, + "property": "nucleotideCounts" + }, + { + "description": "strand with repeated nucleotide", + "expected": { + "A": 0, + "C": 0, + "G": 7, + "T": 0 + }, + "input": { + "strand": "GGGGGGG" + }, + "property": "nucleotideCounts" + }, + { + "description": "strand with multiple nucleotides", + "expected": { + "A": 20, + "C": 12, + "G": 17, + "T": 21 + }, + "input": { + "strand": "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" + }, + "property": "nucleotideCounts" + }, + { + "description": "strand with invalid nucleotides", + "expected": { + "error": "Invalid nucleotide in strand" + }, + "input": { + "strand": "AGXXACT" + }, + "property": "nucleotideCounts" + } +]