Sha256: 28d7071f1b394610f815072a2f4bdc2534dca00969887f5149f9d06a7182d261

Contents?: true

Size: 888 Bytes

Versions: 2

Compression:

Stored size: 888 Bytes

Contents

# encoding: ascii-8bit
# For convenience when validating longer data types.

require_relative '../test_helper'

class APIHelperTest < Minitest::Test
  include TestPacker

  def test_single_integers
    assert_equal pack(:uint8, 25), "\x19"
  end
  
  def test_other_formats
    assert_equal pack(:uint16, 5*10**4),  "P\xC3"
    assert_equal pack(:uint32, 4*10**9),  "\x00(k\xEE"
    assert_equal pack(:uint64, 9*10**18), "\x00\x00\x84\xE2Pl\xE6|"
  end
  
  def test_array
    assert_equal pack(:uint8, [25,26]), "\x19\x1A"
  end
  
  def test_padding
    assert_equal pack(:uint8, 25, pad: 2), "\x19\x00"
  end
  
  def test_min
    assert_raises(ArgumentError) { pack(:uint8, 25, min: 2) }
  end
  
  def test_max
    assert_raises(ArgumentError) { pack(:uint8, [25,26,27], max: 2) }
  end
  
  def test_invalid_formats
    assert_raises(ArgumentError) { pack(:uint128, 25) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
denko-0.13.1 test/board/helper_test.rb
denko-0.13.0 test/board/helper_test.rb