Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions exercises/practice/grade-school/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'minitest/autorun'
require_relative 'grade_school'

class GradeSchoolTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
school = School.new
<%- if cases["property"] == "roster" -%>
<%- cases["input"]["students"].each do |student| -%>
school.add('<%= student[0] %>', <%= student[1] %>)
<%- end -%>
assert_equal <%= cases["expected"] %>, school.roster
<%- elsif cases["property"] == "add" -%>
results = []
<%- cases["input"]["students"].each do |student| -%>
results << school.add('<%= student[0] %>', <%= student[1] %>)
<%- end -%>
assert_equal <%= cases["expected"] %>, results
<%- elsif cases["property"] == "grade" -%>
<%- cases["input"]["students"].each do |student| -%>
school.add('<%= student[0] %>', <%= student[1] %>)
<%- end -%>
assert_equal <%= cases["expected"] %>, school.grade(<%= cases["input"]["desiredGrade"] %>)
<%- end -%>
end
<% end %>
end
124 changes: 62 additions & 62 deletions exercises/practice/grade-school/grade_school_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,185 +5,185 @@ class GradeSchoolTest < Minitest::Test
def test_roster_is_empty_when_no_student_is_added
# skip
school = School.new
assert_empty [], school.roster
assert_empty school.roster
end

def test_add_a_student
skip
school = School.new
results = []
results << school.add("Aimee", 2)
results << school.add('Aimee', 2)
assert_equal [true], results
end

def test_student_is_added_to_the_roster
skip
school = School.new
school.add("Aimee", 2)
school.add('Aimee', 2)
assert_equal ["Aimee"], school.roster
end

def test_adding_multiple_students_in_the_same_grade_in_the_roster
skip
school = School.new
results = []
results << school.add("Blair", 2)
results << school.add("James", 2)
results << school.add("Paul", 2)
results << school.add('Blair', 2)
results << school.add('James', 2)
results << school.add('Paul', 2)
assert_equal [true, true, true], results
end

def test_multiple_students_in_the_same_grade_are_added_to_the_roster
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("Paul", 2)
school.add('Blair', 2)
school.add('James', 2)
school.add('Paul', 2)
assert_equal %w[Blair James Paul], school.roster
end

def test_cannot_add_student_to_same_grade_in_the_roster_more_than_once
skip
school = School.new
results = []
results << school.add("Blair", 2)
results << school.add("James", 2)
results << school.add("James", 2)
results << school.add("Paul", 2)
results << school.add('Blair', 2)
results << school.add('James', 2)
results << school.add('James', 2)
results << school.add('Paul', 2)
assert_equal [true, true, false, true], results
end

def test_student_not_added_to_same_grade_in_the_roster_more_than_once
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("James", 2)
school.add("Paul", 2)
school.add('Blair', 2)
school.add('James', 2)
school.add('James', 2)
school.add('Paul', 2)
assert_equal %w[Blair James Paul], school.roster
end

def test_adding_students_in_multiple_grades
skip
school = School.new
results = []
results << school.add("Chelsea", 3)
results << school.add("Logan", 7)
results << school.add('Chelsea', 3)
results << school.add('Logan', 7)
assert_equal [true, true], results
end

def test_students_in_multiple_grades_are_added_to_the_roster
skip
school = School.new
school.add("Chelsea", 3)
school.add("Logan", 7)
school.add('Chelsea', 3)
school.add('Logan', 7)
assert_equal %w[Chelsea Logan], school.roster
end

def test_cannot_add_same_student_to_multiple_grades_in_the_roster
skip
school = School.new
results = []
results << school.add("Blair", 2)
results << school.add("James", 2)
results << school.add("James", 3)
results << school.add("Paul", 3)
results << school.add('Blair', 2)
results << school.add('James', 2)
results << school.add('James', 3)
results << school.add('Paul', 3)
assert_equal [true, true, false, true], results
end

def test_student_not_added_to_multiple_grades_in_the_roster
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("James", 3)
school.add("Paul", 3)
school.add('Blair', 2)
school.add('James', 2)
school.add('James', 3)
school.add('Paul', 3)
assert_equal %w[Blair James Paul], school.roster
end

def test_students_are_sorted_by_grades_in_the_roster
skip
school = School.new
school.add("Jim", 3)
school.add("Peter", 2)
school.add("Anna", 1)
school.add('Jim', 3)
school.add('Peter', 2)
school.add('Anna', 1)
assert_equal %w[Anna Peter Jim], school.roster
end

def test_students_are_sorted_by_name_in_the_roster
skip
school = School.new
school.add("Peter", 2)
school.add("Zoe", 2)
school.add("Alex", 2)
school.add('Peter', 2)
school.add('Zoe', 2)
school.add('Alex', 2)
assert_equal %w[Alex Peter Zoe], school.roster
end

def test_students_are_sorted_by_grades_and_then_by_name_in_the_roster
skip
school = School.new
school.add("Peter", 2)
school.add("Anna", 1)
school.add("Barb", 1)
school.add("Zoe", 2)
school.add("Alex", 2)
school.add("Jim", 3)
school.add("Charlie", 1)
school.add('Peter', 2)
school.add('Anna', 1)
school.add('Barb', 1)
school.add('Zoe', 2)
school.add('Alex', 2)
school.add('Jim', 3)
school.add('Charlie', 1)
assert_equal %w[Anna Barb Charlie Alex Peter Zoe Jim], school.roster
end

def test_grade_is_empty_if_no_students_in_the_roster
skip
school = School.new
assert_empty [], school.grade(1)
assert_empty school.grade(1)
end

def test_grade_is_empty_if_no_students_in_that_grade
skip
school = School.new
school.add("Peter", 2)
school.add("Zoe", 2)
school.add("Alex", 2)
school.add("Jim", 3)
school.add('Peter', 2)
school.add('Zoe', 2)
school.add('Alex', 2)
school.add('Jim', 3)
assert_empty school.grade(1)
end

def test_student_not_added_to_same_grade_more_than_once
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("James", 2)
school.add("Paul", 2)
school.add('Blair', 2)
school.add('James', 2)
school.add('James', 2)
school.add('Paul', 2)
assert_equal %w[Blair James Paul], school.grade(2)
end

def test_student_not_added_to_multiple_grades
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("James", 3)
school.add("Paul", 3)
school.add('Blair', 2)
school.add('James', 2)
school.add('James', 3)
school.add('Paul', 3)
assert_equal %w[Blair James], school.grade(2)
end

def test_student_not_added_to_other_grade_for_multiple_grades
skip
school = School.new
school.add("Blair", 2)
school.add("James", 2)
school.add("James", 3)
school.add("Paul", 3)
school.add('Blair', 2)
school.add('James', 2)
school.add('James', 3)
school.add('Paul', 3)
assert_equal ["Paul"], school.grade(3)
end

def test_students_are_sorted_by_name_in_a_grade
skip
school = School.new
school.add("Franklin", 5)
school.add("Bradley", 5)
school.add("Jeff", 1)
school.add('Franklin', 5)
school.add('Bradley', 5)
school.add('Jeff', 1)
assert_equal %w[Bradley Franklin], school.grade(5)
end
end
17 changes: 17 additions & 0 deletions exercises/practice/hamming/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'minitest/autorun'
require_relative 'hamming'

class HammingTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
<%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%>
assert_raises(ArgumentError) do
Hamming.compute('<%= cases["input"]["strand1"] %>', '<%= cases["input"]["strand2"] %>')
end
<%- else -%>
assert_equal <%= cases["expected"] %>, Hamming.compute('<%= cases["input"]["strand1"] %>', '<%= cases["input"]["strand2"] %>')
<%- end -%>
end
<% end %>
end
18 changes: 9 additions & 9 deletions exercises/practice/hamming/hamming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,54 @@
class HammingTest < Minitest::Test
def test_empty_strands
# skip
assert_equal 0, Hamming.compute("", "")
assert_equal 0, Hamming.compute('', '')
end

def test_single_letter_identical_strands
skip
assert_equal 0, Hamming.compute("A", "A")
assert_equal 0, Hamming.compute('A', 'A')
end

def test_single_letter_different_strands
skip
assert_equal 1, Hamming.compute("G", "T")
assert_equal 1, Hamming.compute('G', 'T')
end

def test_long_identical_strands
skip
assert_equal 0, Hamming.compute("GGACTGAAATCTG", "GGACTGAAATCTG")
assert_equal 0, Hamming.compute('GGACTGAAATCTG', 'GGACTGAAATCTG')
end

def test_long_different_strands
skip
assert_equal 9, Hamming.compute("GGACGGATTCTG", "AGGACGGATTCT")
assert_equal 9, Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT')
end

def test_disallow_first_strand_longer
skip
assert_raises(ArgumentError) do
Hamming.compute("AATG", "AAA")
Hamming.compute('AATG', 'AAA')
end
end

def test_disallow_second_strand_longer
skip
assert_raises(ArgumentError) do
Hamming.compute("ATA", "AGTG")
Hamming.compute('ATA', 'AGTG')
end
end

def test_disallow_empty_first_strand
skip
assert_raises(ArgumentError) do
Hamming.compute("", "G")
Hamming.compute('', 'G')
end
end

def test_disallow_empty_second_strand
skip
assert_raises(ArgumentError) do
Hamming.compute("G", "")
Hamming.compute('G', '')
end
end
end
11 changes: 5 additions & 6 deletions exercises/practice/house/.meta/example.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
class House
def self.recite
new.recite
def self.recite(start_verse, end_verse)
new.recite(start_verse, end_verse)
end

def recite
(1..pieces.length).map { |i| line(i) }.join("\n")
def recite(start_verse, end_verse)
(start_verse..end_verse).map { |i| line(i) }.join
end

def line(i)
"This is %s.\n" % pieces.last(i).map { |s| s.join("\n") }.join(' ')
"This is %s.\n" % pieces.last(i).join(' ')
end

private

def pieces
[
['the horse and the hound and the horn', 'that belonged to'],
Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/house/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'minitest/autorun'
require_relative 'house'

class HouseTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
expected = <<~RHYME
<%= cases["expected"].join("\n") %>
RHYME
assert_equal expected, House.recite(<%= cases["input"]["startVerse"] %>, <%= cases["input"]["endVerse"] %>)
end
<% end %>
end
Loading