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.1.0.7 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.6 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.5 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.4 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.3 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.2 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.1 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.1.0.0 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.55 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.54 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.53 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.52 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.51 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.50 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.49 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.48 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.47 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.46 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.45 tracks/ruby/exercises/binary-search/binary_search_test.rb
trackler-2.0.8.44 tracks/ruby/exercises/binary-search/binary_search_test.rb