File: code_93_test.rb

package info (click to toggle)
ruby-barby 0.6.8%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 500 kB
  • sloc: ruby: 4,169; java: 1,228; makefile: 9
file content (144 lines) | stat: -rw-r--r-- 4,382 bytes parent folder | download | duplicates (5)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#encoding: ASCII
require 'test_helper'
require 'barby/barcode/code_93'

class Code93Test < Barby::TestCase

  before do
    @data = 'TEST93'
    @code = Code93.new(@data)
  end

  it "should return the same data we put in" do
    @code.data.must_equal @data
  end

  it "should have the expected characters" do
    @code.characters.must_equal @data.split(//)
  end

  it "should have the expected start_encoding" do
    @code.start_encoding.must_equal '101011110'
  end

  it "should have the expected stop_encoding" do
    #                              STOP     TERM
    @code.stop_encoding.must_equal '1010111101'
  end

  it "should have the expected encoded characters" do
    #                                     T         E         S         T         9         3
    @code.encoded_characters.must_equal %w(110100110 110010010 110101100 110100110 100001010 101000010)
  end

  it "should have the expected data_encoding" do
    #                              T        E        S        T        9        3
    @code.data_encoding.must_equal "110100110110010010110101100110100110100001010101000010"
  end

  it "should have the expected data_encoding_with_checksums" do
    #                                             T        E        S        T        9        3        + (C)    6 (K)
    @code.data_encoding_with_checksums.must_equal "110100110110010010110101100110100110100001010101000010101110110100100010"
  end

  it "should have the expected encoding" do
    #                         START    T        E        S        T        9        3        + (C)    6 (K)    STOP     TERM
    @code.encoding.must_equal "1010111101101001101100100101101011001101001101000010101010000101011101101001000101010111101"
  end

  it "should have the expected checksum_values" do
    @code.checksum_values.must_equal [29, 14, 28, 29, 9, 3].reverse #!
  end

  it "should have the expected c_checksum" do
    @code.c_checksum.must_equal 41 #calculate this first!
  end

  it "should have the expected c_checksum_character" do
    @code.c_checksum_character.must_equal '+'
  end

  it "should have the expected c_checksum_encoding" do
    @code.c_checksum_encoding.must_equal '101110110'
  end

  it "should have the expected checksum_values_with_c_checksum" do
    @code.checksum_values_with_c_checksum.must_equal [29, 14, 28, 29, 9, 3, 41].reverse #!
  end

  it "should have the expected k_checksum" do
    @code.k_checksum.must_equal 6 #calculate this first!
  end

  it "should have the expected k_checksum_character" do
    @code.k_checksum_character.must_equal '6'
  end

  it "should have the expected k_checksum_encoding" do
    @code.k_checksum_encoding.must_equal '100100010'
  end

  it "should have the expected checksums" do
    @code.checksums.must_equal [41, 6]
  end

  it "should have the expected checksum_characters" do
    @code.checksum_characters.must_equal ['+', '6']
  end

  it "should have the expected checksum_encodings" do
    @code.checksum_encodings.must_equal %w(101110110 100100010)
  end

  it "should have the expected checksum_encoding" do
    @code.checksum_encoding.must_equal '101110110100100010'
  end

  it "should be valid" do
    assert @code.valid?
  end

  it "should not be valid when not in extended mode" do
    @code.data = 'not extended'
  end

  it "should return data with no checksums on to_s" do
    @code.to_s.must_equal 'TEST93'
  end
  
  describe "Extended mode" do

    before do
      @data = "Extended!"
      @code = Code93.new(@data)
    end

    it "should be extended" do
      assert @code.extended?
    end

    it "should convert extended characters to special shift characters" do
      @code.characters.must_equal ["E", "\304", "X", "\304", "T", "\304", "E", "\304", "N", "\304", "D", "\304", "E", "\304", "D", "\303", "A"]
    end

    it "should have the expected data_encoding" do
      @code.data_encoding.must_equal '110010010100110010101100110100110010110100110100110010110010010'+
      '100110010101000110100110010110010100100110010110010010100110010110010100111010110110101000'
    end

    it "should have the expected c_checksum" do
      @code.c_checksum.must_equal 9
    end

    it "should have the expected k_checksum" do
      @code.k_checksum.must_equal 46
    end

    it "should return the original data on to_s with no checksums" do
      @code.to_s.must_equal 'Extended!'
    end

  end

end