Sha256: 5edb6d133b75f86441359b28cc21cef908180b336644eceb91eff503adabcb27

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

require 'test/unit'

# lowest upper bound of counter's value
LIMIT = 2 ** Counter::Size

# maximum allowed value for a counter
MAX = LIMIT - 1

class ResettedCounterValue < Test::Unit::TestCase
  def setup
    Counter.reset!
  end

  def test_zero
    assert_equal( 0, Counter.count.intVal )
  end

  def test_increment
    LIMIT.times do |i|
      assert_equal( i, Counter.count.intVal )
      Counter.cycle! # increment the counter
    end
  end
end

class MaximumCounterValue < Test::Unit::TestCase
  def setup
    Counter.reset!

    # increment the counter to maximum value
    MAX.times { Counter.cycle! }
    assert_equal( MAX, Counter.count.intVal )
  end

  def test_overflow
    Counter.cycle! # increment the counter
    assert_equal( 0, Counter.count.intVal )
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-vpi-18.0.0 samp/counter/xUnit/counter_spec.rb
ruby-vpi-17.0.0 samp/counter/xUnit/counter_spec.rb
ruby-vpi-18.0.2 samp/counter/xUnit/counter_spec.rb
ruby-vpi-18.0.1 samp/counter/xUnit/counter_spec.rb
ruby-vpi-19.0.0 examples/counter/xUnit/counter_spec.rb