tmud-3.0.0/benchmark/
tmud-3.0.0/cmd/
tmud-3.0.0/cmd/objects/
tmud-3.0.0/cmd/tiny/
tmud-3.0.0/doc/SQLite/
tmud-3.0.0/doc/SQLite3/
tmud-3.0.0/doc/TernaryTrie/
tmud-3.0.0/farts/
tmud-3.0.0/lib/
tmud-3.0.0/lib/engine/
tmud-3.0.0/lib/farts/
tmud-3.0.0/logs/
# Code Generated by ZenTest v. 2.3.0
#                 classname: asrt / meth =  ratio%
#                 Publisher:    8 /    4 = 200.00%

unless defined? $ZENTEST and $ZENTEST
require 'test/unit'
require 'utility/publisher'
end

class TestPublisher < Test::Unit::TestCase

  class A
    include Publisher
  end

  class B
    attr :msg
    def update(msg)
      @msg = msg
    end
  end

  def setup
    @obj1 = A.new
    @obj2 = B.new
    @obj3 = B.new
  end

  def test_publish
    assert(@obj1.subscribe(@obj2))
    assert(@obj1.subscribe(@obj3))
    assert(@obj1.publish("foo"))
    assert_equal("foo", @obj2.msg)
    assert_equal("foo", @obj3.msg)
  end

  def test_subscribe
    assert(@obj1.subscribe(@obj2))
    assert(@obj1.subscribe(@obj3))
    assert_equal(2, @obj1.subscriber_count)
  end

  def test_unsubscribe
    assert(@obj1.subscribe(@obj2))
    assert_equal(1, @obj1.subscriber_count)
    assert(@obj1.unsubscribe(@obj2))
    assert_equal(0, @obj1.subscriber_count)
  end

  def test_subscriber_count
    assert_equal(0, @obj1.subscriber_count)
    assert(@obj1.subscribe(@obj2))
    assert_equal(1, @obj1.subscriber_count)
  end

  def test_unsubscribe_all
    assert(@obj1.subscribe(@obj2))
    assert(@obj1.subscribe(@obj3))
    assert_equal(2, @obj1.subscriber_count)
    assert(@obj1.unsubscribe_all)
    assert_equal(0, @obj1.subscriber_count)
  end
end