File: float_test.rb

package info (click to toggle)
ruby-bindata 2.4.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: ruby: 8,566; makefile: 4
file content (72 lines) | stat: -rwxr-xr-x 1,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))

module FloatTest
  def test_num_bytes
    _(@obj.num_bytes).must_equal 4
  end

  def test_writing_then_reading
    _(@obj.value_read_from_written).must_be_close_to Math::PI, 0.000001
  end
end

module DoubleTest
  def test_num_bytes
    _(@obj.num_bytes).must_equal 8
  end

  def test_writing_then_reading
    _(@obj.value_read_from_written).must_be_close_to Math::PI, 0.0000000000000001
  end
end

describe "A FloatLe" do
  include FloatTest

  before do
    @obj = BinData::FloatLe.new(Math::PI)
  end

  it "#to_binary_s" do
    _(@obj.to_binary_s).must_equal_binary [Math::PI].pack('e')
  end
end

describe "A FloatBe" do
  include FloatTest

  before do
    @obj = BinData::FloatBe.new(Math::PI)
  end

  it "#to_binary_s" do
    _(@obj.to_binary_s).must_equal_binary [Math::PI].pack('g')
  end
end

describe "A DoubleLe" do
  include DoubleTest

  before do
    @obj = BinData::DoubleLe.new(Math::PI)
  end

  it "#to_binary_s" do
    _(@obj.to_binary_s).must_equal_binary [Math::PI].pack('E')
  end
end


describe "A DoubleBe" do
  include DoubleTest

  before do
    @obj = BinData::DoubleBe.new(Math::PI)
  end

  it "#to_binary_s" do
    _(@obj.to_binary_s).must_equal_binary [Math::PI].pack('G')
  end
end