Sha256: 9cd62fa36c9d0bc102e08b1571d631c6f6190094ee6f899443555e16a3c43048

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require "spec_helper"

describe Tabs::Metrics::Value::Stats do

  let(:period) { (Time.now - 2.days..Time.now) }
  let(:resolution) { :hour }
  let(:values) do
    [
      { "timestamp" => Time.now - 30.hours, "count" => 10, "sum" => 145, "min" => 11, "max" => 204, "avg" => 14.5 },
      { "timestamp" => Time.now - 20.hours, "count" => 15, "sum" => 288, "min" => 10, "max" => 199, "avg" => 19.2 },
      { "timestamp" => Time.now - 10.hours, "count" => 25, "sum" => 405, "min" => 12, "max" => 210, "avg" => 16.2 }
    ]
  end
  let(:stats) { Tabs::Metrics::Value::Stats.new(period, resolution, values) }

  it "is enumerable" do
    expect(stats).to respond_to :each
    expect(Tabs::Metrics::Value::Stats.ancestors).to include Enumerable
  end

  it "#count returns the total count for the entire set" do
    expect(stats.count).to eq 50
  end

  it "sum returns the sum for the entire set" do
    expect(stats.sum).to eq 838
  end

  it "min returns the min for the entire set" do
    expect(stats.min).to eq 10
  end

  it "max returns the max for the entire set" do
    expect(stats.max).to eq 210
  end

  it "avg returns the average for the entire set" do
    expect(stats.avg).to eq 16.76
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tabs-0.8.0 spec/lib/tabs/metrics/value/stats_spec.rb