Skip to content

Commit

Permalink
Create api endpoint to fetch current assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Jun 10, 2013
1 parent 121b51d commit 655e759
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ ruby "1.9.3"
gem 'mongoid'
gem 'sinatra', require: 'sinatra/base'
gem 'puma'

group :test, :development do
gem 'approvals'
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ GEM
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
approvals (0.0.7)
nokogiri
thor
builder (3.0.4)
i18n (0.6.1)
mongoid (3.1.4)
Expand All @@ -16,6 +19,7 @@ GEM
tzinfo (~> 0.3.22)
moped (1.5.0)
multi_json (1.7.5)
nokogiri (1.5.9)
origin (1.1.0)
puma (2.0.1)
rack (>= 1.1, < 2.0)
Expand All @@ -26,13 +30,15 @@ GEM
rack (~> 1.5, >= 1.5.2)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
thor (0.18.1)
tilt (1.4.1)
tzinfo (0.3.37)

PLATFORMS
ruby

DEPENDENCIES
approvals
mongoid
puma
sinatra
4 changes: 4 additions & 0 deletions assignments/javascript/anagram/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
blurb: "Write a program that, given a word and a list of possible anagrams, selects the correct one(s)."
source: "Inspired by the Extreme Startup game"
source_url: "https://github.com/rchatley/extreme_startup"
1 change: 1 addition & 0 deletions assignments/javascript/anagram/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In other words, given: `"listen"` and `%w(enlists google inlets banana)` the program should return "inlets".
30 changes: 30 additions & 0 deletions assignments/javascript/anagram/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Anagram = function Anagram(word) {
this.word = word;
};

Anagram.prototype = {
match: function(words) {
var matches = [];

for(var i = 0; i < words.length; i++) {
var currentWord = words[i];

if (currentWord.length == this.word.length) {
var currentWordLetters = currentWord.split('').sort();
var matchingWordLetters = this.word.split('').sort();

var isMatch = true;

for (var j = 0; j < currentWordLetters.length; j++) {
if (currentWordLetters[j] != matchingWordLetters[j]) {
isMatch = false;
}
}

if (isMatch) { matches.push(currentWord); }
}

}
return matches;
}
};
34 changes: 34 additions & 0 deletions assignments/javascript/anagram/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('./anagram');

describe('Anagram', function() {

it("no matches",function() {
var detector = new Anagram("diaper");
var matches = detector.match([ "hello", "world", "zombies", "pants"]);
expect(matches).toEqual([]);
});

it("detects simple anagram",function() {
var detector = new Anagram("ba");
var matches = detector.match(['ab', 'abc', 'bac']);
expect(matches).toEqual(['ab']);
});

it("detects multiple anagrams",function() {
var detector = new Anagram("abc");
var matches = detector.match(['ab', 'abc', 'bac']);
expect(matches).toEqual(['abc', 'bac']);
});

it("detects anagram",function() {
var detector = new Anagram("listen");
var matches = detector.match(['enlists', 'google', 'inlets', 'banana']);
expect(matches).toEqual(['inlets']);
});

it("detects multiple anagrams",function() {
var detector = new Anagram("allergy");
var matches = detector.match(['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading']);
expect(matches).toEqual(['gallery', 'regally', 'largely']);
});
});
4 changes: 4 additions & 0 deletions assignments/ruby/anagram/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
blurb: "Write a program that, given a word and a list of possible anagrams, selects the correct one(s)."
source: "Inspired by the Extreme Startup game"
source_url: "https://github.com/rchatley/extreme_startup"
1 change: 1 addition & 0 deletions assignments/ruby/anagram/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Given `"listen"` and `%w(enlists google inlets banana)` the program should return "inlets".
21 changes: 21 additions & 0 deletions assignments/ruby/anagram/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Anagram

attr_reader :subject, :letters
def initialize(subject)
@subject = subject
@letters = decompose subject
end

def match(words)
words.select do |word|
decompose(word) == letters
end
end

private

def decompose(s)
s.chars.sort
end
end

39 changes: 39 additions & 0 deletions assignments/ruby/anagram/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'anagram'

class AnagramTest < MiniTest::Unit::TestCase

def test_no_matches
skip
detector = Anagram.new('diaper')
assert_equal [], detector.match(%w(hello world zombies pants))
end

def test_detect_simple_anagram
detector = Anagram.new('ba')
anagrams = detector.match(['ab', 'abc', 'bac'])
assert_equal ['ab'], anagrams
end

def test_detect_multiple_anagrams
detector = Anagram.new('abc')
anagrams = detector.match(['ab', 'abc', 'bac'])
assert_equal ['abc', 'bac'], anagrams
end

def test_detect_anagram
skip
detector = Anagram.new('listen')
anagrams = detector.match %w(enlists google inlets banana)
assert_equal ['inlets'], anagrams
end

def test_multiple_anagrams
skip
detector = Anagram.new('allergy')
anagrams = detector.match %w(gallery ballerina regally clergy largely leading)
assert_equal ['gallery', 'regally', 'largely'], anagrams
end
end

4 changes: 4 additions & 0 deletions assignments/ruby/bob/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
blurb: "Bob is a lackadaisical teenager. In conversation, his responses are very limited."
source: "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial."
source_url: "http://pine.fm/LearnToProgram/?Chapter=06"
16 changes: 16 additions & 0 deletions assignments/ruby/bob/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Bob answers 'Sure.' if you ask him a question.

He answers 'Whatever.' if you tell him something.

He answers 'Woah, chill out!' if you yell at him (ALL CAPS).

He says 'Fine. Be that way!' if you address him without actually saying anything.

Bob, Inspired by the 90s, is bringing back "l33t sP34k", and he'll teach you how to do it. Start any sentence with "Bro, ", and he'll translate the rest of it into l33t sP34k for you.

## Hints

`gets`, _get string_ is the opposite of `puts` _put string_.

Notice that when you type "Something" and then hit enter, you get the string
`"Something\n"`
29 changes: 29 additions & 0 deletions assignments/ruby/bob/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Bob

def hey(something)
if silent?(something)
'Fine, be that way.'
elsif question?(something)
'Sure.'
elsif shouting?(something)
'Woah, chill out!'
else
'Whatever.'
end
end

private

def question?(s)
s.end_with?('?')
end

def silent?(s)
s.empty?
end

def shouting?(s)
s.upcase == s
end

end
46 changes: 46 additions & 0 deletions assignments/ruby/bob/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'bob'

class BobTest < MiniTest::Unit::TestCase
attr_reader :bob

def setup
@bob = Bob.new
end

def test_stating_something
assert_equal 'Whatever.', bob.hey('Tom-ay-to, tom-aaaah-to.')
end

def test_shouting
skip
assert_equal 'Woah, chill out!', bob.hey('WATCH OUT!')
end

def test_asking_a_question
skip
assert_equal 'Sure.', bob.hey('Does this cryogenic chamber make me look fat?')
end

def test_talking_forcefully
skip
assert_equal 'Whatever.', bob.hey("Let's go make out behind the gym!")
end

def test_shouting_numbers
skip
assert_equal 'Woah, chill out!', bob.hey('1, 2, 3 GO!')
end

def test_shouting_with_special_characters
skip
assert_equal 'Woah, chill out!', bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!')
end

def test_silence
skip
assert_equal 'Fine, be that way.', bob.hey('')
end

end
2 changes: 2 additions & 0 deletions assignments/ruby/word-count/blurb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Write a program that given a string can count the occurrences of each word in that string.

5 changes: 5 additions & 0 deletions assignments/ruby/word-count/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
blurb: "Write a program that given a string can count the occurrences of each word in that string."
source: "The golang tour"
source_url: "http://tour.golang.org"

8 changes: 8 additions & 0 deletions assignments/ruby/word-count/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

```ruby
words = Words.new("olly olly in come free")
words.count
# => {"olly" => 2, "in" => 1, "come" => 1, "free" => 1}
```


15 changes: 15 additions & 0 deletions assignments/ruby/word-count/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Words

attr_reader :text
def initialize(text)
@text = text.downcase.gsub(/[^a-z0-9\s]/, '')
end

def count
data = Hash.new(0)
text.split(" ").each do |word|
data[word] += 1
end
data
end
end
49 changes: 49 additions & 0 deletions assignments/ruby/word-count/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'words'

class WordsTest < MiniTest::Unit::TestCase

def test_count_one_word
words = Words.new("word")
counts = {"word" => 1}
assert_equal counts, words.count
end

def test_count_one_of_each
skip
words = Words.new("one of each")
counts = {"one" => 1, "of" => 1, "each" => 1}
assert_equal counts, words.count
end

def test_count_multiple_occurrences
skip
words = Words.new("one fish two fish red fish blue fish")
counts = {"one"=>1, "fish"=>4, "two"=>1, "red"=>1, "blue"=>1}
assert_equal counts, words.count
end

def test_ignore_punctuation
skip
words = Words.new("car : carpet as java : javascript!!&@$%^&")
counts = {"car"=>1, "carpet"=>1, "as"=>1, "java"=>1, "javascript"=>1}
assert_equal counts, words.count
end

def test_include_numbers
skip
words = Words.new("testing, 1, 2 testing")
counts = {"testing" => 2, "1" => 1, "2" => 1}
assert_equal counts, words.count
end

def test_normalize_case
skip
words = Words.new("go Go GO")
counts = {"go" => 3}
assert_equal counts, words.count
end

end

1 change: 1 addition & 0 deletions lib/app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'app/client'
require 'app/api'

class ExercismApp < Sinatra::Base
set :root, 'lib/app'
Expand Down
Loading

0 comments on commit 655e759

Please sign in to comment.