Sha256: 5dbcd7fd006427469c32dff7577fd6b0c5220954594ccbad4afef7f0aeb6882a

Contents?: true

Size: 1.73 KB

Versions: 20

Compression:

Stored size: 1.73 KB

Contents

require File.dirname(__FILE__) + '/base'
require File.dirname(__FILE__) + '/../lib/taps/utils'

describe Taps::Utils do
	it "gunzips a string" do
		@hello_world = "\037\213\b\000R\261\207I\000\003\313H\315\311\311W(\317/\312I\001\000\205\021J\r\v\000\000\000"
		Taps::Utils.gunzip(@hello_world).should == "hello world"
	end

	it "gzips and gunzips a string and returns the same string" do
		Taps::Utils.gunzip(Taps::Utils.gzip("hello world")).should == "hello world"
	end

	it "generates a checksum using crc32" do
		Taps::Utils.checksum("hello world").should == Zlib.crc32("hello world")
	end

	it "formats a data hash into one hash that contains an array of headers and an array of array of data" do
		Taps::Utils.format_data([ { :x => 1, :y => 1 }, { :x => 2, :y => 2 } ]).should == { :header => [ :x, :y ], :data => [ [1, 1], [2, 2] ] }
	end

	it "scales chunksize down slowly when the time delta of the block is just over a second" do
		Time.stubs(:now).returns(10.0).returns(11.5)
		Taps::Utils.calculate_chunksize(1000) { }.should == 900
	end

	it "scales chunksize down fast when the time delta of the block is over 3 seconds" do
		Time.stubs(:now).returns(10.0).returns(15.0)
		Taps::Utils.calculate_chunksize(3000) { }.should == 1000
	end

	it "scales up chunksize fast when the time delta of the block is under 0.8 seconds" do
		Time.stubs(:now).returns(10.0).returns(10.7)
		Taps::Utils.calculate_chunksize(1000) { }.should == 2000
	end

	it "scales up chunksize slow when the time delta of the block is between 0.8 and 1.1 seconds" do
		Time.stubs(:now).returns(10.0).returns(10.8)
		Taps::Utils.calculate_chunksize(1000) { }.should == 1100

		Time.stubs(:now).returns(10.0).returns(11.1)
		Taps::Utils.calculate_chunksize(1000) { }.should == 1100
	end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
ricardochimal-taps-0.2.0 spec/utils_spec.rb
ricardochimal-taps-0.2.1 spec/utils_spec.rb
ricardochimal-taps-0.2.2 spec/utils_spec.rb
ricardochimal-taps-0.2.3 spec/utils_spec.rb
ricardochimal-taps-0.2.4 spec/utils_spec.rb
ricardochimal-taps-0.2.5 spec/utils_spec.rb
ricardochimal-taps-0.2.6 spec/utils_spec.rb
ricardochimal-taps-0.2.7 spec/utils_spec.rb
ricardochimal-taps-0.2.8 spec/utils_spec.rb
ricardochimal-taps-0.2.9 spec/utils_spec.rb
taps-0.2.1 spec/utils_spec.rb
taps-0.2.10 spec/utils_spec.rb
taps-0.2.8 spec/utils_spec.rb
taps-0.2.7 spec/utils_spec.rb
taps-0.2.6 spec/utils_spec.rb
taps-0.2.5 spec/utils_spec.rb
taps-0.2.3 spec/utils_spec.rb
taps-0.2.4 spec/utils_spec.rb
taps-0.2.2 spec/utils_spec.rb
taps-0.2.9 spec/utils_spec.rb