Sha256: 3d4b948f50e7107b3bd77be71cd04320f5632e422c3771cb9d1b9c5664bd5d7d

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require File.join(File.dirname(__FILE__), 'CONFIG.rb')

require 'rubygems'
require 'facets'

require 'test/unit'
require 'og'
require 'glue/timestamped'

class TC_OgAggrCalc < Test::Unit::TestCase # :nodoc: all
  include Og

  class User
    property :section, String
    property :age, Fixnum
    is Glue::Timestamped

    def initialize(section, age)
      @section = section
      @age = age
    end    
  end

  $og1.manage_classes(User)

  def test_all
    User.create('a', 12)
    User.create('a', 16)
    User.create('d', 34)
    User.create('d', 33)
    User.create('c', 27)
    last = User.create('c', 31)
    
    assert_equal 6, User.count
    assert_equal 12, User.minimum(:age)
    assert_equal 34, User.maximum(:age)
    assert_equal 34, User.max(:age)
    assert_equal 25.5, User.avg(:age)
    assert_equal 153, User.sum(:age)
    
    sums = User.sum(:age, :group => :section)
    assert_equal 3, sums.size
    assert(sums.include?(28))
    assert(sums.include?(58))
    assert(sums.include?(67))
    assert_equal(last.create_time.to_s, User.max(:create_time).to_s)
    assert_instance_of(Time, User.max(:create_time))
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
og-0.41.0 test/og/tc_aggregations_calculations.rb
og-0.30.0 test/og/tc_aggregations_calculations.rb
og-0.31.0 test/og/tc_aggregations_calculations.rb
og-0.40.0 test/og/tc_aggregations_calculations.rb