diff --git a/README.md b/README.md index c4148e66..fec3e578 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# xCoffeeScript +# CoffeeScript Exercism exercises in CoffeeScript diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index f1f50f03..fdd46fde 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -4,16 +4,16 @@ [linstall]: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager -Install `jasmine-node` and `coffee`: +Install `jasmine-node` and `coffeescript`: ```bash -$ npm install jasmine-node coffeescript -g +$ npm install -g jasmine-node coffeescript ``` Depending on your setup, you may need super user privileges to install an `npm` module globally. This is the case if you've used the official installer linked to above. If NPM gives you an error saying you don't have access, add `sudo` to the command above: ```bash -$ sudo npm install jasmine-node coffeescript -g +$ sudo npm install -g jasmine-node coffeescript ``` If you've used the official installer, your `PATH` should have been automatically configured, but if your shell has trouble locating your globally installed modules--or if you build Node.js from source--update your `PATH` to include the `npm` binaries by adding the following to either `~/.bash_profile` or `~/.zshrc`: diff --git a/exercises/accumulate/accumulate.coffee b/exercises/accumulate/accumulate.coffee new file mode 100644 index 00000000..0b4171f8 --- /dev/null +++ b/exercises/accumulate/accumulate.coffee @@ -0,0 +1,3 @@ +# This is a stub file for the CoffeeScript track + +Array::accumulate = (args) -> diff --git a/exercises/accumulate/accumulate_test.spec.coffee b/exercises/accumulate/accumulate.spec.coffee similarity index 77% rename from exercises/accumulate/accumulate_test.spec.coffee rename to exercises/accumulate/accumulate.spec.coffee index 6d8d1f27..20fd3f3b 100644 --- a/exercises/accumulate/accumulate_test.spec.coffee +++ b/exercises/accumulate/accumulate.spec.coffee @@ -20,10 +20,10 @@ describe '[].accumulate()', -> accumulator = (word) -> word.split('').reverse().join('') result = 'the quick brown fox etc'.split(/\s/).accumulate accumulator - expect(result).toEqual ["eht", "kciuq", "nworb", "xof", "cte"] + expect(result).toEqual ['eht', 'kciuq', 'nworb', 'xof', 'cte'] xit 'accumulate recursively', -> result = 'a b c'.split(/\s+/).accumulate (char) -> - '1 2 3'.split(/\s+/).accumulate (digit) -> "#{char}#{digit}" + '1 2 3'.split(/\s+/).accumulate (digit) -> '#{char}#{digit}' - expect(result).toEqual([["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]]) + expect(result).toEqual([['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]) diff --git a/exercises/anagram/anagram.coffee b/exercises/anagram/anagram.coffee new file mode 100644 index 00000000..842096d3 --- /dev/null +++ b/exercises/anagram/anagram.coffee @@ -0,0 +1,8 @@ +# This is a stub file for the CoffeeScript track + +class Anagram + constructor: (args) -> + + match: (targets) -> + +module.exports = Anagram diff --git a/exercises/anagram/anagram.spec.coffee b/exercises/anagram/anagram.spec.coffee new file mode 100644 index 00000000..caa53fd2 --- /dev/null +++ b/exercises/anagram/anagram.spec.coffee @@ -0,0 +1,56 @@ +Anagram = require './anagram' +describe 'Anagram', -> + it 'no matches', -> + detector = new Anagram 'diaper' + matches = detector.match ['hello', 'world', 'zombies', 'pants'] + expect(matches).toEqual [] + + xit 'detects simple anagram', -> + detector = new Anagram 'ant' + matches = detector.match ['tan', 'stand', 'at'] + expect(matches).toEqual ['tan'] + + xit 'does not detect false positives', -> + detector = new Anagram 'galea' + matches = detector.match ['eagle'] + expect(matches).toEqual [] + + xit 'detects multiple anagrams', -> + detector = new Anagram 'master' + matches = detector.match ['stream', 'pigeon', 'maters'] + expect(matches).toEqual ['stream', 'maters'] + + xit 'does not detect anagram subsets', -> + detector = new Anagram 'good' + matches = detector.match ['dog', 'goody'] + expect(matches).toEqual [] + + xit 'detects anagram', -> + detector = new Anagram 'listen' + matches = detector.match ['enlists', 'google', 'inlets', 'banana'] + expect(matches).toEqual ['inlets'] + + xit 'detects multiple anagrams', -> + detector = new Anagram 'allergy' + matches = detector.match ['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading'] + expect(matches).toEqual ['gallery', 'regally', 'largely'] + + xit 'does not detect identical words', -> + detector = new Anagram 'corn' + matches = detector.match ['corn', 'dark', 'Corn', 'rank', 'CORN', 'cron', 'park'] + expect(matches).toEqual ['cron'] + + xit 'does not detect non-anagrams with identical checksum', -> + detector = new Anagram 'mass' + matches = detector.match ['last'] + expect(matches).toEqual [] + + xit 'detects anagrams using case-insensitive subject', -> + detector = new Anagram 'Orchestra' + matches = detector.match ['cashregister', 'carthorse', 'radishes'] + expect(matches).toEqual ['carthorse'] + + xit 'detects anagrams using case-insensitive candidates', -> + detector = new Anagram 'orchestra' + matches = detector.match ['cashregister', 'Carthorse', 'radishes'] + expect(matches).toEqual ['carthorse'] diff --git a/exercises/anagram/anagram_test.spec.coffee b/exercises/anagram/anagram_test.spec.coffee deleted file mode 100644 index d1b5d9b1..00000000 --- a/exercises/anagram/anagram_test.spec.coffee +++ /dev/null @@ -1,56 +0,0 @@ -Anagram = require "./anagram" -describe "Anagram", -> - it "no matches", -> - detector = new Anagram "diaper" - matches = detector.match ["hello", "world", "zombies", "pants"] - expect(matches).toEqual [] - - xit "detects simple anagram", -> - detector = new Anagram "ant" - matches = detector.match ["tan", "stand", "at"] - expect(matches).toEqual ["tan"] - - xit "does not detect false positives", -> - detector = new Anagram "galea" - matches = detector.match ["eagle"] - expect(matches).toEqual [] - - xit "detects multiple anagrams", -> - detector = new Anagram "master" - matches = detector.match ["stream", "pigeon", "maters"] - expect(matches).toEqual ["stream", "maters"] - - xit "does not detect anagram subsets", -> - detector = new Anagram "good" - matches = detector.match ["dog", "goody"] - expect(matches).toEqual [] - - xit "detects anagram", -> - detector = new Anagram "listen" - matches = detector.match ["enlists", "google", "inlets", "banana"] - expect(matches).toEqual ["inlets"] - - xit "detects multiple anagrams", -> - detector = new Anagram "allergy" - matches = detector.match ["gallery", "ballerina", "regally", "clergy", "largely", "leading"] - expect(matches).toEqual ["gallery", "regally", "largely"] - - xit "does not detect identical words", -> - detector = new Anagram "corn" - matches = detector.match ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"] - expect(matches).toEqual ["cron"] - - xit "does not detect non-anagrams with identical checksum", -> - detector = new Anagram "mass" - matches = detector.match ["last"] - expect(matches).toEqual [] - - xit "detects anagrams using case-insensitive subject", -> - detector = new Anagram "Orchestra" - matches = detector.match ["cashregister", "carthorse", "radishes"] - expect(matches).toEqual ["carthorse"] - - xit "detects anagrams using case-insensitive candidates", -> - detector = new Anagram "orchestra" - matches = detector.match ["cashregister", "Carthorse", "radishes"] - expect(matches).toEqual ["carthorse"] diff --git a/exercises/atbash-cipher/atbash-cipher.coffee b/exercises/atbash-cipher/atbash-cipher.coffee new file mode 100644 index 00000000..502ad1cb --- /dev/null +++ b/exercises/atbash-cipher/atbash-cipher.coffee @@ -0,0 +1,6 @@ +# This is a stub file for the CoffeeScript track + +class AtbashCipher + encode: (args) -> + +module.exports = AtbashCipher diff --git a/exercises/atbash-cipher/atbash_cipher_test.spec.coffee b/exercises/atbash-cipher/atbash-cipher.spec.coffee similarity index 95% rename from exercises/atbash-cipher/atbash_cipher_test.spec.coffee rename to exercises/atbash-cipher/atbash-cipher.spec.coffee index a277f9d0..44e34372 100644 --- a/exercises/atbash-cipher/atbash_cipher_test.spec.coffee +++ b/exercises/atbash-cipher/atbash-cipher.spec.coffee @@ -1,4 +1,4 @@ -Atbash = require './atbash' +Atbash = require './atbash-cipher' describe 'Atbash', -> it 'encodes no', -> diff --git a/exercises/atbash-cipher/atbash.coffee b/exercises/atbash-cipher/atbash.coffee new file mode 100644 index 00000000..d5197af8 --- /dev/null +++ b/exercises/atbash-cipher/atbash.coffee @@ -0,0 +1,5 @@ +class Atbash + + @encode: (args) -> + +module.exports = Atbash diff --git a/exercises/beer-song/beer-song.coffee b/exercises/beer-song/beer-song.coffee new file mode 100644 index 00000000..5a3ac0a4 --- /dev/null +++ b/exercises/beer-song/beer-song.coffee @@ -0,0 +1,8 @@ +# This is a stub file for the CoffeeScript track + +class BeerSong + verse: (args) -> + + sing: (args) -> + +module.exports = BeerSong diff --git a/exercises/beer-song/beer-song_test.spec.coffee b/exercises/beer-song/beer-song.spec.coffee similarity index 63% rename from exercises/beer-song/beer-song_test.spec.coffee rename to exercises/beer-song/beer-song.spec.coffee index cdc82ce5..fdde8cca 100644 --- a/exercises/beer-song/beer-song_test.spec.coffee +++ b/exercises/beer-song/beer-song.spec.coffee @@ -1,25 +1,25 @@ -Beer = require("./beer") -describe "Beer", -> - it "prints an arbitrary verse", -> - expect(Beer.verse 8).toEqual """ +Beer = require './beer-song' +describe 'Beer', -> + it 'prints an arbitrary verse', -> + expect(Beer.verse 8).toEqual ' 8 bottles of beer on the wall, 8 bottles of beer. Take one down and pass it around, 7 bottles of beer on the wall. - """ + ' - xit "handles 1 bottle", -> - expect(Beer.verse 1).toEqual """ + xit 'handles 1 bottle', -> + expect(Beer.verse 1).toEqual ' 1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around, no more bottles of beer on the wall. - """ + ' - xit "handles 0 bottles", -> - expect(Beer.verse 0).toEqual """ + xit 'handles 0 bottles', -> + expect(Beer.verse 0).toEqual ' No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall. - """ + ' - xit "sings several verses", -> - expect(Beer.sing 8, 6).toEqual """ + xit 'sings several verses', -> + expect(Beer.sing 8, 6).toEqual ' 8 bottles of beer on the wall, 8 bottles of beer. Take one down and pass it around, 7 bottles of beer on the wall. @@ -29,10 +29,10 @@ describe "Beer", -> 6 bottles of beer on the wall, 6 bottles of beer. Take one down and pass it around, 5 bottles of beer on the wall. - """ + ' - xit "sings the rest of the verses", -> - expect(Beer.sing 3).toEqual """ + xit 'sings the rest of the verses', -> + expect(Beer.sing 3).toEqual ' 3 bottles of beer on the wall, 3 bottles of beer. Take one down and pass it around, 2 bottles of beer on the wall. @@ -45,6 +45,11 @@ describe "Beer", -> No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall. +<<<<<<< HEAD:exercises/beer-song/beer-song.spec.coffee + ' +======= """ - - +<<<<<<< HEAD:exercises/beer-song/beer-song.spec.coffee +>>>>>>> beer-song stub file:exercises/beer-song/beer-song_test.spec.coffee +======= +>>>>>>> b04a45190849e2f4cb3f56024234c4da51df9ab7:exercises/beer-song/beer-song_test.spec.coffee diff --git a/exercises/binary-search-tree/binary-search-tree.coffee b/exercises/binary-search-tree/binary-search-tree.coffee new file mode 100644 index 00000000..e843b0e9 --- /dev/null +++ b/exercises/binary-search-tree/binary-search-tree.coffee @@ -0,0 +1,9 @@ +# This is a stub file for the CoffeeScript track +class BinarySearchTree + constructor: (args) -> + + insert: (args) -> + + data: -> + +module.exports = BinarySearchTree diff --git a/exercises/binary-search-tree/binary_search_tree_test.spec.coffee b/exercises/binary-search-tree/binary-search-tree.spec.coffee similarity index 77% rename from exercises/binary-search-tree/binary_search_tree_test.spec.coffee rename to exercises/binary-search-tree/binary-search-tree.spec.coffee index 6355c6a7..03856b5d 100644 --- a/exercises/binary-search-tree/binary_search_tree_test.spec.coffee +++ b/exercises/binary-search-tree/binary-search-tree.spec.coffee @@ -1,4 +1,4 @@ -Bst = require './bst' +BinarySearchTree = require './binary-search-tree' recordAllData = (bst) -> out = [] @@ -8,31 +8,31 @@ recordAllData = (bst) -> describe 'BinarySearchTree', -> it 'data is retained', -> - expect(4).toEqual new Bst(4).data + expect(4).toEqual new BinarySearchTree(4).data xit 'inserting less', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(2) expect(four.data).toEqual 4 expect(four.left.data).toEqual 2 xit 'inserting same', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(4) expect(four.data).toEqual 4 expect(four.left.data).toEqual 4 xit 'inserting right', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(5) expect(four.data).toEqual 4 expect(four.right.data).toEqual xit 'complex tree', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(2) four.insert(6) four.insert(1) @@ -49,22 +49,22 @@ describe 'BinarySearchTree', -> expect(four.right.right.data).toEqual 7 xit 'iterating one element', -> - expect(recordAllData(new Bst(4))).toEqual [4] + expect(recordAllData(new BinarySearchTree(4))).toEqual [4] xit 'iterating over smaller element', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(2) expect(recordAllData(four)).toEqual [2, 4] xit 'iterating over larger element', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(5) expect(recordAllData(four)).toEqual [4, 5] xit 'iterating over complex tree', -> - four = new Bst(4) + four = new BinarySearchTree(4) four.insert(2) four.insert(1) four.insert(3) diff --git a/exercises/binary/binary.coffee b/exercises/binary/binary.coffee new file mode 100644 index 00000000..16a062d1 --- /dev/null +++ b/exercises/binary/binary.coffee @@ -0,0 +1,8 @@ +# This is a stub file for the CoffeeScript track + +class Binary + constructor: (args) -> + + toDecimal: -> + +module.exports = Binary diff --git a/exercises/binary/binary_test.spec.coffee b/exercises/binary/binary.spec.coffee similarity index 100% rename from exercises/binary/binary_test.spec.coffee rename to exercises/binary/binary.spec.coffee diff --git a/exercises/bob/.meta/description.md b/exercises/bob/.meta/description.md deleted file mode 100644 index 1072139f..00000000 --- a/exercises/bob/.meta/description.md +++ /dev/null @@ -1,10 +0,0 @@ -Bob is a lackadaisical teenager. In conversation, his responses are very limited. - -Bob answers 'Sure.' if you ask him a question. - -He answers 'Whoa, chill out!' if you yell at him. - -He says 'Fine. Be that way!' if you address him without actually saying -anything. - -He answers 'Whatever.' to anything else. diff --git a/exercises/bob/bob.coffee b/exercises/bob/bob.coffee new file mode 100644 index 00000000..6fa2dd90 --- /dev/null +++ b/exercises/bob/bob.coffee @@ -0,0 +1,4 @@ +class Bob + hey: (args) -> + +module.exports = Bob diff --git a/exercises/bob/bob.spec.coffee b/exercises/bob/bob.spec.coffee new file mode 100644 index 00000000..428757c3 --- /dev/null +++ b/exercises/bob/bob.spec.coffee @@ -0,0 +1,58 @@ +Bob = require './bob' +describe 'Bob', -> + bob = new Bob() + it 'stating something', -> + result = bob.hey 'Tom-ay-to, tom-aaaah-to.' + expect(result).toEqual 'Whatever.' + + xit 'shouting', -> + result = bob.hey 'WATCH OUT!' + expect(result).toEqual 'Whoa, chill out!' + + xit 'asking a question', -> + result = bob.hey 'Does this cryogenic chamber make me look fat?' + expect(result).toEqual 'Sure.' + + xit 'talking forcefully', -> + result = bob.hey 'Let's go make out behind the gym!' + expect(result).toEqual 'Whatever.' + + xit 'using acronyms in regular speech', -> + result = bob.hey 'It's OK if you don't want to go to the DMV.' + expect(result).toEqual 'Whatever.' + + xit 'forceful questions', -> + result = bob.hey 'WHAT THE HELL WERE YOU THINKING?' + expect(result).toEqual 'Whoa, chill out!' + + xit 'shouting numbers', -> + result = bob.hey '1, 2, 3 GO!' + expect(result).toEqual 'Whoa, chill out!' + + xit 'only number', -> + result = bob.hey '1, 2, 3' + expect(result).toEqual 'Whatever.' + + xit 'shouting with special characters', -> + result = bob.hey 'ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!' + expect(result).toEqual 'Whoa, chill out!' + + xit 'shouting with no exclamation mark', -> + result = bob.hey 'I HATE YOU' + expect(result).toEqual 'Whoa, chill out!' + + xit 'statement containing question mark', -> + result = bob.hey 'Ending with a ? means a question.' + expect(result).toEqual 'Whatever.' + + xit 'prattling on', -> + result = bob.hey 'Wait! Hang on. Are you going to be OK?' + expect(result).toEqual 'Sure.' + + xit 'silence', -> + result = bob.hey '' + expect(result).toEqual 'Fine. Be that way!' + + xit 'prolonged silence', -> + result = bob.hey ' ' + expect(result).toEqual 'Fine. Be that way!' diff --git a/exercises/bob/bob_test.spec.coffee b/exercises/bob/bob_test.spec.coffee deleted file mode 100644 index 435a5e32..00000000 --- a/exercises/bob/bob_test.spec.coffee +++ /dev/null @@ -1,58 +0,0 @@ -Bob = require "./bob" -describe "Bob", -> - bob = new Bob() - it "stating something", -> - result = bob.hey "Tom-ay-to, tom-aaaah-to." - expect(result).toEqual "Whatever." - - xit "shouting", -> - result = bob.hey "WATCH OUT!" - expect(result).toEqual "Whoa, chill out!" - - xit "asking a question", -> - result = bob.hey "Does this cryogenic chamber make me look fat?" - expect(result).toEqual "Sure." - - xit "talking forcefully", -> - result = bob.hey "Let's go make out behind the gym!" - expect(result).toEqual "Whatever." - - xit "using acronyms in regular speech", -> - result = bob.hey "It's OK if you don't want to go to the DMV." - expect(result).toEqual "Whatever." - - xit "forceful questions", -> - result = bob.hey "WHAT THE HELL WERE YOU THINKING?" - expect(result).toEqual "Whoa, chill out!" - - xit "shouting numbers", -> - result = bob.hey "1, 2, 3 GO!" - expect(result).toEqual "Whoa, chill out!" - - xit "only number", -> - result = bob.hey "1, 2, 3" - expect(result).toEqual "Whatever." - - xit "shouting with special characters", -> - result = bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" - expect(result).toEqual "Whoa, chill out!" - - xit "shouting with no exclamation mark", -> - result = bob.hey "I HATE YOU" - expect(result).toEqual "Whoa, chill out!" - - xit "statement containing question mark", -> - result = bob.hey "Ending with a ? means a question." - expect(result).toEqual "Whatever." - - xit "prattling on", -> - result = bob.hey "Wait! Hang on. Are you going to be OK?" - expect(result).toEqual "Sure." - - xit "silence", -> - result = bob.hey "" - expect(result).toEqual "Fine. Be that way!" - - xit "prolonged silence", -> - result = bob.hey " " - expect(result).toEqual "Fine. Be that way!" diff --git a/exercises/clock/clock.spec.coffee b/exercises/clock/clock.spec.coffee new file mode 100644 index 00000000..ee7dd276 --- /dev/null +++ b/exercises/clock/clock.spec.coffee @@ -0,0 +1,46 @@ +Clock = require './clock' + +describe 'Clock', -> + it 'prints the hour', -> + expect(Clock.at(8).toString()).toEqual '08:00' + expect(Clock.at(9).toString()).toEqual '09:00' + + xit 'prints past the hour', -> + expect(Clock.at(11, 9).toString()).toEqual '11:09' + expect(Clock.at(11, 19).toString()).toEqual '11:19' + + xit 'can add minutes', -> + clock = Clock.at(10).plus 3 + expect(clock.toString()).toEqual '10:03' + + xit 'can add over an hour', -> + clock = Clock.at(10).plus 61 + expect(clock.toString()).toEqual '11:01' + + xit 'wraps around midnight', -> + clock = Clock.at(23, 59).plus 2 + expect(clock.toString()).toEqual '00:01' + + xit 'can subtract minutes', -> + clock = Clock.at(10, 3).minus 3 + expect(clock.toString()).toEqual '10:00' + + xit 'can subtract over an hour', -> + clock = Clock.at(10, 3).minus 30 + expect(clock.toString()).toEqual '09:33' + clock = Clock.at(10, 3).minus 70 + expect(clock.toString()).toEqual '08:53' + + xit 'can know if it's equal to another clock', -> + clock1 = Clock.at(10, 3) + clock2 = Clock.at(10, 3) + expect(clock1.equals clock2).toBe true + + xit 'can know if it's not equal to another clock', -> + clock1 = Clock.at(10, 3) + clock2 = Clock.at(10, 4) + expect(clock1.equals clock2).toBe false + + xit 'wraps around midnight backwards', -> + clock = Clock.at(0, 3).minus 4 + expect(clock.toString()).toEqual '23:59' diff --git a/exercises/clock/clock_test.spec.coffee b/exercises/clock/clock_test.spec.coffee deleted file mode 100644 index 815f2870..00000000 --- a/exercises/clock/clock_test.spec.coffee +++ /dev/null @@ -1,47 +0,0 @@ -Clock = require './clock' - -describe "Clock", -> - it "prints the hour", -> - expect(Clock.at(8).toString()).toEqual "08:00" - expect(Clock.at(9).toString()).toEqual "09:00" - - xit "prints past the hour", -> - expect(Clock.at(11, 9).toString()).toEqual "11:09" - expect(Clock.at(11, 19).toString()).toEqual "11:19" - - xit "can add minutes", -> - clock = Clock.at(10).plus 3 - expect(clock.toString()).toEqual "10:03" - - xit "can add over an hour", -> - clock = Clock.at(10).plus 61 - expect(clock.toString()).toEqual "11:01" - - xit "wraps around midnight", -> - clock = Clock.at(23, 59).plus 2 - expect(clock.toString()).toEqual "00:01" - - xit "can subtract minutes", -> - clock = Clock.at(10, 3).minus 3 - expect(clock.toString()).toEqual "10:00" - - xit "can subtract over an hour", -> - clock = Clock.at(10, 3).minus 30 - expect(clock.toString()).toEqual "09:33" - clock = Clock.at(10, 3).minus 70 - expect(clock.toString()).toEqual "08:53" - - xit "can know if it's equal to another clock", -> - clock1 = Clock.at(10, 3) - clock2 = Clock.at(10, 3) - expect(clock1.equals clock2).toBe true - - xit "can know if it's not equal to another clock", -> - clock1 = Clock.at(10, 3) - clock2 = Clock.at(10, 4) - expect(clock1.equals clock2).toBe false - - xit "wraps around midnight backwards", -> - clock = Clock.at(0, 3).minus 4 - expect(clock.toString()).toEqual "23:59" - diff --git a/exercises/hello-world/hello_world.coffee b/exercises/hello-world/hello-world.coffee similarity index 55% rename from exercises/hello-world/hello_world.coffee rename to exercises/hello-world/hello-world.coffee index 7f253da3..09c28c85 100644 --- a/exercises/hello-world/hello_world.coffee +++ b/exercises/hello-world/hello-world.coffee @@ -1,5 +1,4 @@ -# Simply return the string 'Hello, World!' - +# This is a stub file for the CoffeeScript track class HelloWorld hello: -> '' diff --git a/exercises/hello-world/hello_world.spec.coffee b/exercises/hello-world/hello-world.spec.coffee similarity index 65% rename from exercises/hello-world/hello_world.spec.coffee rename to exercises/hello-world/hello-world.spec.coffee index c5e6e037..f457f579 100644 --- a/exercises/hello-world/hello_world.spec.coffee +++ b/exercises/hello-world/hello-world.spec.coffee @@ -1,8 +1,8 @@ -HelloWorld = require "./hello_world" +HelloWorld = require './hello-world' describe 'HelloWorld', -> hello_world = new HelloWorld() - it "says 'Hello, World!'", -> + it 'says \'Hello, World!\'', -> result = hello_world.hello() expect(result).toEqual 'Hello, World!' diff --git a/exercises/hexadecimal/hexadecimal.coffee b/exercises/hexadecimal/hexadecimal.coffee new file mode 100644 index 00000000..c78c6d3b --- /dev/null +++ b/exercises/hexadecimal/hexadecimal.coffee @@ -0,0 +1,7 @@ +# This is a stub file for the CoffeeScript track +class Hexadecimal + constructor: (args) -> + + toDecimal: (args) -> + +module.exports = Hexadecimal diff --git a/exercises/hexadecimal/hexadecimal.spec.coffee b/exercises/hexadecimal/hexadecimal.spec.coffee new file mode 100644 index 00000000..a786126b --- /dev/null +++ b/exercises/hexadecimal/hexadecimal.spec.coffee @@ -0,0 +1,43 @@ +Hexadecimal = require './hexadecimal' + +describe 'Hexadecimal', -> + + it 'hex 1 is decimal 1', -> + hex = new Hexadecimal('1') + expect(hex.toDecimal()).toEqual(1) + + xit 'hex c is decimal 12', -> + hex = new Hexadecimal('c') + expect(hex.toDecimal()).toEqual(12) + + xit 'hex 10 is decimal 16', -> + hex = new Hexadecimal('10') + expect(hex.toDecimal()).toEqual(16) + + xit 'hex af is decimal 175', -> + hex = new Hexadecimal('af') + expect(hex.toDecimal()).toEqual(175) + + xit 'hex 100 is decimal 256', -> + hex = new Hexadecimal('100') + expect(hex.toDecimal()).toEqual(256) + + xit 'hex 19ace is decimal 105166', -> + hex = new Hexadecimal('19ace') + expect(hex.toDecimal()).toEqual(105166) + + xit 'invalid hex is decimal 0', -> + hex = new Hexadecimal('carrot') + expect(hex.toDecimal()).toEqual(0) + + xit 'black', -> + hex = new Hexadecimal('000000') + expect(hex.toDecimal()).toEqual(0) + + xit 'white', -> + hex = new Hexadecimal('ffffff') + expect(hex.toDecimal()).toEqual(16777215) + + xit 'yellow', -> + hex = new Hexadecimal('ffff00') + expect(hex.toDecimal()).toEqual(16776960) diff --git a/exercises/hexadecimal/hexadecimal_test.spec.coffee b/exercises/hexadecimal/hexadecimal_test.spec.coffee deleted file mode 100644 index a442565e..00000000 --- a/exercises/hexadecimal/hexadecimal_test.spec.coffee +++ /dev/null @@ -1,43 +0,0 @@ -Hexadecimal = require('./hexadecimal') - -describe "Hexadecimal", -> - - it "hex 1 is decimal 1", -> - hex = new Hexadecimal("1") - expect(hex.toDecimal()).toEqual(1) - - xit "hex c is decimal 12", -> - hex = new Hexadecimal("c") - expect(hex.toDecimal()).toEqual(12) - - xit "hex 10 is decimal 16", -> - hex = new Hexadecimal("10") - expect(hex.toDecimal()).toEqual(16) - - xit "hex af is decimal 175", -> - hex = new Hexadecimal("af") - expect(hex.toDecimal()).toEqual(175) - - xit "hex 100 is decimal 256", -> - hex = new Hexadecimal("100") - expect(hex.toDecimal()).toEqual(256) - - xit "hex 19ace is decimal 105166", -> - hex = new Hexadecimal("19ace") - expect(hex.toDecimal()).toEqual(105166) - - xit "invalid hex is decimal 0", -> - hex = new Hexadecimal("carrot") - expect(hex.toDecimal()).toEqual(0) - - xit "black", -> - hex = new Hexadecimal("000000") - expect(hex.toDecimal()).toEqual(0) - - xit "white", -> - hex = new Hexadecimal("ffffff") - expect(hex.toDecimal()).toEqual(16777215) - - xit "yellow", -> - hex = new Hexadecimal("ffff00") - expect(hex.toDecimal()).toEqual(16776960) diff --git a/exercises/linked-list/linked-list.coffee b/exercises/linked-list/linked-list.coffee new file mode 100644 index 00000000..3112d8eb --- /dev/null +++ b/exercises/linked-list/linked-list.coffee @@ -0,0 +1,17 @@ +class LinkedList + count: -> + + pushNode: (args) -> + + popNode: (args) -> + + deleteNode: (args) -> + + shiftNode: (args) -> + + unshiftNode: (args) -> + + countNodes: -> + + +module.exports = LinkedList diff --git a/exercises/linked-list/linked-list_test.spec.coffee b/exercises/linked-list/linked-list.spec.coffee similarity index 97% rename from exercises/linked-list/linked-list_test.spec.coffee rename to exercises/linked-list/linked-list.spec.coffee index 64760f43..930c7cdb 100644 --- a/exercises/linked-list/linked-list_test.spec.coffee +++ b/exercises/linked-list/linked-list.spec.coffee @@ -1,9 +1,10 @@ -LinkedList = require('./linkedList') +LinkedList = require './linked-list' describe 'LinkedList', -> it 'init', -> list = new LinkedList() expect(list.count).toBe 0 + xit 'push/pop', -> list = new LinkedList() list.pushNode(10) @@ -11,12 +12,14 @@ describe 'LinkedList', -> list.pushNode(30) expect(list.popNode()).toBe 30 expect(list.popNode()).toBe 20 + xit 'push/shift', -> list = new LinkedList() list.pushNode(10) list.pushNode(20) expect(list.shiftNode()).toBe 10 expect(list.shiftNode()).toBe 20 + xit 'unshift/shift', -> list = new LinkedList() list.unshiftNode(20) @@ -24,11 +27,13 @@ describe 'LinkedList', -> list.unshiftNode(30) expect(list.shiftNode()).toBe 30 expect(list.shiftNode()).toBe 10 + xit 'unshift/pop', -> list = new LinkedList() list.unshiftNode(20) list.unshiftNode(30) expect(list.popNode()).toBe 20 + xit 'example', -> list = new LinkedList() list.pushNode(10) @@ -44,9 +49,11 @@ describe 'LinkedList', -> list.deleteNode(60) expect(list.countNodes()).toBe 1 expect(list.shiftNode()).toBe 30 + xit 'pops undefined when there are no elements', -> list = new LinkedList() expect(list.popNode()).toBe undefined + xit ' can count its elements', -> list = new LinkedList() list.pushNode(20) @@ -61,9 +68,9 @@ describe 'LinkedList', -> list.deleteNode(10) expect(list.countNodes()).toBe 2 expect(list.shiftNode()).toBe 20 + xit 'deletes only the last element', -> list = new LinkedList() list.pushNode(10) list.deleteNode(10) expect(list.countNodes()).toBe 0 - diff --git a/exercises/luhn/luhn.coffee b/exercises/luhn/luhn.coffee new file mode 100644 index 00000000..d7c04f2e --- /dev/null +++ b/exercises/luhn/luhn.coffee @@ -0,0 +1,7 @@ +class Luhn + constructor: (args) -> + + valid: -> + + +module.exports = Luhn diff --git a/exercises/luhn/luhn.spec.coffee b/exercises/luhn/luhn.spec.coffee new file mode 100644 index 00000000..03386724 --- /dev/null +++ b/exercises/luhn/luhn.spec.coffee @@ -0,0 +1,71 @@ +Luhn = require './luhn' + +describe 'Luhn', -> + + it 'single digit strings can not be valid', -> + luhn = new Luhn('1') + expect(luhn.valid).toEqual(false) + + xit 'a single zero is invalid', -> + luhn = new Luhn('0') + expect(luhn.valid).toEqual(false) + + xit 'a simple valid SIN that remains valid if reversed', -> + luhn = new Luhn('059') + expect(luhn.valid).toEqual(true) + + xit 'a simple valid SIN that becomes invalid if reversed', -> + luhn = new Luhn('59') + expect(luhn.valid).toEqual(true) + + xit 'a valid Canadian SIN', -> + luhn = new Luhn('055 444 286') + expect(luhn.valid).toEqual(true) + + xit 'invalid credit card', -> + luhn = new Luhn('8273 1232 7352 0569') + expect(luhn.valid).toEqual(false) + + xit 'invalid credit card', -> + luhn = new Luhn('8273 1232 7352 0569') + expect(luhn.valid).toEqual(false) + + xit 'valid number with an even number of digits', -> + luhn = new Luhn('095 245 88') + expect(luhn.valid).toEqual(true) + + xit 'valid number with an odd number of spaces', -> + luhn = new Luhn('234 567 891 234') + expect(luhn.valid).toEqual(true) + + xit 'valid strings with a non-digit added at the end become invalid', -> + luhn = new Luhn('059a') + expect(luhn.valid).toEqual(false) + + xit 'valid strings with punctuation included become invalid', -> + luhn = new Luhn('055-444-285') + expect(luhn.valid).toEqual(false) + + xit 'valid strings with symbols included become invalid', -> + luhn = new Luhn('055# 444$ 285') + expect(luhn.valid).toEqual(false) + + xit 'single zero with space is invalid', -> + luhn = new Luhn(' 0') + expect(luhn.valid).toEqual(false) + + xit 'more than a single zero is valid', -> + luhn = new Luhn('0000 0') + expect(luhn.valid).toEqual(true) + + xit 'input digit 9 is correctly converted to output digit 9', -> + luhn = new Luhn('091') + expect(luhn.valid).toEqual(true) + + xit 'using ascii value for non-doubled non-digit isn\'t allowed', -> + luhn = new Luhn('055b 444 285') + expect(luhn.valid).toEqual(false) + + xit 'using ascii value for doubled non-digit isn\'t allowed', -> + luhn = new Luhn(':9') + expect(luhn.valid).toEqual(false) diff --git a/exercises/luhn/luhn_test.spec.coffee b/exercises/luhn/luhn_test.spec.coffee deleted file mode 100644 index 08703886..00000000 --- a/exercises/luhn/luhn_test.spec.coffee +++ /dev/null @@ -1,47 +0,0 @@ -Luhn = require './luhn' - -describe 'Luhn', -> - - it "check digit", -> - luhn = new Luhn(34567) - expect(luhn.checkDigit).toEqual(7) - - xit "check digit again", -> - luhn = new Luhn(91370) - expect(luhn.checkDigit).toEqual(0) - - xit "addends", -> - luhn = new Luhn(12121) - expect(luhn.addends).toEqual([1, 4, 1, 4, 1]) - - xit "too large added", -> - luhn = new Luhn(8631) - expect(luhn.addends).toEqual([7, 6, 6, 1]) - - xit "checksum", -> - luhn = new Luhn(4913) - expect(luhn.checksum).toEqual(22) - - xit "checksum again", -> - luhn = new Luhn(201773) - expect(luhn.checksum).toEqual(21) - - xit "invalid number", -> - luhn = new Luhn(738) - expect(luhn.valid).toEqual(false) - - xit "valid number", -> - luhn = new Luhn(8739567) - expect(luhn.valid).toEqual(true) - - xit "create valid number", -> - number = Luhn.create(123) - expect(number).toEqual(1230) - - xit "create other valid number", -> - number = Luhn.create(873956) - expect(number).toEqual(8739567) - - xit "create yet another valid number", -> - number = Luhn.create(837263756) - expect(number).toEqual(8372637564) diff --git a/exercises/nth-prime/nth-prime.coffee b/exercises/nth-prime/nth-prime.coffee new file mode 100644 index 00000000..2e03189a --- /dev/null +++ b/exercises/nth-prime/nth-prime.coffee @@ -0,0 +1,4 @@ +class NthPrime + nth: (args) -> + +module.exports = NthPrime diff --git a/exercises/nth-prime/nth_prime_test.spec.coffee b/exercises/nth-prime/nth-prime.spec.coffee similarity index 79% rename from exercises/nth-prime/nth_prime_test.spec.coffee rename to exercises/nth-prime/nth-prime.spec.coffee index 581e7324..4fdef710 100644 --- a/exercises/nth-prime/nth_prime_test.spec.coffee +++ b/exercises/nth-prime/nth-prime.spec.coffee @@ -1,4 +1,4 @@ -Prime = require './prime' +Prime = require './nth-prime' describe 'Prime', -> @@ -19,4 +19,4 @@ describe 'Prime', -> expect(prime).toEqual(104743) xit 'weird case', -> - expect(-> Prime.nth(0)).toThrow("Prime is not possible") + expect(-> Prime.nth(0)).toThrow('Prime is not possible') diff --git a/exercises/nucleotide-count/nucleotide-count.coffee b/exercises/nucleotide-count/nucleotide-count.coffee new file mode 100644 index 00000000..0e0edd59 --- /dev/null +++ b/exercises/nucleotide-count/nucleotide-count.coffee @@ -0,0 +1,7 @@ +class NucleotideCount + constructor: (args) -> + @nucleotideCounts = + + count: (args) -> + +module.exports = NucleotideCount diff --git a/exercises/nucleotide-count/nucleotide-count_test.spec.coffee b/exercises/nucleotide-count/nucleotide-count.spec.coffee similarity index 56% rename from exercises/nucleotide-count/nucleotide-count_test.spec.coffee rename to exercises/nucleotide-count/nucleotide-count.spec.coffee index 49aa0a1d..c97ef99a 100644 --- a/exercises/nucleotide-count/nucleotide-count_test.spec.coffee +++ b/exercises/nucleotide-count/nucleotide-count.spec.coffee @@ -1,25 +1,25 @@ -DNA = require './example' +NucleotideCount = require './nucleotide-count' -describe 'DNA', -> +describe 'NucleotideCount', -> it 'has no nucleotides', -> expected = A: 0 T: 0 C: 0 G: 0 - dna = new DNA('') + dna = new NucleotideCount('') expect(dna.nucleotideCounts).toEqual expected xit 'has no adoenosine', -> - dna = new DNA('') + dna = new NucleotideCount('') expect(dna.count('A')).toEqual 0 xit 'repetitive cytidine gets counts', -> - dna = new DNA('CCCCC') + dna = new NucleotideCount('CCCCC') expect(dna.count('C')).toEqual 5 xit 'repetitive sequence has only gaunosine', -> - dna = new DNA('GGGGGGGG') + dna = new NucleotideCount('GGGGGGGG') expected = A: 0 T: 0 @@ -28,22 +28,28 @@ describe 'DNA', -> expect(dna.nucleotideCounts).toEqual expected xit 'counts only thymidine', -> - dna = new DNA('GGGGTAACCCGG') + dna = new NucleotideCount('GGGGTAACCCGG') expect(dna.count('T')).toEqual 1 xit 'counts a nucleotide only once', -> - dna = new DNA('GGTTGG') + dna = new NucleotideCount('GGTTGG') dna.count('T') expect(dna.count('T')).toEqual 2 + xit 'validates strand', -> + dna = new NucleotideCount('AGTXCG') + expect -> + dna.count 'G' + .toThrow new Error('Invalid nucleotide strand') + xit 'validates nucleotides', -> - dna = new DNA('GGTTGG') + dna = new NucleotideCount('GGTTGG') expect -> dna.count 'X' - .toThrow new Error('Invalid Nucleotide') + .toThrow new Error('Invalid nucleotide') xit 'counts all nucleotides', -> - dna = new DNA('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC') + dna = new NucleotideCount('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC') expected = A: 20 T: 21 diff --git a/exercises/palindrome-products/palindrome-products.coffee b/exercises/palindrome-products/palindrome-products.coffee new file mode 100644 index 00000000..926f6a7c --- /dev/null +++ b/exercises/palindrome-products/palindrome-products.coffee @@ -0,0 +1,10 @@ +class PalindromeProducts + constructor: (args) -> + + generate: -> + + smallest: -> + + largest: -> + +module.export = PalindromeProducts diff --git a/exercises/palindrome-products/palindrome_products_test.spec.coffee b/exercises/palindrome-products/palindrome-products.spec.coffee similarity index 52% rename from exercises/palindrome-products/palindrome_products_test.spec.coffee rename to exercises/palindrome-products/palindrome-products.spec.coffee index 7296cc88..8fe0bf8f 100644 --- a/exercises/palindrome-products/palindrome_products_test.spec.coffee +++ b/exercises/palindrome-products/palindrome-products.spec.coffee @@ -1,37 +1,37 @@ -Palindromes = require('./palindromes') +Palindromes = require './palindrome-products' -describe "Palindrome", -> +describe 'Palindrome', -> - it "largest palindrome from single digit factors", -> - palindromes = new Palindromes({maxFactor: 9}) + it 'largest palindrome from single digit factors', -> + palindromes = new PalindromeProducts({maxFactor: 9}) palindromes.generate() largest = palindromes.largest() expect(largest.value).toEqual(9) expect([[[3, 3], [1, 9]], [[1, 9], [3, 3]]]).toContain(largest.factors) - xit "largest palindrome from double digit factors", -> - palindromes = new Palindromes({ maxFactor: 99, minFactor: 10 }) + xit 'largest palindrome from double digit factors', -> + palindromes = new PalindromeProducts({ maxFactor: 99, minFactor: 10 }) palindromes.generate() largest = palindromes.largest() expect(largest.value).toEqual(9009) expect(largest.factors).toEqual([[91, 99]]) - xit "smallest palindrome from double digit factors", -> - palindromes = new Palindromes({ maxFactor: 99, minFactor: 10 }) + xit 'smallest palindrome from double digit factors', -> + palindromes = new PalindromeProducts({ maxFactor: 99, minFactor: 10 }) palindromes.generate() smallest = palindromes.smallest() expect(smallest.value).toEqual(121) expect(smallest.factors).toEqual([[11, 11]]) - xit "largest palindrome from triple digit factors", -> - palindromes = new Palindromes({ maxFactor: 999, minFactor: 100 }) + xit 'largest palindrome from triple digit factors', -> + palindromes = new PalindromeProducts({ maxFactor: 999, minFactor: 100 }) palindromes.generate() largest = palindromes.largest() expect(largest.value).toEqual(906609) expect(largest.factors).toEqual([[913, 993]]) - xit "smallest palindrome from triple digit factors", -> - palindromes = new Palindromes({ maxFactor: 999, minFactor: 100 }) + xit 'smallest palindrome from triple digit factors', -> + palindromes = new PalindromeProducts({ maxFactor: 999, minFactor: 100 }) palindromes.generate() smallest = palindromes.smallest() expect(smallest.value).toEqual(10201) diff --git a/exercises/pascals-triangle/pascals-triangle.coffee b/exercises/pascals-triangle/pascals-triangle.coffee new file mode 100644 index 00000000..c59ec36d --- /dev/null +++ b/exercises/pascals-triangle/pascals-triangle.coffee @@ -0,0 +1,5 @@ +class PascalsTriangle + constructor: (args) -> + @array = + +module.exports = PascalsTriangle diff --git a/exercises/pascals-triangle/pascal-triangle-spec.coffee b/exercises/pascals-triangle/pascals-triangle.spec.coffee similarity index 72% rename from exercises/pascals-triangle/pascal-triangle-spec.coffee rename to exercises/pascals-triangle/pascals-triangle.spec.coffee index af441c13..4028a0fc 100644 --- a/exercises/pascals-triangle/pascal-triangle-spec.coffee +++ b/exercises/pascals-triangle/pascals-triangle.spec.coffee @@ -1,27 +1,26 @@ -Pascal = require './example.coffee' +Pascal = require './pascals-triangle' describe 'Pascal', -> it 'with one row', -> - arr = new Pascal(1) + arr = new PascalsTriangle(1) expect(arr.array).toEqual [[1]] xit 'with two rows', -> - arr = new Pascal(2) + arr = new PascalsTriangle(2) expect(arr.array).toEqual [[1], [1,1]] xit 'with three rows', -> - arr = new Pascal(3) + arr = new PascalsTriangle(3) expect(arr.array).toEqual [[1], [1,1], [1,2,1]] xit 'with four rows', -> - arr = new Pascal(4) + arr = new PascalsTriangle(4) expect(arr.array).toEqual [[1], [1,1], [1,2,1], [1,3,3,1]] xit 'with five rows', -> - arr = new Pascal(5) + arr = new PascalsTriangle(5) expect(arr.array).toEqual [[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] xit 'should equal 20th row', -> - arr = new Pascal(20) + arr = new PascalsTriangle(20) expect(arr.array[19]).toEqual [1, 19, 171, 969, 3876, 11628, 27132, 50388, 75582, 92378, 92378, 75582, 50388, 27132, 11628, 3876, 969, 171, 19, 1] - diff --git a/exercises/queen-attack/queen-attack.coffee b/exercises/queen-attack/queen-attack.coffee new file mode 100644 index 00000000..e0b55a07 --- /dev/null +++ b/exercises/queen-attack/queen-attack.coffee @@ -0,0 +1,6 @@ +class QueenAttack + constructor: (args) -> + @white = + @black = + +module.exports = QueenAttack diff --git a/exercises/queen-attack/queen-attack.spec.coffee b/exercises/queen-attack/queen-attack.spec.coffee new file mode 100644 index 00000000..3a891c1d --- /dev/null +++ b/exercises/queen-attack/queen-attack.spec.coffee @@ -0,0 +1,58 @@ +Queens = require './queen-attack' + +describe 'Queens', -> + it 'has the correct default positions', -> + queens = new QueenAttack + expect(queens.white).toEqual([0,3]) + expect(queens.black).toEqual([7,3]) + + xit 'initialized with specific placement', -> + queens = new QueenAttack({white: [3,7], black: [6,1] }) + expect(queens.white).toEqual([3, 7]) + expect(queens.black).toEqual([6, 1]) + + + xit 'cannot occupy the same space', -> + positioning = { white: [2,4], black: [2,4] } + expect(-> new QueenAttack(positioning)).toThrow('Queens cannot share the same space') + + + xit 'toString representation', -> + positioning = {white: [2, 4], black: [6, 6]} + queens = new QueenAttack(positioning) + board = '_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n' + + '_ _ W _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ B _\n_ _ _ _ _ _ _ _' + expect(queens.toString()).toEqual(board) + + xit 'queens cannot attack', -> + queens = new QueenAttack({ white: [2,3], black: [4,7] }) + expect(queens.canAttack()).toEqual(false) + + + xit 'queens can attack when they are on the same row', -> + queens = new QueenAttack({ white: [2,4], black: [2,7] }) + expect(queens.canAttack()).toEqual(true) + + + xit 'queens can attack when they are on the same column', -> + queens = new QueenAttack({ white: [5,4], black: [2,4] }) + expect(queens.canAttack()).toEqual(true) + + + xit 'queens can attack diagonally', -> + queens = new Queens({ white: [1, 1], black: [6, 6] }) + expect(queens.canAttack()).toEqual(true) + + + xit 'queens can attack another diagonally', -> + queens = new Queens({ white: [0, 6], black: [1, 7] }) + expect(queens.canAttack()).toEqual(true) + + + xit 'queens can attack yet another diagonally', -> + queens = new Queens({ white: [4, 1], black: [6, 3] }) + expect(queens.canAttack()).toEqual(true) + + xit 'queens can attack yet yet another diagonally', -> + queens = new Queens({ white: [6, 1], black: [1, 6] }) + expect(queens.canAttack()).toEqual(true) diff --git a/exercises/queen-attack/queen_attack_test.spec.coffee b/exercises/queen-attack/queen_attack_test.spec.coffee deleted file mode 100644 index 38ff743b..00000000 --- a/exercises/queen-attack/queen_attack_test.spec.coffee +++ /dev/null @@ -1,59 +0,0 @@ -Queens = require './queens' - -describe "Queens", -> - it "has the correct default positions", -> - queens = new Queens - expect(queens.white).toEqual([0,3]) - expect(queens.black).toEqual([7,3]) - - xit "initialized with specific placement", -> - queens = new Queens({white: [3,7], black: [6,1] }) - expect(queens.white).toEqual([3, 7]) - expect(queens.black).toEqual([6, 1]) - - - xit "cannot occupy the same space", -> - positioning = { white: [2,4], black: [2,4] } - expect(-> new Queens(positioning)).toThrow("Queens cannot share the same space") - - - xit "toString representation", -> - positioning = {white: [2, 4], black: [6, 6]} - queens = new Queens(positioning) - board = "_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ _ _\n" + - "_ _ W _ _ _ _ _\n_ _ _ _ _ _ _ _\n_ _ _ _ _ _ B _\n_ _ _ _ _ _ _ _" - expect(queens.toString()).toEqual(board) - - xit "queens cannot attack", -> - queens = new Queens({ white: [2,3], black: [4,7] }) - expect(queens.canAttack()).toEqual(false) - - - xit "queens can attack when they are on the same row", -> - queens = new Queens({ white: [2,4], black: [2,7] }) - expect(queens.canAttack()).toEqual(true) - - - xit "queens can attack when they are on the same column", -> - queens = new Queens({ white: [5,4], black: [2,4] }) - expect(queens.canAttack()).toEqual(true) - - - xit "queens can attack diagonally", -> - queens = new Queens({ white: [1, 1], black: [6, 6] }) - expect(queens.canAttack()).toEqual(true) - - - xit "queens can attack another diagonally", -> - queens = new Queens({ white: [0, 6], black: [1, 7] }) - expect(queens.canAttack()).toEqual(true) - - - xit "queens can attack yet another diagonally", -> - queens = new Queens({ white: [4, 1], black: [6, 3] }) - expect(queens.canAttack()).toEqual(true) - - xit "queens can attack yet yet another diagonally", -> - queens = new Queens({ white: [6, 1], black: [1, 6] }) - expect(queens.canAttack()).toEqual(true) - diff --git a/exercises/triangle/triangle.coffee b/exercises/triangle/triangle.coffee new file mode 100644 index 00000000..5816d817 --- /dev/null +++ b/exercises/triangle/triangle.coffee @@ -0,0 +1,6 @@ +class Triangle + constructor: (args) -> + + kind: -> + +module.exports = Triangle diff --git a/exercises/triangle/triangle_test.spec.coffee b/exercises/triangle/triangle.spec.coffee similarity index 82% rename from exercises/triangle/triangle_test.spec.coffee rename to exercises/triangle/triangle.spec.coffee index a36be19b..664691dd 100644 --- a/exercises/triangle/triangle_test.spec.coffee +++ b/exercises/triangle/triangle.spec.coffee @@ -1,6 +1,6 @@ Triangle = require './triangle' -describe "Triangle", -> +describe 'Triangle', -> it 'is equilateral with equal sides', -> triangle = new Triangle(2,2,2) expect(triangle.kind()).toBe 'equilateral' @@ -42,13 +42,13 @@ describe "Triangle", -> expect(triangle.kind()).toBe 'scalene' xit 'is illegal when a side is negative', -> - expect(-> new Triangle(2,3,-5)).toThrow("negative sides are illegal") + expect(-> new Triangle(2,3,-5)).toThrow('negative sides are illegal') xit 'is illegal when violating triangle inequality', -> - expect(-> new Triangle(1,1,3)).toThrow("violation of triangle inequality") + expect(-> new Triangle(1,1,3)).toThrow('violation of triangle inequality') xit 'is illegal when violating triangle inequality 2', -> - expect(-> new Triangle(2,2,5)).toThrow("violation of triangle inequality") + expect(-> new Triangle(2,2,5)).toThrow('violation of triangle inequality') xit 'is illegal when violating triangle inequality 3', -> - expect(-> new Triangle(7,3,2)).toThrow("violation of triangle inequality") + expect(-> new Triangle(7,3,2)).toThrow('violation of triangle inequality') diff --git a/exercises/trinary/trinary.coffee b/exercises/trinary/trinary.coffee new file mode 100644 index 00000000..a2039910 --- /dev/null +++ b/exercises/trinary/trinary.coffee @@ -0,0 +1,4 @@ +class Trinary + constructor: (args) -> + +module.exports = Trinary diff --git a/exercises/trinary/trinary_test.spec.coffee b/exercises/trinary/trinary.spec.coffee similarity index 100% rename from exercises/trinary/trinary_test.spec.coffee rename to exercises/trinary/trinary.spec.coffee diff --git a/exercises/word-count/word-count.coffee b/exercises/word-count/word-count.coffee new file mode 100644 index 00000000..ba5f1a47 --- /dev/null +++ b/exercises/word-count/word-count.coffee @@ -0,0 +1,7 @@ +class WordCount + constructor: (args) -> + + count: -> + + +module.exports = WordCount diff --git a/exercises/word-count/word-count.spec.coffee b/exercises/word-count/word-count.spec.coffee new file mode 100644 index 00000000..339f1ae9 --- /dev/null +++ b/exercises/word-count/word-count.spec.coffee @@ -0,0 +1,44 @@ +WordCount = require './word-count' + +describe 'WordCount', -> + it 'counts one word', -> + words = new WordCount 'word' + expect(words.count()).toEqual + word: 1 + + xit 'counts one of each', -> + words = new WordCount 'one of each' + expect(words.count()).toEqual + one: 1 + of: 1 + each: 1 + + xit 'counts multiple occurrences', -> + words = new WordCount 'one fish two fish red fish blue fish' + expect(words.count()).toEqual + one: 1 + fish: 4 + two: 1 + red: 1 + blue: 1 + + xit 'ignores punctuation', -> + words = new WordCount 'car : carpet as java : javascript!!&@$%^&' + expect(words.count()).toEqual + car: 1 + carpet: 1 + as: 1 + java: 1 + javascript: 1 + + xit 'includes numbers', -> + words = new WordCount 'testing, 1, 2 testing' + expect(words.count()).toEqual + testing: 2 + 1: 1 + 2: 1 + + xit 'normalizes case', -> + words = new WordCount 'go Go GO' + expect(words.count()).toEqual + go: 3 diff --git a/exercises/word-count/word-count_test.spec.coffee b/exercises/word-count/word-count_test.spec.coffee deleted file mode 100644 index 134ae701..00000000 --- a/exercises/word-count/word-count_test.spec.coffee +++ /dev/null @@ -1,44 +0,0 @@ -Words = require "./words" - -describe "Words", -> - it "counts one word", -> - words = new Words "word" - expect(words.count()).toEqual - word: 1 - - xit "counts one of each", -> - words = new Words "one of each" - expect(words.count()).toEqual - one: 1 - of: 1 - each: 1 - - xit "counts multiple occurrences", -> - words = new Words "one fish two fish red fish blue fish" - expect(words.count()).toEqual - one: 1 - fish: 4 - two: 1 - red: 1 - blue: 1 - - xit "ignores punctuation", -> - words = new Words "car : carpet as java : javascript!!&@$%^&" - expect(words.count()).toEqual - car: 1 - carpet: 1 - as: 1 - java: 1 - javascript: 1 - - xit "includes numbers", -> - words = new Words "testing, 1, 2 testing" - expect(words.count()).toEqual - testing: 2 - 1: 1 - 2: 1 - - xit "normalizes case", -> - words = new Words "go Go GO" - expect(words.count()).toEqual - go: 3 diff --git a/exercises/wordy/wordy.coffee b/exercises/wordy/wordy.coffee new file mode 100644 index 00000000..098a910e --- /dev/null +++ b/exercises/wordy/wordy.coffee @@ -0,0 +1,6 @@ +class Wordy + constructor: (args) -> + + answer: -> + +module.exports = Wordy diff --git a/exercises/wordy/wordy_test.spec.coffee b/exercises/wordy/wordy.spec.coffee similarity index 100% rename from exercises/wordy/wordy_test.spec.coffee rename to exercises/wordy/wordy.spec.coffee