Skip to content
Open
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
16 changes: 16 additions & 0 deletions exercises/practice/connect/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'minitest/autorun'
require_relative 'connect'

class ConnectTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
expected = '<%= cases["expected"] %>'
board = [
'<%= cases["input"]["board"].join("', \n'") %>'
].map { |row| row.gsub(/^ */, '') }
actual = Board.new(board).winner
assert_equal expected, actual, '<%= cases["description"] %>'
end
<% end %>
end
50 changes: 30 additions & 20 deletions exercises/practice/connect/connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,124 @@
class ConnectTest < Minitest::Test
def test_an_empty_board_has_no_winner
# skip
expected = ''
board = [
'. . . . .',
' . . . . .',
' . . . . .',
' . . . . .',
' . . . . .'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal '', game.winner, 'an empty board has no winner'
actual = Board.new(board).winner
assert_equal expected, actual, 'an empty board has no winner'
end

def test_x_can_win_on_a_1x1_board
skip
expected = 'X'
board = [
'X'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'X', game.winner, 'X can win on a 1x1 board'
actual = Board.new(board).winner
assert_equal expected, actual, 'X can win on a 1x1 board'
end

def test_o_can_win_on_a_1x1_board
skip
expected = 'O'
board = [
'O'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'O', game.winner, 'O can win on a 1x1 board'
actual = Board.new(board).winner
assert_equal expected, actual, 'O can win on a 1x1 board'
end

def test_only_edges_does_not_make_a_winner
skip
expected = ''
board = [
'O O O X',
' X . . X',
' X . . X',
' X O O O'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal '', game.winner, 'only edges does not make a winner'
actual = Board.new(board).winner
assert_equal expected, actual, 'only edges does not make a winner'
end

def test_illegal_diagonal_does_not_make_a_winner
skip
expected = ''
board = [
'X O . .',
' O X X X',
' O X O .',
' . O X .',
' X X O O'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal '', game.winner, 'illegal diagonal does not make a winner'
actual = Board.new(board).winner
assert_equal expected, actual, 'illegal diagonal does not make a winner'
end

def test_nobody_wins_crossing_adjacent_angles
skip
expected = ''
board = [
'X . . .',
' . X O .',
' O . X O',
' . O . X',
' . . O .'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal '', game.winner, 'nobody wins crossing adjacent angles'
actual = Board.new(board).winner
assert_equal expected, actual, 'nobody wins crossing adjacent angles'
end

def test_x_wins_crossing_from_left_to_right
skip
expected = 'X'
board = [
'. O . .',
' O X X X',
' O X O .',
' X X O X',
' . O X .'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'X', game.winner, 'X wins crossing from left to right'
actual = Board.new(board).winner
assert_equal expected, actual, 'X wins crossing from left to right'
end

def test_o_wins_crossing_from_top_to_bottom
skip
expected = 'O'
board = [
'. O . .',
' O X X X',
' O O O .',
' X X O X',
' . O X .'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'O', game.winner, 'O wins crossing from top to bottom'
actual = Board.new(board).winner
assert_equal expected, actual, 'O wins crossing from top to bottom'
end

def test_x_wins_using_a_convoluted_path
skip
expected = 'X'
board = [
'. X X . .',
' X . X . X',
' . X . X .',
' . X X . .',
' O O O O O'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'X', game.winner, 'X wins using a convoluted path'
actual = Board.new(board).winner
assert_equal expected, actual, 'X wins using a convoluted path'
end

def test_x_wins_using_a_spiral_path
skip
expected = 'X'
board = [
'O X X X X X X X X',
' O X O O O O O O O',
Expand All @@ -123,7 +133,7 @@ def test_x_wins_using_a_spiral_path
' O O O O O O O X O',
' X X X X X X X X O'
].map { |row| row.gsub(/^ */, '') }
game = Board.new(board)
assert_equal 'X', game.winner, 'X wins using a spiral path'
actual = Board.new(board).winner
assert_equal expected, actual, 'X wins using a spiral path'
end
end
19 changes: 19 additions & 0 deletions exercises/practice/nucleotide-count/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'minitest/autorun'
require_relative 'nucleotide_count'

class NucleotideTest < 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
Nucleotide.from_dna('<%= cases["input"]["strand"] %>')
end
<%- else -%>
expected = <%= cases["expected"] %>
actual = Nucleotide.from_dna('<%= cases["input"]["strand"] %>').histogram
assert_equal expected, actual
<%- end -%>
end
<% end %>
end
52 changes: 19 additions & 33 deletions exercises/practice/nucleotide-count/nucleotide_count_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,38 @@
require_relative 'nucleotide_count'

class NucleotideTest < Minitest::Test
def test_empty_dna_strand_has_no_adenosine
assert_equal 0, Nucleotide.from_dna('').count('A')
def test_empty_strand
# skip
expected = { "A" => 0, "C" => 0, "G" => 0, "T" => 0 }
actual = Nucleotide.from_dna('').histogram
assert_equal expected, actual
end

def test_repetitive_cytidine_gets_counted
def test_can_count_one_nucleotide_in_single_character_input
skip
assert_equal 5, Nucleotide.from_dna('CCCCC').count('C')
expected = { "A" => 0, "C" => 0, "G" => 1, "T" => 0 }
actual = Nucleotide.from_dna('G').histogram
assert_equal expected, actual
end

def test_counts_only_thymidine
def test_strand_with_repeated_nucleotide
skip
assert_equal 1, Nucleotide.from_dna('GGGGGTAACCCGG').count('T')
expected = { "A" => 0, "C" => 0, "G" => 7, "T" => 0 }
actual = Nucleotide.from_dna('GGGGGGG').histogram
assert_equal expected, actual
end

def test_counts_a_nucleotide_only_once
def test_strand_with_multiple_nucleotides
skip
dna = Nucleotide.from_dna('CGATTGGG')
dna.count('T')
dna.count('T')
assert_equal 2, dna.count('T')
expected = { "A" => 20, "C" => 12, "G" => 17, "T" => 21 }
actual = Nucleotide.from_dna('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC').histogram
assert_equal expected, actual
end

def test_empty_dna_strand_has_no_nucleotides
skip
expected = { 'A' => 0, 'T' => 0, 'C' => 0, 'G' => 0 }
assert_equal expected, Nucleotide.from_dna('').histogram
end

def test_repetitive_sequence_has_only_guanosine
skip
expected = { 'A' => 0, 'T' => 0, 'C' => 0, 'G' => 8 }
assert_equal expected, Nucleotide.from_dna('GGGGGGGG').histogram
end

def test_counts_all_nucleotides
skip
s = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
dna = Nucleotide.from_dna(s)
expected = { 'A' => 20, 'T' => 21, 'G' => 17, 'C' => 12 }
assert_equal expected, dna.histogram
end

def test_validates_dna
def test_strand_with_invalid_nucleotides
skip
assert_raises ArgumentError do
Nucleotide.from_dna('JOHNNYAPPLESEED')
Nucleotide.from_dna('AGXXACT')
end
end
end
20 changes: 20 additions & 0 deletions exercises/practice/ocr-numbers/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'minitest/autorun'
require_relative 'ocr_numbers'

class OcrNumbersTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
input = ['<%= cases["input"]["rows"].join("', \n'") %>'].join("\n")
<%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%>
assert_raises(ArgumentError) do
OcrNumbers.convert(input)
end
<%- else -%>
expected = '<%= cases["expected"] %>'
actual = OcrNumbers.convert(input)
assert_equal expected, actual
<%- end -%>
end
<% end %>
end
Loading