Sha256: 393a4d12cda4347dbb19518e95f5cc67603626ed436b9b58f35d065fa459bf52

Contents?: true

Size: 876 Bytes

Versions: 3

Compression:

Stored size: 876 Bytes

Contents

require 'test/unit'

# lowest upper bound of counter's value
LIMIT = 2 ** DUT.Size.intVal

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

class A_counter_after_being_reset < Test::Unit::TestCase
  def setup
    DUT.reset! # reset the counter
  end

  def test_should_be_zero
    assert_equal( 0, DUT.count.intVal )
  end

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

class A_counter_with_the_maximum_value < Test::Unit::TestCase
  def setup
    DUT.reset! # reset the counter

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-vpi-20.0.0 examples/counter/xUnit/counter_spec.rb
ruby-vpi-21.0.0 examples/counter/xUnit/counter_spec.rb
ruby-vpi-21.1.0 examples/counter/xUnit/counter_spec.rb