Sha256: bf398bd3bcc2642350824c9d398d2696731ddb3b6d6ee4594e7ab555a6327c86

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

require 'test/unit'

require 'eymiha/util/histogram'

include Eymiha

class TC_Histogram < Test::Unit::TestCase
  
  def test_empty
    histogram = Histogram.new
    assert(histogram.count == 0)
    assert(histogram.keys == [])
  end

  def test_loading
    h1 = Histogram.new "hello"
    h1.add "goodbye",2
    assert(h1.count == 3)
    assert(h1.count("hello") == 1)
    assert(h1.count("goodbye") == 2)
    assert(h1.count("everyone") == 0)
    assert(h1.key_count == 2)
    h2 = Histogram.new [["hello", 4], "goodbye", "everyone"]
    assert(h2.count == 6)
    assert(h2.count("hello") == 4)
    assert(h2.count("goodbye") == 1)
    assert(h2.count("everyone") == 1)
    assert(h2.key_count == 3)
    h1.add h2
    assert(h1.count == 9)
    assert(h1.count("hello") == 5)
    assert(h1.count("goodbye") == 3)
    assert(h1.count("everyone") == 1)
    assert(h1.key_count == 3)
    assert(h1.has_key?("hello"))
    assert(h1.has_key?("goodbye"))
    assert(h1.has_key?("everyone"))
    assert(!(h1.has_key? "help"))
  end
  
  def test_subset
    h = Histogram.new [["hello", 4], ["goodbye", 3], "everyone"]
    h1 = Histogram.new [["hello", 4], ["goodbye", 3]]
    assert((h >= 3) == h1)
    h2 = Histogram.new [["hello", 4]]
    assert((h > 3) == h2)
    assert((h == 4) == h2)
    h3 = Histogram.new [["goodbye", 3], "everyone"]
    assert((h <= 3) == h3)
    h4 = Histogram.new "everyone"
    assert((h < 3) == h4)
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eymiha_util-1.0.2 test/tc_histogram.rb
eymiha_util-1.0.3 test/tc_histogram.rb
eymiha_util-1.0.0 test/tc_histogram.rb
eymiha_util-1.0.1 test/tc_histogram.rb