barcode1dtools 0.9.6.0 → 0.9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ #--
2
+ # Copyright 2012 Michael Chaney Consulting Corporation
3
+ #
4
+ # Released under the terms of the MIT License or the GNU
5
+ # General Public License, v. 2
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require 'barcode1dtools'
10
+
11
+ class Barcode1DToolsCoop2of5Test < Test::Unit::TestCase
12
+ def setup
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ # Creates a random number from 1 to 10 digits long
19
+ def random_coop2of5_value(len)
20
+ (1..1+rand(len)).collect { "0123456789"[rand(10),1] }.join
21
+ end
22
+
23
+ def test_checksum_generation
24
+ assert_equal 2, Barcode1DTools::Coop2of5.generate_check_digit_for('1234')
25
+ end
26
+
27
+ def test_checksum_validation
28
+ assert Barcode1DTools::Coop2of5.validate_check_digit_for('12342')
29
+ end
30
+
31
+ def test_attr_readers
32
+ coop2of5 = Barcode1DTools::Coop2of5.new('1234', :checksum_included => false)
33
+ assert_equal 2, coop2of5.check_digit
34
+ assert_equal '1234', coop2of5.value
35
+ assert_equal '12342', coop2of5.encoded_string
36
+ end
37
+
38
+ def test_checksum_error
39
+ # proper checksum is 2
40
+ assert_raise(Barcode1DTools::ChecksumError) { Barcode1DTools::Coop2of5.new('12345', :checksum_included => true) }
41
+ end
42
+
43
+ def test_skip_checksum
44
+ coop2of5 = Barcode1DTools::Coop2of5.new('1234', :skip_checksum => true)
45
+ assert_nil coop2of5.check_digit
46
+ assert_equal '1234', coop2of5.value
47
+ assert_equal '1234', coop2of5.encoded_string
48
+ end
49
+
50
+ def test_bad_character_errors
51
+ # Characters that cannot be encoded
52
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Coop2of5.new('thisisnotgood', :checksum_included => false) }
53
+ end
54
+
55
+ # Only need to test wn, as bars and rle are based on wn
56
+ def test_barcode_generation
57
+ coop2of5 = Barcode1DTools::Coop2of5.new('1234', :skip_checksum => true)
58
+ assert_equal "wnwnnnnwwnnnwnwnnnwwnnnwnnwnnww", coop2of5.wn
59
+ end
60
+
61
+ def test_decode_error
62
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Coop2of5.decode('x') }
63
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Coop2of5.decode('x'*60) }
64
+ # proper start & stop, but crap in middle
65
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Coop2of5.decode('wnwnnnnnnnww') }
66
+ # wrong start/stop
67
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Coop2of5.decode('nwwnwnwnwnwnwnw') }
68
+ end
69
+
70
+ def test_decoding
71
+ random_coop2of5_num=random_coop2of5_value(10)
72
+ coop2of5 = Barcode1DTools::Coop2of5.new(random_coop2of5_num, :skip_checksum => true)
73
+ coop2of52 = Barcode1DTools::Coop2of5.decode(coop2of5.wn)
74
+ assert_equal coop2of5.value, coop2of52.value
75
+ # Should also work in reverse
76
+ coop2of54 = Barcode1DTools::Coop2of5.decode(coop2of5.wn.reverse)
77
+ assert_equal coop2of5.value, coop2of54.value
78
+ end
79
+ end
@@ -0,0 +1,79 @@
1
+ #--
2
+ # Copyright 2012 Michael Chaney Consulting Corporation
3
+ #
4
+ # Released under the terms of the MIT License or the GNU
5
+ # General Public License, v. 2
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require 'barcode1dtools'
10
+
11
+ class Barcode1DToolsIATA2of5Test < Test::Unit::TestCase
12
+ def setup
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ # Creates a random number from 1 to 10 digits long
19
+ def random_iata2of5_value(len)
20
+ (1..1+rand(len)).collect { "0123456789"[rand(10),1] }.join
21
+ end
22
+
23
+ def test_checksum_generation
24
+ assert_equal 2, Barcode1DTools::IATA2of5.generate_check_digit_for('1234')
25
+ end
26
+
27
+ def test_checksum_validation
28
+ assert Barcode1DTools::IATA2of5.validate_check_digit_for('12342')
29
+ end
30
+
31
+ def test_attr_readers
32
+ iata2of5 = Barcode1DTools::IATA2of5.new('1234', :skip_checksum => false)
33
+ assert_equal 2, iata2of5.check_digit
34
+ assert_equal '1234', iata2of5.value
35
+ assert_equal '12342', iata2of5.encoded_string
36
+ end
37
+
38
+ def test_checksum_error
39
+ # proper checksum is 2
40
+ assert_raise(Barcode1DTools::ChecksumError) { Barcode1DTools::IATA2of5.new('12345', :checksum_included => true, :skip_checksum => false) }
41
+ end
42
+
43
+ def test_skip_checksum
44
+ iata2of5 = Barcode1DTools::IATA2of5.new('1234', :skip_checksum => true)
45
+ assert_nil iata2of5.check_digit
46
+ assert_equal '1234', iata2of5.value
47
+ assert_equal '1234', iata2of5.encoded_string
48
+ end
49
+
50
+ def test_bad_character_errors
51
+ # Characters that cannot be encoded
52
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::IATA2of5.new('thisisnotgood', :checksum_included => false) }
53
+ end
54
+
55
+ # Only need to test wn, as bars and rle are based on wn
56
+ def test_barcode_generation
57
+ iata2of5 = Barcode1DTools::IATA2of5.new('1234', :skip_checksum => true)
58
+ assert_equal "nnnnwnnnnnnnwnnnwnnnnnwnwnwnnnnnnnnnnnwnnnwnwnn", iata2of5.wn
59
+ end
60
+
61
+ def test_decode_error
62
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::IATA2of5.decode('x') }
63
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::IATA2of5.decode('x'*60) }
64
+ # proper start & stop, but crap in middle
65
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::IATA2of5.decode('nnnnwwwwwwwwwwnwnn') }
66
+ # wrong start/stop
67
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::IATA2of5.decode('nwwnwnwnwnwnwnw') }
68
+ end
69
+
70
+ def test_decoding
71
+ random_iata2of5_num=random_iata2of5_value(10)
72
+ iata2of5 = Barcode1DTools::IATA2of5.new(random_iata2of5_num, :skip_checksum => true)
73
+ iata2of52 = Barcode1DTools::IATA2of5.decode(iata2of5.wn)
74
+ assert_equal iata2of5.value, iata2of52.value
75
+ # Should also work in reverse
76
+ iata2of54 = Barcode1DTools::IATA2of5.decode(iata2of5.wn.reverse)
77
+ assert_equal iata2of5.value, iata2of54.value
78
+ end
79
+ end
@@ -0,0 +1,79 @@
1
+ #--
2
+ # Copyright 2012 Michael Chaney Consulting Corporation
3
+ #
4
+ # Released under the terms of the MIT License or the GNU
5
+ # General Public License, v. 2
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require 'barcode1dtools'
10
+
11
+ class Barcode1DToolsIndustrial2of5Test < Test::Unit::TestCase
12
+ def setup
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ # Creates a random number from 1 to 10 digits long
19
+ def random_industrial2of5_value(len)
20
+ (1..1+rand(len)).collect { "0123456789"[rand(10),1] }.join
21
+ end
22
+
23
+ def test_checksum_generation
24
+ assert_equal 2, Barcode1DTools::Industrial2of5.generate_check_digit_for('1234')
25
+ end
26
+
27
+ def test_checksum_validation
28
+ assert Barcode1DTools::Industrial2of5.validate_check_digit_for('12342')
29
+ end
30
+
31
+ def test_attr_readers
32
+ industrial2of5 = Barcode1DTools::Industrial2of5.new('1234', :skip_checksum => false)
33
+ assert_equal 2, industrial2of5.check_digit
34
+ assert_equal '1234', industrial2of5.value
35
+ assert_equal '12342', industrial2of5.encoded_string
36
+ end
37
+
38
+ def test_checksum_error
39
+ # proper checksum is 2
40
+ assert_raise(Barcode1DTools::ChecksumError) { Barcode1DTools::Industrial2of5.new('12345', :checksum_included => true, :skip_checksum => false) }
41
+ end
42
+
43
+ def test_skip_checksum
44
+ industrial2of5 = Barcode1DTools::Industrial2of5.new('1234', :skip_checksum => true)
45
+ assert_nil industrial2of5.check_digit
46
+ assert_equal '1234', industrial2of5.value
47
+ assert_equal '1234', industrial2of5.encoded_string
48
+ end
49
+
50
+ def test_bad_character_errors
51
+ # Characters that cannot be encoded
52
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Industrial2of5.new('thisisnotgood', :checksum_included => false) }
53
+ end
54
+
55
+ # Only need to test wn, as bars and rle are based on wn
56
+ def test_barcode_generation
57
+ industrial2of5 = Barcode1DTools::Industrial2of5.new('1234', :skip_checksum => true)
58
+ assert_equal "wnwnnnwnnnnnnnwnnnwnnnnnwnwnwnnnnnnnnnnnwnnnwnwnnnw", industrial2of5.wn
59
+ end
60
+
61
+ def test_decode_error
62
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Industrial2of5.decode('x') }
63
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Industrial2of5.decode('x'*60) }
64
+ # proper start & stop, but crap in middle
65
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Industrial2of5.decode('wnwnnnnnnnww') }
66
+ # wrong start/stop
67
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Industrial2of5.decode('nwwnwnwnwnwnwnw') }
68
+ end
69
+
70
+ def test_decoding
71
+ random_industrial2of5_num=random_industrial2of5_value(10)
72
+ industrial2of5 = Barcode1DTools::Industrial2of5.new(random_industrial2of5_num, :skip_checksum => true)
73
+ industrial2of52 = Barcode1DTools::Industrial2of5.decode(industrial2of5.wn)
74
+ assert_equal industrial2of5.value, industrial2of52.value
75
+ # Should also work in reverse
76
+ industrial2of54 = Barcode1DTools::Industrial2of5.decode(industrial2of5.wn.reverse)
77
+ assert_equal industrial2of5.value, industrial2of54.value
78
+ end
79
+ end
@@ -0,0 +1,79 @@
1
+ #--
2
+ # Copyright 2012 Michael Chaney Consulting Corporation
3
+ #
4
+ # Released under the terms of the MIT License or the GNU
5
+ # General Public License, v. 2
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require 'barcode1dtools'
10
+
11
+ class Barcode1DToolsMatrix2of5Test < Test::Unit::TestCase
12
+ def setup
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ # Creates a random number from 1 to 10 digits long
19
+ def random_matrix2of5_value(len)
20
+ (1..1+rand(len)).collect { "0123456789"[rand(10),1] }.join
21
+ end
22
+
23
+ def test_checksum_generation
24
+ assert_equal 2, Barcode1DTools::Matrix2of5.generate_check_digit_for('1234')
25
+ end
26
+
27
+ def test_checksum_validation
28
+ assert Barcode1DTools::Matrix2of5.validate_check_digit_for('12342')
29
+ end
30
+
31
+ def test_attr_readers
32
+ matrix2of5 = Barcode1DTools::Matrix2of5.new('1234', :checksum_included => false)
33
+ assert_equal 2, matrix2of5.check_digit
34
+ assert_equal '1234', matrix2of5.value
35
+ assert_equal '12342', matrix2of5.encoded_string
36
+ end
37
+
38
+ def test_checksum_error
39
+ # proper checksum is 2
40
+ assert_raise(Barcode1DTools::ChecksumError) { Barcode1DTools::Matrix2of5.new('12345', :checksum_included => true) }
41
+ end
42
+
43
+ def test_skip_checksum
44
+ matrix2of5 = Barcode1DTools::Matrix2of5.new('1234', :skip_checksum => true)
45
+ assert_nil matrix2of5.check_digit
46
+ assert_equal '1234', matrix2of5.value
47
+ assert_equal '1234', matrix2of5.encoded_string
48
+ end
49
+
50
+ def test_bad_character_errors
51
+ # Characters that cannot be encoded
52
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Matrix2of5.new('thisisnotgood', :checksum_included => false) }
53
+ end
54
+
55
+ # Only need to test wn, as bars and rle are based on wn
56
+ def test_barcode_generation
57
+ matrix2of5 = Barcode1DTools::Matrix2of5.new('1234', :skip_checksum => true)
58
+ assert_equal "wnnnnnwnnnwnnwnnwnwwnnnnnnwnwnwnnnn", matrix2of5.wn
59
+ end
60
+
61
+ def test_decode_error
62
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Matrix2of5.decode('x') }
63
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Matrix2of5.decode('x'*60) }
64
+ # proper start & stop, but crap in middle
65
+ assert_raise(Barcode1DTools::UndecodableCharactersError) { Barcode1DTools::Matrix2of5.decode('wnnnnnnnnnnnwnnnn') }
66
+ # wrong start/stop
67
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::Matrix2of5.decode('nwwnwnwnwnwnwnw') }
68
+ end
69
+
70
+ def test_decoding
71
+ random_matrix2of5_num=random_matrix2of5_value(10)
72
+ matrix2of5 = Barcode1DTools::Matrix2of5.new(random_matrix2of5_num, :skip_checksum => true)
73
+ matrix2of52 = Barcode1DTools::Matrix2of5.decode(matrix2of5.wn)
74
+ assert_equal matrix2of5.value, matrix2of52.value
75
+ # Should also work in reverse
76
+ matrix2of54 = Barcode1DTools::Matrix2of5.decode(matrix2of5.wn.reverse)
77
+ assert_equal matrix2of5.value, matrix2of54.value
78
+ end
79
+ end
@@ -0,0 +1,87 @@
1
+ #--
2
+ # Copyright 2012 Michael Chaney Consulting Corporation
3
+ #
4
+ # Released under the terms of the MIT License or the GNU
5
+ # General Public License, v. 2
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require 'barcode1dtools'
10
+
11
+ class Barcode1DToolsPostNetTest < Test::Unit::TestCase
12
+ def setup
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ # Creates a random number from 1 to 10 digits long
19
+ def random_postnet_value(len)
20
+ (1..len).collect { "0123456789"[rand(10),1] }.join
21
+ end
22
+
23
+ def test_checksum_generation
24
+ assert_equal 5, Barcode1DTools::PostNet.generate_check_digit_for('12345')
25
+ end
26
+
27
+ def test_checksum_validation
28
+ assert Barcode1DTools::PostNet.validate_check_digit_for('123455')
29
+ end
30
+
31
+ def test_attr_readers
32
+ postnet = Barcode1DTools::PostNet.new('12345', :checksum_included => false)
33
+ assert_equal 5, postnet.check_digit
34
+ assert_equal '12345', postnet.value
35
+ assert_equal '123455', postnet.encoded_string
36
+ end
37
+
38
+ def test_checksum_error
39
+ # proper checksum is 5
40
+ assert_raise(Barcode1DTools::ChecksumError) { Barcode1DTools::PostNet.new('123451', :checksum_included => true) }
41
+ end
42
+
43
+ def test_skip_checksum
44
+ postnet = Barcode1DTools::PostNet.new('12345', :skip_checksum => true)
45
+ assert_nil postnet.check_digit
46
+ assert_equal '12345', postnet.value
47
+ assert_equal '12345', postnet.encoded_string
48
+ end
49
+
50
+ def test_bad_character_errors
51
+ # Characters that cannot be encoded
52
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::PostNet.new('thisisnotgood', :checksum_included => false) }
53
+ end
54
+
55
+ # Only need to test wn, as bars and rle are based on wn
56
+ def test_barcode_generation
57
+ postnet = Barcode1DTools::PostNet.new('555551237')
58
+ assert_equal "wnwnwnnwnwnnwnwnnwnwnnwnwnnnnwwnnwnwnnwwnwnnnwnnwnww", postnet.wn
59
+ end
60
+
61
+ def test_decode_error
62
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::PostNet.decode('x') }
63
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::PostNet.decode('x'*60) }
64
+ # proper start & stop, but crap in middle
65
+ assert_raise(Barcode1DTools::UndecodableCharactersError) { Barcode1DTools::PostNet.decode('wnwnnnnnnnww') }
66
+ # wrong start/stop
67
+ assert_raise(Barcode1DTools::UnencodableCharactersError) { Barcode1DTools::PostNet.decode('nwwnwnwnwnwnwnw') }
68
+ end
69
+
70
+ def test_auto_add_checksum
71
+ postnet = Barcode1DTools::PostNet.new(random_postnet_value(5))
72
+ assert !postnet.check_digit.nil?
73
+ end
74
+
75
+ def test_auto_check_checksum
76
+ postnet = Barcode1DTools::PostNet.new('372116')
77
+ assert_equal 6, postnet.check_digit
78
+ assert postnet.options[:checksum_included]
79
+ end
80
+
81
+ def test_decoding
82
+ random_postnet_num=random_postnet_value(11)
83
+ postnet = Barcode1DTools::PostNet.new(random_postnet_num)
84
+ postnet2 = Barcode1DTools::PostNet.decode(postnet.wn)
85
+ assert_equal postnet.value, postnet2.value
86
+ end
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barcode1dtools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
9
+ - 7
10
10
  - 0
11
- version: 0.9.6.0
11
+ version: 0.9.7.0
12
12
  platform: ruby
13
13
  authors:
14
14
  - Michael Chaney
@@ -22,7 +22,8 @@ dependencies: []
22
22
 
23
23
  description: "\t Barcode1D is a small library for handling many kinds of\n\
24
24
  \t 1-dimensional barcodes. Currently implemented are Code 3 of 9, Code\n\
25
- \t 93, Code 11, Codabar, Interleaved 2 of 5, EAN-13, EAN-8, UPC-A,\n\
25
+ \t 93, Code 11, Codabar, Interleaved 2 of 5, COOP 2 of 5, Matrix 2 of\n\
26
+ \t 5, Industrial 2 of 5, IATA 2 of 5, PostNet, EAN-13, EAN-8, UPC-A,\n\
26
27
  \t UPC-E, UPC Supplemental 2, and UPC Supplemental 5. Patterns are\n\
27
28
  \t created in either a simple format of bars and spaces or as a\n\
28
29
  \t run-length encoded string. This only generates and decodes the\n\
@@ -41,9 +42,14 @@ files:
41
42
  - lib/barcode1dtools/code11.rb
42
43
  - lib/barcode1dtools/code3of9.rb
43
44
  - lib/barcode1dtools/code93.rb
45
+ - lib/barcode1dtools/coop2of5.rb
44
46
  - lib/barcode1dtools/ean13.rb
45
47
  - lib/barcode1dtools/ean8.rb
48
+ - lib/barcode1dtools/iata2of5.rb
49
+ - lib/barcode1dtools/industrial2of5.rb
46
50
  - lib/barcode1dtools/interleaved2of5.rb
51
+ - lib/barcode1dtools/matrix2of5.rb
52
+ - lib/barcode1dtools/postnet.rb
47
53
  - lib/barcode1dtools/upc_a.rb
48
54
  - lib/barcode1dtools/upc_e.rb
49
55
  - lib/barcode1dtools/upc_supplemental_2.rb
@@ -55,9 +61,14 @@ files:
55
61
  - test/test_barcode1dcode11.rb
56
62
  - test/test_barcode1dcode3of9.rb
57
63
  - test/test_barcode1dcode93.rb
64
+ - test/test_barcode1dcoop2of5.rb
58
65
  - test/test_barcode1dean13.rb
59
66
  - test/test_barcode1dean8.rb
60
67
  - test/test_barcode1di2of5.rb
68
+ - test/test_barcode1diata2of5.rb
69
+ - test/test_barcode1dindustrial2of5.rb
70
+ - test/test_barcode1dmatrix2of5.rb
71
+ - test/test_barcode1dpostnet.rb
61
72
  - test/test_barcode1dupca.rb
62
73
  - test/test_barcode1dupce.rb
63
74
  - test/test_barcode1dupcsupp2.rb
@@ -105,9 +116,14 @@ test_files:
105
116
  - test/test_barcode1dcode11.rb
106
117
  - test/test_barcode1dcode3of9.rb
107
118
  - test/test_barcode1dcode93.rb
119
+ - test/test_barcode1dcoop2of5.rb
108
120
  - test/test_barcode1dean13.rb
109
121
  - test/test_barcode1dean8.rb
110
122
  - test/test_barcode1di2of5.rb
123
+ - test/test_barcode1diata2of5.rb
124
+ - test/test_barcode1dindustrial2of5.rb
125
+ - test/test_barcode1dmatrix2of5.rb
126
+ - test/test_barcode1dpostnet.rb
111
127
  - test/test_barcode1dupca.rb
112
128
  - test/test_barcode1dupce.rb
113
129
  - test/test_barcode1dupcsupp2.rb