Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
Move sorting (mostly) into Course
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Apr 5, 2014
1 parent aca9a08 commit d39bf97
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 45 deletions.
12 changes: 7 additions & 5 deletions lib/xapi/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def restore
private

def exercises
course.exercises.reject(&:not_found?).sort_by {|exercise|
[exercise.language, exercise.slug]
}
course.exercises.reject(&:not_found?)
end

def course
Expand All @@ -30,8 +28,12 @@ def data
end

def code
iterations.map {|iteration| Iteration.new(iteration)}.sort_by {|iteration|
[iteration.language, iteration.slug]
iterations.map {|iteration| Iteration.new(iteration)}.sort_by(&name)
end

def name
Proc.new {|exercise|
[exercise.language, exercise.slug]
}
end

Expand Down
10 changes: 9 additions & 1 deletion lib/xapi/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ def initialize(data)
end

def exercises
lessons.map(&:exercises).flatten
lessons.map(&:exercises).flatten.sort_by(&name)
end

def lessons
data.map {|language, slugs|
Lesson.new(language, data[language])
}
end

private

def name
Proc.new {|exercise|
[exercise.language, exercise.slug]
}
end
end
end
8 changes: 1 addition & 7 deletions lib/xapi/homework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def exercises_in(language)
end

def exercises
(current_exercises + upcoming_exercises).reject(&:not_found?).sort_by(&name)
(current_exercises + upcoming_exercises).reject(&:not_found?)
end

private
Expand All @@ -29,12 +29,6 @@ def upcoming_exercises
}
end

def name
Proc.new {|exercise|
[exercise.language, exercise.slug]
}
end

def data
@data ||= ExercismIO.exercises_for(key)
end
Expand Down
48 changes: 24 additions & 24 deletions test/fixtures/approvals/get_current_exercises.approved.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
{
"assignments": [
{
"track": "ruby",
"slug": "anagram",
"files": {
"anagram_test.rb": "require 'minitest/autorun'\nrequire_relative 'anagram'\n\nclass AnagramTest < MiniTest::Unit::TestCase\n\n def test_no_matches\n detector = Anagram.new('diaper')\n assert_equal [], detector.match(%w(hello world zombies pants))\n end\n\n def test_detect_simple_anagram\n skip\n detector = Anagram.new('ant')\n anagrams = detector.match(['tan', 'stand', 'at'])\n assert_equal ['tan'], anagrams\n end\n\n def test_detect_multiple_anagrams\n skip\n detector = Anagram.new('master')\n anagrams = detector.match(['stream', 'pigeon', 'maters'])\n assert_equal ['maters', 'stream'], anagrams.sort\n end\n\n def test_does_not_confuse_different_duplicates\n skip\n detector = Anagram.new('galea')\n assert_equal [], detector.match(['eagle'])\n end\n\n def test_identical_word_is_not_anagram\n skip\n detector = Anagram.new('corn')\n anagrams = detector.match %w(corn dark Corn rank CORN cron park)\n assert_equal ['cron'], anagrams\n end\n\n def test_eliminate_anagrams_with_same_checksum\n skip\n detector = Anagram.new('mass')\n assert_equal [], detector.match(['last'])\n end\n\n def test_eliminate_anagram_subsets\n skip\n detector = Anagram.new('good')\n assert_equal [], detector.match(['dog', 'goody'])\n end\n\n def test_detect_anagram\n skip\n detector = Anagram.new('listen')\n anagrams = detector.match %w(enlists google inlets banana)\n assert_equal ['inlets'], anagrams\n end\n\n def test_multiple_anagrams\n skip\n detector = Anagram.new('allergy')\n anagrams = detector.match %w(gallery ballerina regally clergy largely leading)\n assert_equal ['gallery', 'largely', 'regally'], anagrams.sort\n end\n\n def test_anagrams_are_case_insensitive\n skip\n detector = Anagram.new('Orchestra')\n anagrams = detector.match %w(cashregister Carthorse radishes)\n assert_equal ['Carthorse'], anagrams\n end\nend\n",
"README.md": "# Anagram\n\nWrite a program that, given a word and a list of possible anagrams, selects the correct sublist.\n\nGiven `\"listen\"` and a list of candidates like `\"enlists\" \"google\" \"inlets\" \"banana\"` the program should return a list containing `\"inlets\"`.\n\n\n## Source\n\nInspired by the Extreme Startup game [view source](https://github.com/rchatley/extreme_startup)\n"
},
"fresh": false,
"readme": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io",
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "ruby",
"slug": "word-count",
"files": {
"word_count_test.rb": "require 'minitest/autorun'\nrequire_relative 'phrase'\n\nclass PhraseTest < MiniTest::Unit::TestCase\n\n def test_count_one_word\n phrase = Phrase.new(\"word\")\n counts = {\"word\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_one_of_each\n skip\n phrase = Phrase.new(\"one of each\")\n counts = {\"one\" => 1, \"of\" => 1, \"each\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_multiple_occurrences\n skip\n phrase = Phrase.new(\"one fish two fish red fish blue fish\")\n counts = {\"one\" => 1, \"fish\" => 4, \"two\" => 1, \"red\" => 1, \"blue\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_everything_just_once\n skip\n phrase = Phrase.new(\"all the kings horses and all the kings men\")\n phrase.word_count # count it an extra time\n counts = {\n \"all\" => 2, \"the\" => 2, \"kings\" => 2, \"horses\" => 1, \"and\" => 1, \"men\" => 1\n }\n assert_equal counts, phrase.word_count\n end\n\n def test_ignore_punctuation\n skip\n phrase = Phrase.new(\"car : carpet as java : javascript!!&@$%^&\")\n counts = {\"car\" => 1, \"carpet\" => 1, \"as\" => 1, \"java\" => 1, \"javascript\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_handles_cramped_lists\n skip\n phrase = Phrase.new(\"one,two,three\")\n counts = {\"one\" => 1, \"two\" => 1, \"three\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_include_numbers\n skip\n phrase = Phrase.new(\"testing, 1, 2 testing\")\n counts = {\"testing\" => 2, \"1\" => 1, \"2\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_normalize_case\n skip\n phrase = Phrase.new(\"go Go GO\")\n counts = {\"go\" => 3}\n assert_equal counts, phrase.word_count\n end\n\n def test_with_apostrophes\n skip\n phrase = Phrase.new(\"First: don't laugh. Then: don't cry.\")\n counts = {\"first\"=>1, \"don't\"=>2, \"laugh\"=>1, \"then\"=>1, \"cry\"=>1}\n assert_equal counts, phrase.word_count\n end\nend\n",
"README.md": "# Word Count\n\nWrite a program that given a phrase can count the occurrences of each word in that phrase.\n\nFor example for the input `\"olly olly in come free\"`\n\n```plain\nolly: 2\nin: 1\ncome: 1\nfree: 1\n```\n\n\n\n## Source\n\nThe golang tour [view source](http://tour.golang.org)\n"
},
"fresh": false,
"readme": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io",
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "clojure",
"slug": "bob",
Expand Down Expand Up @@ -123,18 +147,6 @@
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "ruby",
"slug": "anagram",
"files": {
"anagram_test.rb": "require 'minitest/autorun'\nrequire_relative 'anagram'\n\nclass AnagramTest < MiniTest::Unit::TestCase\n\n def test_no_matches\n detector = Anagram.new('diaper')\n assert_equal [], detector.match(%w(hello world zombies pants))\n end\n\n def test_detect_simple_anagram\n skip\n detector = Anagram.new('ant')\n anagrams = detector.match(['tan', 'stand', 'at'])\n assert_equal ['tan'], anagrams\n end\n\n def test_detect_multiple_anagrams\n skip\n detector = Anagram.new('master')\n anagrams = detector.match(['stream', 'pigeon', 'maters'])\n assert_equal ['maters', 'stream'], anagrams.sort\n end\n\n def test_does_not_confuse_different_duplicates\n skip\n detector = Anagram.new('galea')\n assert_equal [], detector.match(['eagle'])\n end\n\n def test_identical_word_is_not_anagram\n skip\n detector = Anagram.new('corn')\n anagrams = detector.match %w(corn dark Corn rank CORN cron park)\n assert_equal ['cron'], anagrams\n end\n\n def test_eliminate_anagrams_with_same_checksum\n skip\n detector = Anagram.new('mass')\n assert_equal [], detector.match(['last'])\n end\n\n def test_eliminate_anagram_subsets\n skip\n detector = Anagram.new('good')\n assert_equal [], detector.match(['dog', 'goody'])\n end\n\n def test_detect_anagram\n skip\n detector = Anagram.new('listen')\n anagrams = detector.match %w(enlists google inlets banana)\n assert_equal ['inlets'], anagrams\n end\n\n def test_multiple_anagrams\n skip\n detector = Anagram.new('allergy')\n anagrams = detector.match %w(gallery ballerina regally clergy largely leading)\n assert_equal ['gallery', 'largely', 'regally'], anagrams.sort\n end\n\n def test_anagrams_are_case_insensitive\n skip\n detector = Anagram.new('Orchestra')\n anagrams = detector.match %w(cashregister Carthorse radishes)\n assert_equal ['Carthorse'], anagrams\n end\nend\n",
"README.md": "# Anagram\n\nWrite a program that, given a word and a list of possible anagrams, selects the correct sublist.\n\nGiven `\"listen\"` and a list of candidates like `\"enlists\" \"google\" \"inlets\" \"banana\"` the program should return a list containing `\"inlets\"`.\n\n\n## Source\n\nInspired by the Extreme Startup game [view source](https://github.com/rchatley/extreme_startup)\n"
},
"fresh": false,
"readme": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io",
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "ruby",
"slug": "bob",
Expand All @@ -147,18 +159,6 @@
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "ruby",
"slug": "word-count",
"files": {
"word_count_test.rb": "require 'minitest/autorun'\nrequire_relative 'phrase'\n\nclass PhraseTest < MiniTest::Unit::TestCase\n\n def test_count_one_word\n phrase = Phrase.new(\"word\")\n counts = {\"word\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_one_of_each\n skip\n phrase = Phrase.new(\"one of each\")\n counts = {\"one\" => 1, \"of\" => 1, \"each\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_multiple_occurrences\n skip\n phrase = Phrase.new(\"one fish two fish red fish blue fish\")\n counts = {\"one\" => 1, \"fish\" => 4, \"two\" => 1, \"red\" => 1, \"blue\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_count_everything_just_once\n skip\n phrase = Phrase.new(\"all the kings horses and all the kings men\")\n phrase.word_count # count it an extra time\n counts = {\n \"all\" => 2, \"the\" => 2, \"kings\" => 2, \"horses\" => 1, \"and\" => 1, \"men\" => 1\n }\n assert_equal counts, phrase.word_count\n end\n\n def test_ignore_punctuation\n skip\n phrase = Phrase.new(\"car : carpet as java : javascript!!&@$%^&\")\n counts = {\"car\" => 1, \"carpet\" => 1, \"as\" => 1, \"java\" => 1, \"javascript\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_handles_cramped_lists\n skip\n phrase = Phrase.new(\"one,two,three\")\n counts = {\"one\" => 1, \"two\" => 1, \"three\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_include_numbers\n skip\n phrase = Phrase.new(\"testing, 1, 2 testing\")\n counts = {\"testing\" => 2, \"1\" => 1, \"2\" => 1}\n assert_equal counts, phrase.word_count\n end\n\n def test_normalize_case\n skip\n phrase = Phrase.new(\"go Go GO\")\n counts = {\"go\" => 3}\n assert_equal counts, phrase.word_count\n end\n\n def test_with_apostrophes\n skip\n phrase = Phrase.new(\"First: don't laugh. Then: don't cry.\")\n counts = {\"first\"=>1, \"don't\"=>2, \"laugh\"=>1, \"then\"=>1, \"cry\"=>1}\n assert_equal counts, phrase.word_count\n end\nend\n",
"README.md": "# Word Count\n\nWrite a program that given a phrase can count the occurrences of each word in that phrase.\n\nFor example for the input `\"olly olly in come free\"`\n\n```plain\nolly: 2\nin: 1\ncome: 1\nfree: 1\n```\n\n\n\n## Source\n\nThe golang tour [view source](http://tour.golang.org)\n"
},
"fresh": false,
"readme": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io",
"test_file": "PLEASE_UPGRADE.txt",
"tests": "Please upgrade to the latest version of the exercism command-line client. See: http://cli.exercism.io"
},
{
"track": "scala",
"slug": "bob",
Expand Down

0 comments on commit d39bf97

Please sign in to comment.