Sha256: f13a8c6be4a8ffc0b4fa9f81bf1e9dafcac616e14d7246a3ae8d7038bfb5dd82

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')
require 'rubyonacid/factories/modulo'

include RubyOnAcid

describe ModuloFactory do
  
  MARGIN = 0.01
  
  before :each do
    @it = ModuloFactory.new
  end
  
  it "accumulates values and returns remainder of dividing by 1" do
    source_factory = mock('Factory')
    source_factory.should_receive(:get_unit).exactly(3).times.and_return(0.1, 0.35, 0.75)
    @it.source_factory = source_factory
    @it.get_unit(:x).should be_close(0.1, MARGIN)
    @it.get_unit(:x).should be_close(0.45, MARGIN)
    @it.get_unit(:x).should be_close(0.2, MARGIN) #0.45 + 0.75 == 1.2, 1.2 modulo 1 == 0.2
  end
  
  it "Tracks modulos on a per-key basis" do
    source_factory = mock('Factory')
    source_factory.should_receive(:get_unit).exactly(4).times.and_return(0.25, 0.9, 0.33, 0.8)
    @it.source_factory = source_factory
    @it.get_unit(:x).should be_close(0.25, MARGIN)#== 0.25
    @it.get_unit(:x).should be_close(0.15, MARGIN)#== 0.15
    @it.get_unit(:y).should be_close(0.33, MARGIN)#== 0.33
    @it.get_unit(:x).should be_close(0.95, MARGIN)#== 0.95
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubyonacid-0.1.2 spec/generators/modulo_spec.rb
rubyonacid-0.1.1 spec/generators/modulo_spec.rb
rubyonacid-0.1.0 spec/generators/modulo_spec.rb