Sha256: a2b85717e4d33ebb5e1f432a67d5de0879274daed78dce80b8b97c89eefd4903

Contents?: true

Size: 1.33 KB

Versions: 163

Compression:

Stored size: 1.33 KB

Contents

#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'binary_search'

class BinarySearchTest < Minitest::Test
  def test_it_has_list_data
    binary = BinarySearch.new([1, 3, 4, 6, 8, 9, 11])
    assert_equal [1, 3, 4, 6, 8, 9, 11], binary.list
  end

  def test_it_raises_error_for_unsorted_list
    skip
    assert_raises ArgumentError do
      BinarySearch.new([2, 1, 4, 3, 6])
    end
  end

  def test_it_raises_error_for_data_not_in_list
    skip
    assert_raises RuntimeError do
      BinarySearch.new([1, 3, 6]).search_for(2)
    end
  end

  def test_it_finds_position_of_middle_item
    skip
    binary = BinarySearch.new([1, 3, 4, 6, 8, 9, 11])
    assert_equal 3, binary.middle
  end

  def test_it_finds_position_of_search_data
    skip
    binary = BinarySearch.new([1, 3, 4, 6, 8, 9, 11])
    assert_equal 5, binary.search_for(9)
  end

  def test_it_finds_position_in_a_larger_list
    skip
    binary = BinarySearch.new([1, 3, 5, 8, 13, 21, 34, 55, 89, 144])
    assert_equal 1, binary.search_for(3)
    assert_equal 7, binary.search_for(55)
  end

  def test_it_finds_correct_position_in_a_list_with_an_even_number_of_elements
    skip
    binary = BinarySearch.new([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377])
    assert_equal 5, binary.search_for(21)
    assert_equal 6, binary.search_for(34)
  end
end

Version data entries

163 entries across 163 versions & 1 rubygems

Version Path
trackler-2.0.6.7 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.6 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.5 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.4 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.3 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.2 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.1 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.6.0 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.18 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.17 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.16 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.15 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.14 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.13 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.12 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.11 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.10 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.9 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.8 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.5.7 tracks/ruby/exercises/binary-search/binary_search_test.rb