Sha256: d40f2c5506275dcba9507ff5d07a050d864c27b216584a9c838e9c44cb474b95

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

require 'helper'

class TestMetric < Test::Unit::TestCase
  def test_counting
    m = Dasht::Metric.new
    proc = Proc.new do |old_value, new_value|
      (old_value || 0) + new_value
    end
    m.append(4, 1, &proc)
    m.append(5, 1, &proc)
    m.append(6, 2, &proc)
    m.append(7, 2, &proc)

    assert_equal 22, m.enum(1).inject(:+)
    assert_equal 13, m.enum(2).inject(:+)
    assert_equal 9, m.enum(1,2).inject(:+)
  end

  def test_lists
    m = Dasht::Metric.new
    proc = Proc.new do |old_value, new_value|
      (old_value || []).push(new_value)
    end
    m.append(:a, 1, &proc)
    m.append(:b, 1, &proc)
    m.append(:c, 2, &proc)
    m.append(:d, 2, &proc)

    assert_equal [:a, :b, :c, :d], m.enum(1).to_a.flatten
    assert_equal [:c, :d], m.enum(2).to_a.flatten
    assert_equal [:a, :b], m.enum(1, 2).to_a.flatten
  end

  def test_trim_to
    m = Dasht::Metric.new
    proc = Proc.new do |old_value, new_value|
      (old_value || []).push(new_value)
    end
    m.append(:a, 1, &proc)
    m.append(:b, 1, &proc)
    m.append(:c, 2, &proc)
    m.append(:d, 2, &proc)

    m.trim_to(1)
    assert_equal [:a, :b, :c, :d], m.enum(0).to_a.flatten

    m.trim_to(2)
    assert_equal [:c, :d], m.enum(0).to_a.flatten

    m.append(:e, 3, &proc)
    m.append(:f, 3, &proc)
    assert_equal [:c, :d, :e, :f], m.enum(0).to_a.flatten


    m.trim_to(3)
    assert_equal [:e, :f], m.enum(0).to_a.flatten
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dasht-0.1.9 test/test_metric.rb
dasht-0.1.8 test/test_metric.rb
dasht-0.1.7 test/test_metric.rb
dasht-0.1.6 test/test_metric.rb
dasht-0.1.5 test/test_metric.rb
dasht-0.1.4 test/test_metric.rb
dasht-0.1.3 test/test_metric.rb
dasht-0.1.2 test/test_metric.rb
dasht-0.1.1 test/test_metric.rb
dasht-0.1.0 test/test_metric.rb