summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Edi <jedi@manas.com.ar>2016-10-18 19:08:40 (GMT)
committerJuan Edi <jedi@Juans-MacBook-Pro.local>2016-10-18 19:08:40 (GMT)
commit0f7a9a931dc0ce3374ad3a5f4ca20cfa92fa96b6 (patch)
tree55afc39515a291b15bc665e1aaac467065be7b86
parenta8e414b61b66c65b8a947b3bd99fd01e2e7f3baa (diff)
downloadcrystal-0f7a9a931dc0ce3374ad3a5f4ca20cfa92fa96b6.zip
crystal-0f7a9a931dc0ce3374ad3a5f4ca20cfa92fa96b6.tar.gz
crystal-0f7a9a931dc0ce3374ad3a5f4ca20cfa92fa96b6.tar.bz2
Excercism exercises specs
-rw-r--r--.gitignore1
-rw-r--r--exercism/anagram/anagram_spec.cr46
-rw-r--r--exercism/atbash-cipher/atbash_cipher_spec.cr40
-rw-r--r--exercism/bob/bob_spec.cr66
-rw-r--r--exercism/bracket-push/bracket_push_spec.cr46
-rw-r--r--exercism/gigasecond/gigasecond_spec.cr34
-rw-r--r--exercism/hamming/hamming_spec.cr30
-rw-r--r--exercism/hello-world/GETTING_STARTED.md10
-rw-r--r--exercism/hello-world/hello_world_spec.cr18
-rw-r--r--exercism/largest-series-product/largest_series_product_spec.cr58
-rw-r--r--exercism/leap/leap_spec.cr36
-rw-r--r--exercism/pangram/pangram_spec.cr51
-rw-r--r--exercism/raindrops/raindrops_spec.cr34
-rw-r--r--exercism/react/react_spec.cr124
-rw-r--r--exercism/rna-transcription/rna_transcription_spec.cr26
-rw-r--r--exercism/roman-numerals/roman_numerals_spec.cr61
-rw-r--r--exercism/sieve/sieve_spec.cr22
17 files changed, 703 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7fd46fa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+example.cr
diff --git a/exercism/anagram/anagram_spec.cr b/exercism/anagram/anagram_spec.cr
new file mode 100644
index 0000000..87d6bf0
--- /dev/null
+++ b/exercism/anagram/anagram_spec.cr
@@ -0,0 +1,46 @@
+require "spec"
+require "./anagram"
+
+describe "Anagram" do
+ describe "#find" do
+ it "detects no anagrams" do
+ Anagram.find("diaper", ["hello", "world", "zombies", "pants"]).should eq [] of String
+ end
+
+ pending "detects one anagram" do
+ Anagram.find("ant", ["tan", "stand", "at"]).should eq ["tan"]
+ end
+
+ pending "detects multiple anagrams" do
+ Anagram.find("master", ["stream", "pigeon", "maters"]).should eq ["stream", "maters"]
+ end
+
+ pending "detects multiple anagrams 2" do
+ Anagram.find("allergy", ["gallery", "ballerina", "regally", "clergy", "largely", "leading"]).should eq ["gallery", "regally", "largely"]
+ end
+
+ pending "does not detect false positives" do
+ Anagram.find("galea", ["eagle"]).should eq [] of String
+ end
+
+ pending "does not detect anagram subsets" do
+ Anagram.find("good", ["dog", "goody"]).should eq [] of String
+ end
+
+ pending "does not detect identical words" do
+ Anagram.find("corn", ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"]).should eq ["cron"]
+ end
+
+ pending "detects anagrams case-insensitively" do
+ Anagram.find("Orchestra", ["cashregister", "carthorse", "radishes"]).should eq ["carthorse"]
+ end
+
+ pending "does not detect a word as its own anagram" do
+ Anagram.find("banana", ["Banana"]).should eq [] of String
+ end
+
+ pending "anagrams must use all letters exactly once" do
+ Anagram.find("tapper", ["patter"]).should eq [] of String
+ end
+ end
+end
diff --git a/exercism/atbash-cipher/atbash_cipher_spec.cr b/exercism/atbash-cipher/atbash_cipher_spec.cr
new file mode 100644
index 0000000..5019098
--- /dev/null
+++ b/exercism/atbash-cipher/atbash_cipher_spec.cr
@@ -0,0 +1,40 @@
+require "spec"
+require "./atbash_cipher"
+
+describe "Atbash" do
+ describe "#encode" do
+ it "encodes no" do
+ Atbash.encode("no").should eq "ml"
+ end
+
+ pending "encodes yes" do
+ Atbash.encode("yes").should eq "bvh"
+ end
+
+ pending "encode OMG" do
+ Atbash.encode("OMG").should eq "lnt"
+ end
+
+ pending "encodes O M G spaces" do
+ Atbash.encode("O M G").should eq "lnt"
+ end
+
+ pending "encode long words" do
+ Atbash.encode("mindblowingly").should eq "nrmwy oldrm tob"
+ end
+
+ pending "encodes numbers" do
+ Atbash.encode("Testing, 1 2 3, testing.").should eq "gvhgr mt123 gvhgr mt"
+ end
+
+ pending "encodes sentence" do
+ Atbash.encode("Truth is fiction.").should eq "gifgs rhurx grlm"
+ end
+
+ pending "encodes all the things" do
+ plaintext = "The quick brown fox jumps over the lazy dog."
+ cipher = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
+ Atbash.encode(plaintext).should eq cipher
+ end
+ end
+end
diff --git a/exercism/bob/bob_spec.cr b/exercism/bob/bob_spec.cr
new file mode 100644
index 0000000..8aeeca0
--- /dev/null
+++ b/exercism/bob/bob_spec.cr
@@ -0,0 +1,66 @@
+require "spec"
+require "./bob"
+
+describe "Bob" do
+ describe "#hey" do
+ it "responds to stating something" do
+ Bob.hey("Tom-ay-to, tom-aaaah-to.").should eq "Whatever."
+ end
+
+ pending "responds to shouting something" do
+ Bob.hey("WATCH OUT!").should eq "Whoa, chill out!"
+ end
+
+ pending "responds to asking a question" do
+ Bob.hey("Does this cryogenic chamber make me look fat?").should eq "Sure."
+ end
+
+ pending "responds to talking forcefully" do
+ Bob.hey("Let\'s go make out behind the gym!").should eq "Whatever."
+ end
+
+ pending "responds to using acronyms in regular speech" do
+ Bob.hey("It\'s OK if you don\'t want to go to the DMV.").should eq "Whatever."
+ end
+
+ pending "responds to forceful questions" do
+ Bob.hey("WHAT THE HELL WERE YOU THINKING?").should eq "Whoa, chill out!"
+ end
+
+ pending "responds to shouting numbers" do
+ Bob.hey("1, 2, 3 GO!").should eq "Whoa, chill out!"
+ end
+
+ pending "responds to only numbers" do
+ Bob.hey("1, 2, 3").should eq "Whatever."
+ end
+
+ pending "responds to question with only numbers" do
+ Bob.hey("4?").should eq "Sure."
+ end
+
+ pending "responds to shouting with special characters" do
+ Bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!").should eq "Whoa, chill out!"
+ end
+
+ pending "responds to shouting with no exclamation mark" do
+ Bob.hey("I HATE YOU").should eq "Whoa, chill out!"
+ end
+
+ pending "responds to statement containing question mark" do
+ Bob.hey("Ending with a ? means a question.").should eq "Whatever."
+ end
+
+ pending "responds to prattling on" do
+ Bob.hey("Wait! Hang on. Are you going to be OK?").should eq "Sure."
+ end
+
+ pending "responds to silence" do
+ Bob.hey("").should eq "Fine. Be that way!"
+ end
+
+ pending "responds to prolonged silence" do
+ Bob.hey(" ").should eq "Fine. Be that way!"
+ end
+ end
+end
diff --git a/exercism/bracket-push/bracket_push_spec.cr b/exercism/bracket-push/bracket_push_spec.cr
new file mode 100644
index 0000000..55484a2
--- /dev/null
+++ b/exercism/bracket-push/bracket_push_spec.cr
@@ -0,0 +1,46 @@
+require "spec"
+require "./bracket_push"
+
+describe "Brackets" do
+ describe "#are_valid?" do
+ it "paired square brackets" do
+ Brackets.are_valid?("[]").should be_true
+ end
+ it "empty string" do
+ Brackets.are_valid?("").should be_true
+ end
+ it "unpaired brackets" do
+ Brackets.are_valid?("[[").should be_false
+ end
+ it "wrong ordered brackets" do
+ Brackets.are_valid?("}{").should be_false
+ end
+ it "paired with whitespace" do
+ Brackets.are_valid?("{ }").should be_true
+ end
+ it "simple nested brackets" do
+ Brackets.are_valid?("{[]}").should be_true
+ end
+ it "several paired brackets" do
+ Brackets.are_valid?("{}[]").should be_true
+ end
+ it "paired and nested brackets" do
+ Brackets.are_valid?("([{}({}[])])").should be_true
+ end
+ it "unopened closing brackets" do
+ Brackets.are_valid?("{[)][]}").should be_false
+ end
+ it "unpaired and nested brackets" do
+ Brackets.are_valid?("([{])").should be_false
+ end
+ it "paired and wrong nested brackets" do
+ Brackets.are_valid?("[({]})").should be_false
+ end
+ it "math expression" do
+ Brackets.are_valid?("(((185 + 223.85) * 15) - 543)/2").should be_true
+ end
+ it "complex latex expression" do
+ Brackets.are_valid?("\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)").should be_true
+ end
+ end
+end
diff --git a/exercism/gigasecond/gigasecond_spec.cr b/exercism/gigasecond/gigasecond_spec.cr
new file mode 100644
index 0000000..f6298a2
--- /dev/null
+++ b/exercism/gigasecond/gigasecond_spec.cr
@@ -0,0 +1,34 @@
+require "spec"
+require "./gigasecond"
+
+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
+
+ pending "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
+
+ pending "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
+
+ pending "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
+
+ pending "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
+
+ pending "test_with_your_birthday" do
+ end
+ end
+end
diff --git a/exercism/hamming/hamming_spec.cr b/exercism/hamming/hamming_spec.cr
new file mode 100644
index 0000000..bc86f6e
--- /dev/null
+++ b/exercism/hamming/hamming_spec.cr
@@ -0,0 +1,30 @@
+require "spec"
+require "./hamming"
+
+describe "Hamming" do
+ describe "#compute" do
+ it "computes no difference for identical single nucleotide strands" do
+ Hamming.compute("A", "A").should eq 0
+ end
+
+ pending "computes a distance for single nucleotide strands" do
+ Hamming.compute("A", "G").should eq 1
+ end
+
+ pending "computes a distance for small strands" do
+ Hamming.compute("AG", "CT").should eq 2
+ end
+
+ pending "computes a distance for medium strands" do
+ Hamming.compute("GGACG", "GGTCG").should eq 1
+ end
+
+ pending "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
+ expect_raises(ArgumentError) { Hamming.compute("GCC", "A") }
+ end
+ end
+end
diff --git a/exercism/hello-world/GETTING_STARTED.md b/exercism/hello-world/GETTING_STARTED.md
new file mode 100644
index 0000000..6914987
--- /dev/null
+++ b/exercism/hello-world/GETTING_STARTED.md
@@ -0,0 +1,10 @@
+# Welcome to Crystal!
+
+## Installation
+
+*Note: Currently, Crystal only supports Linux and OSX.*
+
+Use one of the [installation guides](http://crystal-lang.org/docs/installation/index.html) for instructions on installing Crystal.
+
+## Running Tests
+`crystal spec hello_world_spec.cr`
diff --git a/exercism/hello-world/hello_world_spec.cr b/exercism/hello-world/hello_world_spec.cr
new file mode 100644
index 0000000..fa89d00
--- /dev/null
+++ b/exercism/hello-world/hello_world_spec.cr
@@ -0,0 +1,18 @@
+require "spec"
+require "./hello_world"
+
+describe "HelloWorld" do
+ describe "#hello" do
+ it "says hello with default 'World'" do
+ HelloWorld.hello.should eq "Hello, World"
+ end
+
+ pending "says hello with one name" do
+ HelloWorld.hello("Max").should eq "Hello, Max"
+ end
+
+ pending "says hello with another name" do
+ HelloWorld.hello("Alice").should eq "Hello, Alice"
+ end
+ end
+end
diff --git a/exercism/largest-series-product/largest_series_product_spec.cr b/exercism/largest-series-product/largest_series_product_spec.cr
new file mode 100644
index 0000000..59b73c2
--- /dev/null
+++ b/exercism/largest-series-product/largest_series_product_spec.cr
@@ -0,0 +1,58 @@
+require "spec"
+require "./largest_series_product"
+
+describe "Series" do
+ describe "#largest_product" do
+ it "can find the largest product of 2 with numbers in order" do
+ Series.new("0123456789").largest_product(2).should eq 72
+ end
+ it "can find the largest product of 2" do
+ Series.new("576802143").largest_product(2).should eq 48
+ end
+ it "finds the largest product if span equals length" do
+ Series.new("29").largest_product(2).should eq 18
+ end
+ it "can find the largest product of 3 with numbers in order" do
+ Series.new("0123456789").largest_product(3).should eq 504
+ end
+ it "can find the largest product of 3" do
+ Series.new("1027839564").largest_product(3).should eq 270
+ end
+ it "can find the largest product of 5 with numbers in order" do
+ Series.new("0123456789").largest_product(5).should eq 15120
+ end
+ it "can get the largest product of a big number" do
+ Series.new("73167176531330624919225119674426574742355349194934").largest_product(6).should eq 23520
+ end
+ it "can get the largest product of a big number II" do
+ Series.new("52677741234314237566414902593461595376319419139427").largest_product(6).should eq 28350
+ end
+ it "can get the largest product of a big number (Project Euler)" do
+ Series.new("7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450").largest_product(13).should eq 23514624000
+ end
+ it "reports zero if the only digits are zero" do
+ Series.new("0000").largest_product(2).should eq 0
+ end
+ it "reports zero if all spans include zero" do
+ Series.new("99099").largest_product(3).should eq 0
+ end
+ it "rejects span longer than string length" do
+ expect_raises(ArgumentError) { Series.new("123").largest_product(4) }
+ end
+ it "reports 1 for empty string and empty product (0 span)" do
+ Series.new("").largest_product(0).should eq 1
+ end
+ it "reports 1 for nonempty string and empty product (0 span)" do
+ Series.new("123").largest_product(0).should eq 1
+ end
+ it "rejects empty string and nonzero span" do
+ expect_raises(ArgumentError) { Series.new("").largest_product(1) }
+ end
+ it "rejects invalid character in digits" do
+ expect_raises(ArgumentError) { Series.new("1234a5").largest_product(2).should eq -1 }
+ end
+ it "rejects negative span" do
+ expect_raises(ArgumentError) { Series.new("12345").largest_product(-1) }
+ end
+ end
+end
diff --git a/exercism/leap/leap_spec.cr b/exercism/leap/leap_spec.cr
new file mode 100644
index 0000000..eee7082
--- /dev/null
+++ b/exercism/leap/leap_spec.cr
@@ -0,0 +1,36 @@
+require "spec"
+require "./leap"
+
+struct Time
+ def leap_year?
+ raise "That's too easy! Implement this method in your own way!"
+ end
+end
+
+describe "Leap" do
+ describe "#leap?" do
+ it "marks 1996 as a leap year" do
+ Year.leap?(1996).should be_true
+ end
+
+ pending "marks 1997 not as a leap year" do
+ Year.leap?(1997).should be_false
+ end
+
+ pending "marks 1998 not as a leap year" do
+ Year.leap?(1998).should be_false
+ end
+
+ pending "marks 1900 not as a leap year" do
+ Year.leap?(1900).should be_false
+ end
+
+ pending "marks 2400 as a leap year" do
+ Year.leap?(2400).should be_true
+ end
+
+ pending "marks 2000 as a leap year" do
+ Year.leap?(2000).should be_true
+ end
+ end
+end
diff --git a/exercism/pangram/pangram_spec.cr b/exercism/pangram/pangram_spec.cr
new file mode 100644
index 0000000..b1d90f9
--- /dev/null
+++ b/exercism/pangram/pangram_spec.cr
@@ -0,0 +1,51 @@
+require "spec"
+require "./pangram"
+
+describe "Pangram" do
+ describe "#pangram?" do
+ it "should reject an empty string" do
+ str = ""
+ Pangram.pangram?(str).should be_false
+ end
+
+ pending "should accept a pangram with only lower case" do
+ str = "the quick brown fox jumps over the lazy dog"
+ Pangram.pangram?(str).should be_true
+ end
+
+ pending "should reject a string missing character 'x'" do
+ str = "a quick movement of the enemy will jeopardize five gunboats"
+ Pangram.pangram?(str).should be_false
+ end
+
+ pending "should reject another string missing character 'x'" do
+ str = "the quick brown fish jumps over the lazy dog"
+ Pangram.pangram?(str).should be_false
+ end
+
+ pending "should accept a pangram with underscores" do
+ str = "the_quick_brown_fox_jumps_over_the_lazy_dog"
+ Pangram.pangram?(str).should be_true
+ end
+
+ pending "should accept a pangram with numbers" do
+ str = "the 1 quick brown fox jumps over the 2 lazy dogs"
+ Pangram.pangram?(str).should be_true
+ end
+
+ pending "should reject a string where missing letters replaced by numbers" do
+ str = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"
+ Pangram.pangram?(str).should be_false
+ end
+
+ pending "should accept a pangram with mixed case and punctuation" do
+ str = "\"Five quacking Zephyrs jolt my wax bed.\""
+ Pangram.pangram?(str).should be_true
+ end
+
+ pending "should accept a pangram with non ascii characters" do
+ str = "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich."
+ Pangram.pangram?(str).should be_true
+ end
+ end
+end
diff --git a/exercism/raindrops/raindrops_spec.cr b/exercism/raindrops/raindrops_spec.cr
new file mode 100644
index 0000000..44a83c9
--- /dev/null
+++ b/exercism/raindrops/raindrops_spec.cr
@@ -0,0 +1,34 @@
+require "spec"
+require "./raindrops"
+
+describe "Raindrops" do
+ describe "#drops" do
+ it "converts 1 to 1" do
+ Raindrops.drops(1).should eq "1"
+ end
+
+ pending "converts 3 to Pling" do
+ Raindrops.drops(3).should eq "Pling"
+ end
+
+ pending "converts 5 to Plang" do
+ Raindrops.drops(5).should eq "Plang"
+ end
+
+ pending "converts 7 to Plong" do
+ Raindrops.drops(7).should eq "Plong"
+ end
+
+ pending "converts 35 to PlangPlong" do
+ Raindrops.drops(35).should eq "PlangPlong"
+ end
+
+ pending "converts 52 to 52" do
+ Raindrops.drops(52).should eq "52"
+ end
+
+ pending "converts 105 to PlingPlangPlong" do
+ Raindrops.drops(105).should eq "PlingPlangPlong"
+ end
+ end
+end
diff --git a/exercism/react/react_spec.cr b/exercism/react/react_spec.cr
new file mode 100644
index 0000000..63206dc
--- /dev/null
+++ b/exercism/react/react_spec.cr
@@ -0,0 +1,124 @@
+require "spec"
+require "./react"
+
+describe React::InputCell do
+ it "have a value" do
+ input = React::InputCell.new(10)
+ input.value.should eq 10
+ end
+
+ it "can have values set" do
+ input = React::InputCell.new(4)
+ input.value = 20
+ input.value.should eq 20
+ end
+end
+
+describe React::ComputeCell do
+ it "calculate initial value" do
+ input = React::InputCell.new(1)
+ output = React::ComputeCell.new(input) { |v| v + 1 }
+ output.value.should eq 2
+ end
+
+ it "take input in the right order" do
+ one = React::InputCell.new(1)
+ two = React::InputCell.new(2)
+ output = React::ComputeCell.new(one, two) { |v1, v2| v1 + v2 * 10 }
+ output.value.should eq 21
+ end
+
+ it "update value when dependencies are changed" do
+ one = React::InputCell.new(1)
+ output = React::ComputeCell.new(one) { |v| v + 1 }
+ one.value = 3
+ output.value.should eq 4
+ end
+
+ it "can depend on other compute cells" do
+ input = React::InputCell.new(1)
+ times_two = React::ComputeCell.new(input) { |v| v * 2 }
+ times_thirty = React::ComputeCell.new(input) { |v| v * 30 }
+ output = React::ComputeCell.new(times_two, times_thirty) { |v1, v2| v1 + v2 }
+ output.value.should eq 32
+ input.value = 3
+ output.value.should eq 96
+ end
+
+ describe "callbacks" do
+ it "are fired on change" do
+ values = [] of Int32
+ input = React::InputCell.new(1)
+ output = React::ComputeCell.new(input) { |v| v + 1 }
+ output.add_callback { |v| values << v }
+ input.value = 3
+ values.should eq [4]
+ end
+
+ it "are not fired if no change" do
+ values = [] of Int32
+ input = React::InputCell.new(1)
+ output = React::ComputeCell.new(input) { |v| v < 3 ? 111 : 222 }
+ output.add_callback { |v| values << v }
+ input.value = 2
+ values.should eq [] of Int32
+ input.value = 4
+ values.should eq [222]
+ end
+
+ it "can be added and removed" do
+ values1 = [] of Int32
+ values2 = [] of Int32
+ values3 = [] of Int32
+ input = React::InputCell.new(1)
+ output = React::ComputeCell.new(input) { |v| v + 1 }
+ callback = output.add_callback { |v| values1 << v }
+ output.add_callback { |v| values2 << v }
+ input.value = 31
+ values1.should eq [32]
+ values2.should eq [32]
+ output.remove_callback(callback)
+ output.add_callback { |v| values3 << v }
+ input.value = 41
+ values1.should eq [32]
+ values2.should eq [32, 42]
+ values3.should eq [42]
+ end
+
+ it "don't interfere with other callbacks if removed multiple times" do
+ values1 = [] of Int32
+ values2 = [] of Int32
+ input = React::InputCell.new(1)
+ output = React::ComputeCell.new(input) { |v| v + 1 }
+ callback = output.add_callback { |v| values1 << v }
+ output.add_callback { |v| values2 << v }
+ 10.times { output.remove_callback(callback) }
+ input.value = 2
+ values1.should eq [] of Int32
+ values2.should eq [3]
+ end
+
+ it "are called only once even if multiple dependencies change" do
+ values = [] of Int32
+ input = React::InputCell.new(1)
+ plus_one = React::ComputeCell.new(input) { |v| v + 1 }
+ minus_one1 = React::ComputeCell.new(input) { |v| v - 1 }
+ minus_one2 = React::ComputeCell.new(minus_one1) { |v| v - 1 }
+ output = React::ComputeCell.new(plus_one, minus_one2) { |v1, v2| v1 * v2 }
+ output.add_callback { |v| values << v }
+ input.value = 4
+ values.should eq [10]
+ end
+
+ it "are not called if dependencies change in such a way that final value doesn't change" do
+ values = [] of Int32
+ input = React::InputCell.new(1)
+ plus_one = React::ComputeCell.new(input) { |v| v + 1 }
+ minus_one = React::ComputeCell.new(input) { |v| v - 1 }
+ always_two = React::ComputeCell.new(plus_one, minus_one) { |v1, v2| v1 - v2 }
+ always_two.add_callback { |v| values << v }
+ 10.times { |i| input.value = i }
+ values.should eq [] of Int32
+ end
+ end
+end
diff --git a/exercism/rna-transcription/rna_transcription_spec.cr b/exercism/rna-transcription/rna_transcription_spec.cr
new file mode 100644
index 0000000..90dfe3d
--- /dev/null
+++ b/exercism/rna-transcription/rna_transcription_spec.cr
@@ -0,0 +1,26 @@
+require "spec"
+require "./rna_transcription"
+
+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
diff --git a/exercism/roman-numerals/roman_numerals_spec.cr b/exercism/roman-numerals/roman_numerals_spec.cr
new file mode 100644
index 0000000..46a6b76
--- /dev/null
+++ b/exercism/roman-numerals/roman_numerals_spec.cr
@@ -0,0 +1,61 @@
+require "spec"
+require "./roman_numerals"
+
+describe "Int" do
+ describe "#to_roman" do
+ it "changes 1 to I" do
+ 1.to_roman.should eq "I"
+ end
+ pending "changes 2 to II" do
+ 2.to_roman.should eq "II"
+ end
+ pending "changes 3 to III" do
+ 3.to_roman.should eq "III"
+ end
+ pending "changes 4 to IV" do
+ 4.to_roman.should eq "IV"
+ end
+ pending "changes 5 to V" do
+ 5.to_roman.should eq "V"
+ end
+ pending "changes 6 to VI" do
+ 6.to_roman.should eq "VI"
+ end
+ pending "changes 9 to IX" do
+ 9.to_roman.should eq "IX"
+ end
+ pending "changes 27 to XXVII" do
+ 27.to_roman.should eq "XXVII"
+ end
+ pending "changes 48 to XLVIII" do
+ 48.to_roman.should eq "XLVIII"
+ end
+ pending "changes 59 to LIX" do
+ 59.to_roman.should eq "LIX"
+ end
+ pending "changes 93 to XCIII" do
+ 93.to_roman.should eq "XCIII"
+ end
+ pending "changes 141 to CXLI" do
+ 141.to_roman.should eq "CXLI"
+ end
+ pending "changes 163 to CLXIII" do
+ 163.to_roman.should eq "CLXIII"
+ end
+ pending "changes 402 to CDII" do
+ 402.to_roman.should eq "CDII"
+ end
+ pending "changes 575 to DLXXV" do
+ 575.to_roman.should eq "DLXXV"
+ end
+ pending "changes 911 to CMXI" do
+ 911.to_roman.should eq "CMXI"
+ end
+ pending "changes 1024 to MXXIV" do
+ 1024.to_roman.should eq "MXXIV"
+ end
+ pending "changes 3000 to MMM" do
+ 3000.to_roman.should eq "MMM"
+ end
+ end
+end
diff --git a/exercism/sieve/sieve_spec.cr b/exercism/sieve/sieve_spec.cr
new file mode 100644
index 0000000..248bf75
--- /dev/null
+++ b/exercism/sieve/sieve_spec.cr
@@ -0,0 +1,22 @@
+require "spec"
+require "./sieve"
+
+describe "Primes" do
+ describe "#sieve" do
+ it "no primes under two" do
+ Primes.sieve(1).should eq [] of Int32
+ end
+ pending "find first prime" do
+ Primes.sieve(2).should eq [2]
+ end
+ pending "find primes up to 10" do
+ Primes.sieve(10).should eq [2, 3, 5, 7]
+ end
+ pending "limit is prime" do
+ Primes.sieve(13).should eq [2, 3, 5, 7, 11, 13]
+ end
+ pending "find primes up to 1000" do
+ Primes.sieve(1000).should eq [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
+ end
+ end
+end