Sha256: 19c6a8fc37069b2c1c49f3f5a16fed6fce43ba524735999647a19a6191a00e63

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'test_helper'
require 'stringio'

include IterationLab

class TestIterativeAlgoritms < Test::Unit::TestCase
  
  def test_00_banner
    print "\nIterationLab"
  end
  
  # Test the contains? method (our version of include?)
  
  def test_01_contains
    a = ["fee", "fie", "foe", "fum"]
    assert contains?(a, "fee")
    assert contains?(a, "foe")
    assert contains?(a, "fum")
    assert !contains?(a, "foo")
  end

	# Same as above, but using the location method (our version of index)
	
  def test_02_search
    a = ["fee", "fie", "foe", "fum"]
    assert_equal 0, search(a, "fee")
    assert_equal 2, search(a, "foe")
    assert_equal 3, search(a, "fum")
    assert_nil search(a, "foo")
  end

	# Make some test arrays, sort them	

	def test_03_isort
	  [15, 16, 17].each do |size|
  		a = TestArray.new(size)
  		assert_equal isort(a), a.sort
    end
	end
	
	# Capture the output of a trace when sorting a list of 5 numbers.  Expect
	# four lines, with left bracket moving one number to the right each time.
	
	def test_04_trace
    assert Source.clear
    oldout = $stdout
    newout = StringIO.new
    $stdout = newout
    Source.probe :isort, 5, "puts brackets(a,i)"
    trace { isort(TestArray.new(5)) }
    $stdout = oldout
    lines = newout.string.split("\n")
	  assert_equal 4, lines.length
	  assert_match /\d+\s+\[.*\]/, lines[0]
	  assert_match /\d+\s+\d+\s+\[.*\]/, lines[1]
	  assert_match /\[\d+\]/, lines[-1]
	end
	
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubylabs-0.8.2 test/iteration_test.rb
rubylabs-0.8.1 test/iteration_test.rb
rubylabs-0.8.0 test/iteration_test.rb