Professional Web Applications Themes

New Computer, version, confusion - Ruby

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. ...

  1. #1

    Default 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 Guest

  2. #2

    Default Re: New Computer, version, confusion

    Ronald E Jeffries 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


    Joel Guest

  3. #3

    Default Re: New Computer, version, confusion

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

    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

    <:((><



    Nathaniel Guest

  4. #4

    Default Re: New Computer, version, confusion

    On Thu, 5 Feb 2004 05:07:39 +0900, Nathaniel Talbott
    <ws> wrote:
     
    >
    >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.[/ref]

    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!

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

  5. #5

    Default Re: New Computer, version, confusion

    On Thu, 5 Feb 2004 05:03:05 +0900, Joel VanderWerf
    <Berkeley.EDU> wrote:
     

    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,

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

  6. #6

    Default Re: New Computer, version, confusion

    Ronald E Jeffries wrote:
     [/ref]

    On second thought, it might be clearer to do:

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


    Joel Guest

Similar Threads

  1. confusion over CD or DVD for version 6.06
    By Catherine in forum Ubuntu
    Replies: 17
    Last Post: August 14th, 05:54 AM
  2. MS06-020 confusion on Flash Player version
    By JoshKil in forum Macromedia Flash Player
    Replies: 0
    Last Post: May 10th, 08:37 PM
  3. Kernel version confusion
    By Tim in forum Debian
    Replies: 3
    Last Post: August 10th, 11:10 AM
  4. Replies: 0
    Last Post: July 15th, 05:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139