nucleotide-count.t (1810B) - raw
1 #!/usr/bin/env perl 2 use Test2::V0; 3 use JSON::PP; 4 use constant JSON => JSON::PP->new; 5 6 use FindBin qw<$Bin>; 7 use lib $Bin, "$Bin/local/lib/perl5"; 8 9 use NucleotideCount qw<count_nucleotides>; 10 11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; 12 plan 6; 13 14 imported_ok qw<count_nucleotides> or bail_out; 15 16 for my $case (@test_cases) { 17 if ( $case->{expected}{error} ) { 18 like dies( sub { count_nucleotides( $case->{input}{strand} ) } ), 19 qr/$case->{expected}{error}/, $case->{description}; 20 } 21 else { 22 is count_nucleotides( $case->{input}{strand} ), 23 $case->{expected}, $case->{description}; 24 } 25 } 26 27 __DATA__ 28 [ 29 { 30 "description": "empty strand", 31 "expected": { 32 "A": 0, 33 "C": 0, 34 "G": 0, 35 "T": 0 36 }, 37 "input": { 38 "strand": "" 39 }, 40 "property": "nucleotideCounts" 41 }, 42 { 43 "description": "can count one nucleotide in single-character input", 44 "expected": { 45 "A": 0, 46 "C": 0, 47 "G": 1, 48 "T": 0 49 }, 50 "input": { 51 "strand": "G" 52 }, 53 "property": "nucleotideCounts" 54 }, 55 { 56 "description": "strand with repeated nucleotide", 57 "expected": { 58 "A": 0, 59 "C": 0, 60 "G": 7, 61 "T": 0 62 }, 63 "input": { 64 "strand": "GGGGGGG" 65 }, 66 "property": "nucleotideCounts" 67 }, 68 { 69 "description": "strand with multiple nucleotides", 70 "expected": { 71 "A": 20, 72 "C": 12, 73 "G": 17, 74 "T": 21 75 }, 76 "input": { 77 "strand": "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" 78 }, 79 "property": "nucleotideCounts" 80 }, 81 { 82 "description": "strand with invalid nucleotides", 83 "expected": { 84 "error": "Invalid nucleotide in strand" 85 }, 86 "input": { 87 "strand": "AGXXACT" 88 }, 89 "property": "nucleotideCounts" 90 } 91 ]