Sha256: 74dcbd363d7b546850e4cd0e304bf234bfcd1e1b2546639e0b966cc43be4becf

Contents?: true

Size: 992 Bytes

Versions: 10

Compression:

Stored size: 992 Bytes

Contents

require 'spec_helper'


describe XDR::Float, ".read" do
  it "decodes values correctly" do
    expect(read("\x00\x00\x00\x00")).to eq(0.0)
    expect(read("\x80\x00\x00\x00")).to eq(-0.0)
    expect(read("\x3F\x80\x00\x00")).to eq(1.0)
    expect(read("\xBF\x80\x00\x00")).to eq(-1.0)
  end

  def read(str)
    io = StringIO.new(str)
    subject.read(io)
  end
end

describe XDR::Float, ".write" do
  it "encodes values correctly" do
    expect(write(0.0)).to eq_bytes("\x00\x00\x00\x00")
    expect(write(-0.0)).to eq_bytes("\x80\x00\x00\x00")
    expect(write(1.0)).to eq_bytes("\x3F\x80\x00\x00")
    expect(write(-1.0)).to eq_bytes("\xBF\x80\x00\x00")
  end

  it "raises a WriteError when the value is not Float" do
    expect{ write 3 }.to raise_error(XDR::WriteError)
    expect{ write "hello" }.to raise_error(XDR::WriteError)
    expect{ write "1.0" }.to raise_error(XDR::WriteError)
  end

  def write(val)
    io = StringIO.new()
    subject.write(val, io)
    io.string
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
payshares-xdr-0.0.2 spec/lib/xdr/float_spec.rb
xdr-3.0.1 spec/lib/xdr/float_spec.rb
xdr-3.0.0 spec/lib/xdr/float_spec.rb
xdr-2.0.0 spec/lib/xdr/float_spec.rb
xdr-1.0.0 spec/lib/xdr/float_spec.rb
xdr-0.1.0 spec/lib/xdr/float_spec.rb
xdr-0.0.4 spec/lib/xdr/float_spec.rb
xdr-0.0.3 spec/lib/xdr/float_spec.rb
xdr-0.0.2 spec/lib/xdr/float_spec.rb
xdr-0.0.1 spec/lib/xdr/float_spec.rb