hamming spec

This commit is contained in:
Ben Harris 2018-03-13 12:54:07 -04:00
parent 983639f8ce
commit b09bebcd84
8 changed files with 157 additions and 8 deletions

View File

@ -0,0 +1,34 @@
# Gigasecond
Calculate the moment when someone has lived for 10^9 seconds.
A gigasecond is 10^9 (1,000,000,000) seconds.
## Setup
Follow the setup instructions for Crystal here:
http://exercism.io/languages/crystal
More help installing can be found here:
http://crystal-lang.org/docs/installation/index.html
## Making the Test Suit Pass
Execute the tests with:
```bash
$ crystal spec
```
In each test suite all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by changing `pending` to `it`.
## Source
Chapter 9 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=09](http://pine.fm/LearnToProgram/?Chapter=09)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@ -0,0 +1,34 @@
require "spec"
require "../src/*"
describe "Gigasecond" do
describe "#from" do
it "finds gigsecond from 2011_04_25" do
result = Gigasecond.from(Time.new(2011, 4, 25, 0, 0, 0))
result.should eq Time.new(2043, 1, 1, 1, 46, 40)
end
it "finds gigsecond from 1977_06_13" do
result = Gigasecond.from(Time.new(1977, 6, 13, 0, 0, 0))
result.should eq Time.new(2009, 2, 19, 1, 46, 40)
end
it "finds gigsecond from 1959_07_19" do
result = Gigasecond.from(Time.new(1959, 7, 19, 0, 0, 0))
result.should eq Time.new(1991, 3, 27, 1, 46, 40)
end
it "finds gigsecond with full_time specified" do
result = Gigasecond.from(Time.new(2015, 1, 24, 22, 0, 0))
result.should eq Time.new(2046, 10, 2, 23, 46, 40)
end
it "finds gigsecond with full_time with day rollover" do
result = Gigasecond.from(Time.new(2015, 1, 24, 23, 59, 59))
result.should eq Time.new(2046, 10, 3, 1, 46, 39)
end
it "test_with_your_birthday" do
end
end
end

View File

@ -0,0 +1,6 @@
module Gigasecond
def self.from(time)
time + Time::Span.new(0, 0, 1000000000)
end
end

View File

@ -7,23 +7,23 @@ describe "Hamming" do
Hamming.compute("A", "A").should eq 0
end
pending "computes a distance for single nucleotide strands" do
it "computes a distance for single nucleotide strands" do
Hamming.compute("A", "G").should eq 1
end
pending "computes a distance for small strands" do
it "computes a distance for small strands" do
Hamming.compute("AG", "CT").should eq 2
end
pending "computes a distance for medium strands" do
it "computes a distance for medium strands" do
Hamming.compute("GGACG", "GGTCG").should eq 1
end
pending "computes a distance for large strands" do
it "computes a distance for large strands" do
Hamming.compute("GGACGGATTCTG", "AGGACGGATTCT").should eq 9
end
pending "raises an exception when strands aren't of equal length" do
it "raises an exception when strands aren't of equal length" do
expect_raises(ArgumentError) { Hamming.compute("GCC", "A") }
end
end

View File

@ -1,7 +1,7 @@
module Hamming
class Hamming
def self.compute(a, b)
raise ArgumentError unless a.size == b.size
(0..a.size).count {|i| a[i] != b[i]}
raise ArgumentError.new unless a.size == b.size
(0...a.size).count {|i| a[i] != b[i]}
end
end

View File

@ -0,0 +1,48 @@
# RNA Transcription
Given a DNA strand, return its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and thymine (**T**).
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and uracil (**U**).
Given a DNA strand, its transcribed RNA strand is formed by replacing
each nucleotide with its complement:
* `G` -> `C`
* `C` -> `G`
* `T` -> `A`
* `A` -> `U`
## Setup
Follow the setup instructions for Crystal here:
http://exercism.io/languages/crystal
More help installing can be found here:
http://crystal-lang.org/docs/installation/index.html
## Making the Test Suit Pass
Execute the tests with:
```bash
$ crystal spec
```
In each test suite all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by changing `pending` to `it`.
## Source
Hyperphysics [http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html](http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@ -0,0 +1,26 @@
require "spec"
require "../src/*"
describe "RnaComplement" do
describe "#of_dna" do
it "correctly transcribes cytosine to guanine" do
RnaComplement.of_dna("C").should eq "G"
end
pending "correctly transcribes guanine to cytocine" do
RnaComplement.of_dna("G").should eq "C"
end
pending "correctly transcribes thymine to adenine" do
RnaComplement.of_dna("T").should eq "A"
end
pending "correctly transcribes adenine to uracil" do
RnaComplement.of_dna("A").should eq "U"
end
pending "correctly transcribes all dna nucleotides to their rna compliment" do
RnaComplement.of_dna("ACGTGGTCTTAA").should eq "UGCACCAGAAUU"
end
end
end

View File

@ -0,0 +1 @@
# Please implement your solution to rna-transcription in this file