Skip to content

Instantly share code, notes, and snippets.

@hectorhuertas
Created October 27, 2015 18:01
Show Gist options
  • Save hectorhuertas/5672f6655d921c30ac8c to your computer and use it in GitHub Desktop.
Save hectorhuertas/5672f6655d921c30ac8c to your computer and use it in GitHub Desktop.
require 'minitest'
require_relative 'character_counter'
class CharCounterTest < Minitest::Test
def test_class_exists
assert CharCounter
end
def test_initializes_without_input
assert CharCounter.new
end
def test_initializes_with_string_input
assert CharCounter.new("hello")
end
def test_can_access_string_input
char_counter = CharCounter.new("hello")
assert_equal "hello", char_counter.string
end
def test_without_input_input_is_nil
char_counter = CharCounter.new
refute char_counter.string
end
def test_initializes_with_result
char_counter = CharCounter.new
assert char_counter.result
end
def test_result_initializes_as_empty_hash
char_counter = CharCounter.new
assert_equal({}, char_counter.result)
end
def test_letter_count_method_exists
char_counter = CharCounter.new
assert char_counter.respond_to?(:letter_count)
end
def test_counts_single_letter
char_counter = CharCounter.new("a")
char_counter.letter_count
expected = {'a' => 1}
assert_equal expected, char_counter.result
end
def test_counts_a_second_single_letter
char_counter = CharCounter.new("b")
char_counter.letter_count
expected = {'b' => 1}
assert_equal expected, char_counter.result
end
def test_counts_pair_of_identical_letters
char_counter = CharCounter.new("aa")
char_counter.letter_count
expected = {'a' => 2}
assert_equal expected, char_counter.result
end
def test_counts_pair_of_distinct_letter
char_counter = CharCounter.new("ab")
char_counter.letter_count
expected = {'a' => 1, 'b' => 1}
assert_equal expected, char_counter.result
end
def test_can_count_letters_in_string
char_counter = CharCounter.new("hello")
char_counter.letter_count
expected = {'h'=> 1, 'e' => 1, 'l' => 2, 'o' => 1}
computed = char_counter.result
assert_equal expected, computed
end
def test_it_outputs_letter_count_in_correct_format
char_counter = CharCounter.new("hello")
char_counter.letter_count
expected = " h: 1\n e: 1\n l: 2\n o: 1\n"
assert_equal expected, char_counter.print_out
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment