New Computer, version, confusion

I just got a new computer and need to get stuff moved over to it.
Among “stuff” is Ruby, which mediates building my web site.

I had taken to building my little projects with a project file that
looks like this:

project.rb:

···

==========
require 'rubyunit’
require “binsrch.rb”

With the actual program and tests (for simple examples) in the second
required file, as shown below.

I used to reference TestCase thus:

class TestBinsrch < TestCase

in Ruby 1.6, but now in 1.8 I have to say

class TestBinsrch < Test::Unit::TestCase

When I make that change, things seem to be working OK. What happened?
What would I have to do to make it go back to the other way?

Thanks!!

Ron Jeffries
www.XProgramming.com

===============================
binsrch.rb:

def binsrch ( array, item )

low = 0
high = array.length - 1
while low <= high
half = low + (high-low)/2

puts "item #{item} low #{low} half #{half} high #{high} compare

#{array[half]}"
return half if array[half] == item
if array[half] < item

puts “changing low”

  low = half + 1
else

puts “changing high”

  high = half - 1
end

puts “new low #{low} high #{high}”

end
return -1
end

class TestBinsrch < TestCase

def test1000
array = []
(1…1000).each { | i | array << i }
assert_equal(76, binsrch(array,77))
assert_equal(75, binsrch(array,76))
assert_equal(77, binsrch(array,78))
(1…1000).each { | item |
assert_equal(item-1, binsrch(array,item))
}
end

def test3
array = [1,2,3,4,5,6,7,8,9]
item = 11
assert_equal(-1, binsrch(array,item))
end

def test4
array = [1,2,3,4,5,6,7,8,9]
item = 1
assert_equal(0, binsrch(array,item))
end

def test1
array = [1,2,3,4,5,6,7,8,9]
item = 5
assert_equal(4, binsrch(array,item))
end

def test2
array = [1,2,3,4,5,6,7,8,9]
item = 0
assert_equal(-1, binsrch(array,item))
end

def test5
array = [1,2,3,4,5,6,7,8,9]
item = 9
assert_equal(8, binsrch(array,item))
end

def test6
array = [1,2,3,4,5,6,7,8,9]
item = 3
assert_equal(2, binsrch(array,item))
end

end

Ronald E Jeffries wrote:

I used to reference TestCase thus:

class TestBinsrch < TestCase

in Ruby 1.6, but now in 1.8 I have to say

class TestBinsrch < Test::Unit::TestCase

When I make that change, things seem to be working OK. What happened?
What would I have to do to make it go back to the other way?

This works for me, does it help?

require ‘rubyunit’

TestCase = Test::Unit::TestCase if RUBY_VERSION.to_f > 1.7

class TestBinsrch < TestCase
def test1
assert(true)
end
end

Well, previously you were probably using an actual installation of
RubyUnit, which I guess aliased RUNIT::TestCase to the top-level
constant TestCase. Test::Unit doesn’t do that, because I’d rather not
pollute the namespace automatically. Thus you need to fully qualify the
class name. A possible workaround if you have a bunch of tests that you
don’t want to change is to do the following before your tests:

include Test::Unit

Which imports that namespace in to the top-level.

HTH,

Nathaniel

<:((><

···

On Feb 4, 2004, at 14:55, Ronald E Jeffries wrote:

I just got a new computer and need to get stuff moved over to it.
Among “stuff” is Ruby, which mediates building my web site.

I had taken to building my little projects with a project file that
looks like this:

project.rb:

require ‘rubyunit’
require “binsrch.rb”

With the actual program and tests (for simple examples) in the second
required file, as shown below.

I used to reference TestCase thus:

class TestBinsrch < TestCase

in Ruby 1.6, but now in 1.8 I have to say

class TestBinsrch < Test::Unit::TestCase

When I make that change, things seem to be working OK. What happened?
What would I have to do to make it go back to the other way?

Thanks Joel … I think maybe I’ll change my standard project.rb file
to have that. I was concerned that I had somehow messed up my install
or my paths or something weird.

Thanks again,

···

On Thu, 5 Feb 2004 05:03:05 +0900, Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:

This works for me, does it help?

require ‘rubyunit’

TestCase = Test::Unit::TestCase if RUBY_VERSION.to_f > 1.7

class TestBinsrch < TestCase
def test1
assert(true)
end
end


Ron Jeffries
www.XProgramming.com
I’m giving the best advice I have. You get to decide if it’s true for you.

OK, gotcha. I can do that, or use Joel’s trick. I was just concerned
that my new setup was gratuitously different.

And how’s your life going? Well, I hope!

···

On Thu, 5 Feb 2004 05:07:39 +0900, Nathaniel Talbott nathaniel@talbott.ws wrote:

class TestBinsrch < Test::Unit::TestCase

When I make that change, things seem to be working OK. What happened?
What would I have to do to make it go back to the other way?

Well, previously you were probably using an actual installation of
RubyUnit, which I guess aliased RUNIT::TestCase to the top-level
constant TestCase. Test::Unit doesn’t do that, because I’d rather not
pollute the namespace automatically. Thus you need to fully qualify the
class name. A possible workaround if you have a bunch of tests that you
don’t want to change is to do the following before your tests:

include Test::Unit

Which imports that namespace in to the top-level.


Ron Jeffries
www.XProgramming.com
I’m giving the best advice I have. You get to decide if it’s true for you.

Ronald E Jeffries wrote:

TestCase = Test::Unit::TestCase if RUBY_VERSION.to_f > 1.7

On second thought, it might be clearer to do:

TestCase = Test::Unit::TestCase unless defined?(TestCase)