File: test.rb

package info (click to toggle)
ruby-multibitnums 0.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 92 kB
  • ctags: 26
  • sloc: ansic: 125; ruby: 122; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (2)
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
#-*- mode: ruby; encoding: utf-8-unix -*-#
require "test/unit"
require "narray"
require "numru/multibitnums"
include NumRu

class MultibitNumsTest1 < Test::Unit::TestCase

  def setup
    @testdata = ' '*10
    for i in 0..9
      @testdata[i] = 0x11.chr
    end

    @nbit2 = NArray.int(40).fill!(0)
    for i in 0..39
      @nbit2[i] = 1 if i%2 == 1
    end
    @nbit3 = NArray.int(26).fill!(0)
    for i in 0..25
      @nbit3[i] = 0 if i%4 == 0
      @nbit3[i] = 4 if i%4 == 1
      @nbit3[i] = 2 if i%4 == 2
      @nbit3[i] = 1 if i%4 == 3
    end
    @nbit4 = NArray.int(20).fill!(1)
    @nbit5 = NArray.int(16)
    for i in 0..15
      @nbit5[i] = 2  if i%4 ==0
      @nbit5[i] = 4  if i%4 ==1
      @nbit5[i] = 8  if i%4 ==2
      @nbit5[i] = 17 if i%4 ==3
    end
    @nbit6 = NArray.int(13)
    for i in 0..12
      @nbit6[i] = 4  if i%2 == 0
      @nbit6[i] = 17 if i%2 == 1
    end
    @nbit7 = NArray.int(11)
    for i in 0..10
      @nbit7[i] = 8  if i%4 == 0
      @nbit7[i] = 68 if i%4 == 1
      @nbit7[i] = 34 if i%4 == 2
      @nbit7[i] = 17 if i%4 == 3
    end
    @nbit8 = NArray.int(10).fill!(17)
    @nbit9 = NArray.int(8)
    for i in 0..7
      @nbit9[i] = 34  if i%4 == 0
      @nbit9[i] = 68  if i%4 == 1
      @nbit9[i] = 136 if i%4 == 2
      @nbit9[i] = 273 if i%4 == 3
    end
    @nbit10 = NArray.int(8)
    for i in 0..7
      @nbit10[i] = 68  if i%2 == 0
      @nbit10[i] = 273 if i%2 == 1
    end
  end

  define_method("test_bigedian_unsigned_int") do
    for nbit in 2..10
      mb = MultiBitNums.new(@testdata, nbit)
      assert_equal eval("@nbit#{nbit}"), NArray.to_na( mb.to_int32str, 'int')
    end
  end

end