Sha256: 094a99840dd0f433b07fc445c0dad389b3e69664da793e5386007f13dc67f6f8

Contents?: true

Size: 1.88 KB

Versions: 13

Compression:

Stored size: 1.88 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.
	
	# ?? This test works fine when the shell command (executed from the parent
	# directory) is "ruby test/iteration_test.rb", but fails when run from rake
	# as "rake test".  The captured output is an error message:
	#    "undefined local variable or method `wrapper' for RubyLabs::Source:Module"
	# There is no call to 'wrapper' in our code, so something is messed up in the test.
	
  # 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

13 entries across 13 versions & 1 rubygems

Version Path
rubylabs-1.0.2 test/iteration_test.rb
rubylabs-1.0.1 test/iteration_test.rb
rubylabs-1.0.0 test/iteration_test.rb
rubylabs-0.9.8 test/iteration_test.rb
rubylabs-0.9.7 test/iteration_test.rb
rubylabs-0.9.6 test/iteration_test.rb
rubylabs-0.9.5 test/iteration_test.rb
rubylabs-0.9.4 test/iteration_test.rb
rubylabs-0.9.3 test/iteration_test.rb
rubylabs-0.9.2 test/iteration_test.rb
rubylabs-0.9.1 test/iteration_test.rb
rubylabs-0.9.0 test/iteration_test.rb
rubylabs-0.8.3 test/iteration_test.rb