go-tinyqr

An experimental minimal QR Code generator  http://go-qrcode.appspot.com
git clone https://git.ce9e.org/go-tinyqr.git

commit
f88a46e3cca8631f37b9988bd169f51294086dfb
parent
da1b6568686e89143e94f980a98bc2dbd5537f13
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-02-29 17:37
rm tests

Diffstat

D bitset/bitset_test.go 321 ------------------------------------------------------------
D encoder_test.go 410 ------------------------------------------------------------
D example_test.go 53 -----------------------------------------------------
D qrcode_decode_test.go 232 ------------------------------------------------------------
D qrcode_test.go 175 ------------------------------------------------------------
D reedsolomon/gf2_8_test.go 83 ------------------------------------------------------------
D reedsolomon/gf_poly_test.go 182 ------------------------------------------------------------
D reedsolomon/reed_solomon_test.go 89 ------------------------------------------------------------
D regular_symbol_test.go 31 -------------------------------
D symbol_test.go 334 ------------------------------------------------------------
D version_test.go 158 ------------------------------------------------------------

11 files changed, 0 insertions, 2068 deletions


diff --git a/bitset/bitset_test.go b/bitset/bitset_test.go

@@ -1,321 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package bitset
    5    -1 
    6    -1 import (
    7    -1 	rand "math/rand"
    8    -1 	"testing"
    9    -1 )
   10    -1 
   11    -1 func TestNewBitset(t *testing.T) {
   12    -1 	tests := [][]bool{
   13    -1 		{},
   14    -1 		{b1},
   15    -1 		{b0},
   16    -1 		{b1, b0},
   17    -1 		{b1, b0, b1},
   18    -1 		{b0, b0, b1},
   19    -1 	}
   20    -1 
   21    -1 	for _, v := range tests {
   22    -1 		result := New(v...)
   23    -1 
   24    -1 		if !equal(result.Bits(), v) {
   25    -1 			t.Errorf("%s", result.String())
   26    -1 			t.Errorf("%v => %v, want %v", v, result.Bits(), v)
   27    -1 		}
   28    -1 	}
   29    -1 }
   30    -1 
   31    -1 func TestAppend(t *testing.T) {
   32    -1 	randomBools := make([]bool, 128)
   33    -1 
   34    -1 	rng := rand.New(rand.NewSource(1))
   35    -1 
   36    -1 	for i := 0; i < len(randomBools); i++ {
   37    -1 		randomBools[i] = rng.Intn(2) == 1
   38    -1 	}
   39    -1 
   40    -1 	for i := 0; i < len(randomBools)-1; i++ {
   41    -1 		a := New(randomBools[0:i]...)
   42    -1 		b := New(randomBools[i:]...)
   43    -1 
   44    -1 		a.Append(b)
   45    -1 
   46    -1 		if !equal(a.Bits(), randomBools) {
   47    -1 			t.Errorf("got %v, want %v", a.Bits(), randomBools)
   48    -1 		}
   49    -1 	}
   50    -1 }
   51    -1 
   52    -1 func TestAppendByte(t *testing.T) {
   53    -1 	tests := []struct {
   54    -1 		initial  *Bitset
   55    -1 		value    byte
   56    -1 		numBits  int
   57    -1 		expected *Bitset
   58    -1 	}{
   59    -1 		{
   60    -1 			New(),
   61    -1 			0x01,
   62    -1 			1,
   63    -1 			New(b1),
   64    -1 		},
   65    -1 		{
   66    -1 			New(b1),
   67    -1 			0x01,
   68    -1 			1,
   69    -1 			New(b1, b1),
   70    -1 		},
   71    -1 		{
   72    -1 			New(b0),
   73    -1 			0x01,
   74    -1 			1,
   75    -1 			New(b0, b1),
   76    -1 		},
   77    -1 		{
   78    -1 			New(b1, b0, b1, b0, b1, b0, b1),
   79    -1 			0xAA, // 0b10101010
   80    -1 			2,
   81    -1 			New(b1, b0, b1, b0, b1, b0, b1, b1, b0),
   82    -1 		},
   83    -1 		{
   84    -1 			New(b1, b0, b1, b0, b1, b0, b1),
   85    -1 			0xAA, // 0b10101010
   86    -1 			8,
   87    -1 			New(b1, b0, b1, b0, b1, b0, b1, b1, b0, b1, b0, b1, b0, b1, b0),
   88    -1 		},
   89    -1 	}
   90    -1 
   91    -1 	for _, test := range tests {
   92    -1 		test.initial.AppendByte(test.value, test.numBits)
   93    -1 		if !equal(test.initial.Bits(), test.expected.Bits()) {
   94    -1 			t.Errorf("Got %v, expected %v", test.initial.Bits(),
   95    -1 				test.expected.Bits())
   96    -1 		}
   97    -1 	}
   98    -1 }
   99    -1 
  100    -1 func TestAppendUint32(t *testing.T) {
  101    -1 	tests := []struct {
  102    -1 		initial  *Bitset
  103    -1 		value    uint32
  104    -1 		numBits  int
  105    -1 		expected *Bitset
  106    -1 	}{
  107    -1 		{
  108    -1 			New(),
  109    -1 			0xAAAAAAAF,
  110    -1 			4,
  111    -1 			New(b1, b1, b1, b1),
  112    -1 		},
  113    -1 		{
  114    -1 			New(),
  115    -1 			0xFFFFFFFF,
  116    -1 			32,
  117    -1 			New(b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1,
  118    -1 				b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1, b1),
  119    -1 		},
  120    -1 		{
  121    -1 			New(),
  122    -1 			0x0,
  123    -1 			32,
  124    -1 			New(b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0,
  125    -1 				b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0),
  126    -1 		},
  127    -1 		{
  128    -1 			New(),
  129    -1 			0xAAAAAAAA,
  130    -1 			32,
  131    -1 			New(b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1,
  132    -1 				b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0),
  133    -1 		},
  134    -1 		{
  135    -1 			New(),
  136    -1 			0xAAAAAAAA,
  137    -1 			31,
  138    -1 			New(b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1,
  139    -1 				b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0),
  140    -1 		},
  141    -1 	}
  142    -1 
  143    -1 	for _, test := range tests {
  144    -1 		test.initial.AppendUint32(test.value, test.numBits)
  145    -1 		if !equal(test.initial.Bits(), test.expected.Bits()) {
  146    -1 			t.Errorf("Got %v, expected %v", test.initial.Bits(),
  147    -1 				test.expected.Bits())
  148    -1 		}
  149    -1 	}
  150    -1 }
  151    -1 
  152    -1 func TestAppendBools(t *testing.T) {
  153    -1 	randomBools := make([]bool, 128)
  154    -1 
  155    -1 	rng := rand.New(rand.NewSource(1))
  156    -1 
  157    -1 	for i := 0; i < len(randomBools); i++ {
  158    -1 		randomBools[i] = rng.Intn(2) == 1
  159    -1 	}
  160    -1 
  161    -1 	for i := 0; i < len(randomBools)-1; i++ {
  162    -1 		result := New(randomBools[0:i]...)
  163    -1 		result.AppendBools(randomBools[i:]...)
  164    -1 
  165    -1 		if !equal(result.Bits(), randomBools) {
  166    -1 			t.Errorf("got %v, want %v", result.Bits(), randomBools)
  167    -1 		}
  168    -1 	}
  169    -1 }
  170    -1 
  171    -1 func BenchmarkShortAppend(b *testing.B) {
  172    -1 	bitset := New()
  173    -1 
  174    -1 	for i := 0; i < b.N; i++ {
  175    -1 		bitset.AppendBools(b0, b1, b0, b1, b0, b1, b0)
  176    -1 	}
  177    -1 }
  178    -1 
  179    -1 func TestLen(t *testing.T) {
  180    -1 	randomBools := make([]bool, 128)
  181    -1 
  182    -1 	rng := rand.New(rand.NewSource(1))
  183    -1 
  184    -1 	for i := 0; i < len(randomBools); i++ {
  185    -1 		randomBools[i] = rng.Intn(2) == 1
  186    -1 	}
  187    -1 
  188    -1 	for i := 0; i < len(randomBools)-1; i++ {
  189    -1 		result := New(randomBools[0:i]...)
  190    -1 
  191    -1 		if result.Len() != i {
  192    -1 			t.Errorf("Len = %d, want %d", result.Len(), i)
  193    -1 		}
  194    -1 	}
  195    -1 }
  196    -1 
  197    -1 func TestAt(t *testing.T) {
  198    -1 	test := []bool{b0, b1, b0, b1, b0, b1, b1, b0, b1}
  199    -1 
  200    -1 	bitset := New(test...)
  201    -1 	for i, v := range test {
  202    -1 		result := bitset.At(i)
  203    -1 
  204    -1 		if result != test[i] {
  205    -1 			t.Errorf("bitset[%d] => %t, want %t", i, result, v)
  206    -1 		}
  207    -1 	}
  208    -1 }
  209    -1 
  210    -1 func equal(a []bool, b []bool) bool {
  211    -1 	if len(a) != len(b) {
  212    -1 		return false
  213    -1 	}
  214    -1 
  215    -1 	for i := 0; i < len(a); i++ {
  216    -1 		if a[i] != b[i] {
  217    -1 			return false
  218    -1 		}
  219    -1 	}
  220    -1 
  221    -1 	return true
  222    -1 }
  223    -1 
  224    -1 func TestExample(t *testing.T) {
  225    -1 	b := New()                       // {}
  226    -1 	b.AppendBools(true, true, false) // {1, 1, 0}
  227    -1 	b.AppendBools(true)              // {1, 1, 0, 1}
  228    -1 	b.AppendByte(0x02, 4)            // {1, 1, 0, 1, 0, 0, 1, 0}
  229    -1 
  230    -1 	expected := []bool{b1, b1, b0, b1, b0, b0, b1, b0}
  231    -1 
  232    -1 	if !equal(b.Bits(), expected) {
  233    -1 		t.Errorf("Got %v, expected %v", b.Bits(), expected)
  234    -1 	}
  235    -1 }
  236    -1 
  237    -1 func TestByteAt(t *testing.T) {
  238    -1 	data := []bool{b0, b1, b0, b1, b0, b1, b1, b0, b1}
  239    -1 
  240    -1 	tests := []struct {
  241    -1 		index    int
  242    -1 		expected byte
  243    -1 	}{
  244    -1 		{
  245    -1 			0,
  246    -1 			0x56,
  247    -1 		},
  248    -1 		{
  249    -1 			1,
  250    -1 			0xad,
  251    -1 		},
  252    -1 		{
  253    -1 			2,
  254    -1 			0x2d,
  255    -1 		},
  256    -1 		{
  257    -1 			5,
  258    -1 			0x0d,
  259    -1 		},
  260    -1 		{
  261    -1 			8,
  262    -1 			0x01,
  263    -1 		},
  264    -1 	}
  265    -1 
  266    -1 	for _, test := range tests {
  267    -1 		b := New()
  268    -1 		b.AppendBools(data...)
  269    -1 
  270    -1 		result := b.ByteAt(test.index)
  271    -1 
  272    -1 		if result != test.expected {
  273    -1 			t.Errorf("Got %#x, expected %#x", result, test.expected)
  274    -1 		}
  275    -1 	}
  276    -1 }
  277    -1 
  278    -1 func TestSubstr(t *testing.T) {
  279    -1 	data := []bool{b0, b1, b0, b1, b0, b1, b1, b0}
  280    -1 
  281    -1 	tests := []struct {
  282    -1 		start    int
  283    -1 		end      int
  284    -1 		expected []bool
  285    -1 	}{
  286    -1 		{
  287    -1 			0,
  288    -1 			8,
  289    -1 			[]bool{b0, b1, b0, b1, b0, b1, b1, b0},
  290    -1 		},
  291    -1 		{
  292    -1 			0,
  293    -1 			0,
  294    -1 			[]bool{},
  295    -1 		},
  296    -1 		{
  297    -1 			0,
  298    -1 			1,
  299    -1 			[]bool{b0},
  300    -1 		},
  301    -1 		{
  302    -1 			2,
  303    -1 			4,
  304    -1 			[]bool{b0, b1},
  305    -1 		},
  306    -1 	}
  307    -1 
  308    -1 	for _, test := range tests {
  309    -1 		b := New()
  310    -1 		b.AppendBools(data...)
  311    -1 
  312    -1 		result := b.Substr(test.start, test.end)
  313    -1 
  314    -1 		expected := New()
  315    -1 		expected.AppendBools(test.expected...)
  316    -1 
  317    -1 		if !result.Equals(expected) {
  318    -1 			t.Errorf("Got %s, expected %s", result.String(), expected.String())
  319    -1 		}
  320    -1 	}
  321    -1 }

diff --git a/encoder_test.go b/encoder_test.go

@@ -1,410 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import (
    7    -1 	"fmt"
    8    -1 	"reflect"
    9    -1 	"testing"
   10    -1 
   11    -1 	bitset "github.com/skip2/go-qrcode/bitset"
   12    -1 )
   13    -1 
   14    -1 func TestClassifyDataMode(t *testing.T) {
   15    -1 	type Test struct {
   16    -1 	}
   17    -1 
   18    -1 	tests := []struct {
   19    -1 		data   []byte
   20    -1 		actual []segment
   21    -1 	}{
   22    -1 		{
   23    -1 			[]byte{0x30},
   24    -1 			[]segment{
   25    -1 				{
   26    -1 					dataModeNumeric,
   27    -1 					[]byte{0x30},
   28    -1 				},
   29    -1 			},
   30    -1 		},
   31    -1 		{
   32    -1 			[]byte{0x30, 0x41, 0x42, 0x43, 0x20, 0x00, 0xf0, 0xf1, 0xf2, 0x31},
   33    -1 			[]segment{
   34    -1 				{
   35    -1 					dataModeNumeric,
   36    -1 					[]byte{0x30},
   37    -1 				},
   38    -1 				{
   39    -1 					dataModeAlphanumeric,
   40    -1 					[]byte{0x41, 0x42, 0x43, 0x20},
   41    -1 				},
   42    -1 				{
   43    -1 					dataModeByte,
   44    -1 					[]byte{0x00, 0xf0, 0xf1, 0xf2},
   45    -1 				},
   46    -1 				{
   47    -1 					dataModeNumeric,
   48    -1 					[]byte{0x31},
   49    -1 				},
   50    -1 			},
   51    -1 		},
   52    -1 	}
   53    -1 
   54    -1 	for _, test := range tests {
   55    -1 		encoder := newDataEncoder(dataEncoderType1To9)
   56    -1 		encoder.encode(test.data)
   57    -1 
   58    -1 		if !reflect.DeepEqual(test.actual, encoder.actual) {
   59    -1 			t.Errorf("Got %v, expected %v", encoder.actual, test.actual)
   60    -1 		}
   61    -1 	}
   62    -1 }
   63    -1 
   64    -1 func TestByteModeLengthCalculations(t *testing.T) {
   65    -1 	tests := []struct {
   66    -1 		dataEncoderType dataEncoderType
   67    -1 		dataMode        dataMode
   68    -1 		numSymbols      int
   69    -1 		expectedLength  int
   70    -1 	}{}
   71    -1 
   72    -1 	for i, test := range tests {
   73    -1 		encoder := newDataEncoder(test.dataEncoderType)
   74    -1 		var resultLength int
   75    -1 
   76    -1 		resultLength, err := encoder.encodedLength(test.dataMode, test.numSymbols)
   77    -1 
   78    -1 		if test.expectedLength == -1 {
   79    -1 			if err == nil {
   80    -1 				t.Errorf("Test %d: got length %d, expected error", i, resultLength)
   81    -1 			}
   82    -1 		} else if resultLength != test.expectedLength {
   83    -1 			t.Errorf("Test %d: got length %d, expected length %d", i, resultLength,
   84    -1 				test.expectedLength)
   85    -1 		}
   86    -1 	}
   87    -1 }
   88    -1 
   89    -1 func TestSingleModeEncodings(t *testing.T) {
   90    -1 	tests := []struct {
   91    -1 		dataEncoderType dataEncoderType
   92    -1 		dataMode        dataMode
   93    -1 		data            string
   94    -1 		expected        *bitset.Bitset
   95    -1 	}{
   96    -1 		{
   97    -1 			dataEncoderType1To9,
   98    -1 			dataModeNumeric,
   99    -1 			"01234567",
  100    -1 			bitset.NewFromBase2String("0001 0000001000 0000001100 0101011001 1000011"),
  101    -1 		},
  102    -1 		{
  103    -1 			dataEncoderType1To9,
  104    -1 			dataModeAlphanumeric,
  105    -1 			"AC-42",
  106    -1 			bitset.NewFromBase2String("0010 000000101 00111001110 11100111001 000010"),
  107    -1 		},
  108    -1 		{
  109    -1 			dataEncoderType1To9,
  110    -1 			dataModeByte,
  111    -1 			"123",
  112    -1 			bitset.NewFromBase2String("0100 00000011 00110001 00110010 00110011"),
  113    -1 		},
  114    -1 		{
  115    -1 			dataEncoderType10To26,
  116    -1 			dataModeByte,
  117    -1 			"123",
  118    -1 			bitset.NewFromBase2String("0100 00000000 00000011 00110001 00110010 00110011"),
  119    -1 		},
  120    -1 		{
  121    -1 			dataEncoderType27To40,
  122    -1 			dataModeByte,
  123    -1 			"123",
  124    -1 			bitset.NewFromBase2String("0100 00000000 00000011 00110001 00110010 00110011"),
  125    -1 		},
  126    -1 	}
  127    -1 
  128    -1 	for _, test := range tests {
  129    -1 		encoder := newDataEncoder(test.dataEncoderType)
  130    -1 		encoded := bitset.New()
  131    -1 
  132    -1 		encoder.encodeDataRaw([]byte(test.data), test.dataMode, encoded)
  133    -1 
  134    -1 		if !test.expected.Equals(encoded) {
  135    -1 			t.Errorf("For %s got %s, expected %s", test.data, encoded.String(),
  136    -1 				test.expected.String())
  137    -1 		}
  138    -1 	}
  139    -1 }
  140    -1 
  141    -1 type testModeSegment struct {
  142    -1 	dataMode dataMode
  143    -1 	numChars int
  144    -1 }
  145    -1 
  146    -1 func TestOptimiseEncoding(t *testing.T) {
  147    -1 	tests := []struct {
  148    -1 		dataEncoderType dataEncoderType
  149    -1 		actual          []testModeSegment
  150    -1 		optimised       []testModeSegment
  151    -1 	}{
  152    -1 		// Coalescing multiple segments.
  153    -1 		{
  154    -1 			dataEncoderType1To9,
  155    -1 			[]testModeSegment{
  156    -1 				{dataModeAlphanumeric, 1}, // length = 4 + 9 + 6 = 19 bits
  157    -1 				{dataModeNumeric, 1},      // length = 4 + 10 + 4 = 18 bits
  158    -1 				{dataModeAlphanumeric, 1}, // 19 bits.
  159    -1 				{dataModeNumeric, 1},      // 18 bits.
  160    -1 				{dataModeAlphanumeric, 1}, // 19 bits.
  161    -1 				// total = 93 bits.
  162    -1 			},
  163    -1 			[]testModeSegment{
  164    -1 				{dataModeAlphanumeric, 5}, // length = 4 + 9 + 22 + 6 = 41.
  165    -1 			},
  166    -1 		},
  167    -1 		// Coalesing not necessary.
  168    -1 		{
  169    -1 			dataEncoderType1To9,
  170    -1 			[]testModeSegment{
  171    -1 				{dataModeAlphanumeric, 1},
  172    -1 				{dataModeNumeric, 20},
  173    -1 			},
  174    -1 			[]testModeSegment{
  175    -1 				{dataModeAlphanumeric, 1},
  176    -1 				{dataModeNumeric, 20},
  177    -1 			},
  178    -1 		},
  179    -1 		// Switch to more general dataMode.
  180    -1 		{
  181    -1 			dataEncoderType1To9,
  182    -1 			[]testModeSegment{
  183    -1 				{dataModeAlphanumeric, 100},
  184    -1 				{dataModeByte, 1},
  185    -1 				{dataModeNumeric, 1},
  186    -1 			},
  187    -1 			[]testModeSegment{
  188    -1 				{dataModeAlphanumeric, 100},
  189    -1 				{dataModeByte, 2},
  190    -1 			},
  191    -1 		},
  192    -1 		// Sometimes encoding everything as bytes is more efficient.
  193    -1 		{
  194    -1 			dataEncoderType1To9,
  195    -1 			[]testModeSegment{
  196    -1 				{dataModeAlphanumeric, 1},
  197    -1 				{dataModeByte, 1},
  198    -1 				{dataModeNumeric, 1},
  199    -1 			},
  200    -1 			[]testModeSegment{
  201    -1 				{dataModeByte, 3},
  202    -1 			},
  203    -1 		},
  204    -1 		// https://www.google.com/123456789012345678901234567890
  205    -1 		// BBBBBAAABBBABBBBBBABBBANNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  206    -1 		{
  207    -1 			dataEncoderType1To9,
  208    -1 			[]testModeSegment{
  209    -1 				{dataModeByte, 5},
  210    -1 				{dataModeAlphanumeric, 3},
  211    -1 				{dataModeByte, 3},
  212    -1 				{dataModeAlphanumeric, 1},
  213    -1 				{dataModeByte, 6},
  214    -1 				{dataModeAlphanumeric, 1},
  215    -1 				{dataModeAlphanumeric, 4},
  216    -1 				{dataModeNumeric, 30},
  217    -1 			},
  218    -1 			[]testModeSegment{
  219    -1 				{dataModeByte, 23},
  220    -1 				{dataModeNumeric, 30},
  221    -1 			},
  222    -1 		},
  223    -1 		// https://www.google.com/123
  224    -1 		// BBBBBAAABBBABBBBBBABBBANNN
  225    -1 		// Small segments are inefficient because of additional metadata.
  226    -1 		{
  227    -1 			dataEncoderType1To9,
  228    -1 			[]testModeSegment{
  229    -1 				{dataModeByte, 5},
  230    -1 				{dataModeAlphanumeric, 3},
  231    -1 				{dataModeByte, 3},
  232    -1 				{dataModeAlphanumeric, 1},
  233    -1 				{dataModeByte, 6},
  234    -1 				{dataModeAlphanumeric, 1},
  235    -1 				{dataModeAlphanumeric, 4},
  236    -1 				{dataModeNumeric, 3},
  237    -1 			},
  238    -1 			[]testModeSegment{
  239    -1 				{dataModeByte, 26},
  240    -1 			},
  241    -1 		},
  242    -1 		// HTTPS://WWW.GOOGLE.COM/123
  243    -1 		// AAAAAAAAAAAAAAAAAAAAAAANNN
  244    -1 		{
  245    -1 			dataEncoderType1To9,
  246    -1 			[]testModeSegment{
  247    -1 				{dataModeAlphanumeric, 23},
  248    -1 				{dataModeNumeric, 3},
  249    -1 			},
  250    -1 			[]testModeSegment{
  251    -1 				{dataModeAlphanumeric, 26},
  252    -1 			},
  253    -1 		},
  254    -1 		{
  255    -1 			dataEncoderType27To40,
  256    -1 			[]testModeSegment{
  257    -1 				{dataModeByte, 1},
  258    -1 				{dataModeNumeric, 1},
  259    -1 				{dataModeByte, 1},
  260    -1 				{dataModeNumeric, 1},
  261    -1 				{dataModeByte, 1},
  262    -1 				{dataModeNumeric, 1},
  263    -1 				{dataModeByte, 1},
  264    -1 				{dataModeNumeric, 1},
  265    -1 			},
  266    -1 			[]testModeSegment{
  267    -1 				{dataModeByte, 8},
  268    -1 			},
  269    -1 		},
  270    -1 		// HTTPS://ABC.DE/Q/393AABB6998877XYZ0518AUQCRVJN25
  271    -1 		// AAAAAAAAAAAAAAAAANNNAAAANNNNNNNAAANNNNAAAAAAAANN
  272    -1 		// different to below---------^--------------------
  273    -1 		{
  274    -1 			dataEncoderType1To9,
  275    -1 			[]testModeSegment{
  276    -1 				{dataModeAlphanumeric, 17},
  277    -1 				{dataModeNumeric, 3},
  278    -1 				{dataModeAlphanumeric, 4},
  279    -1 				{dataModeNumeric, 7},
  280    -1 				{dataModeAlphanumeric, 3},
  281    -1 				{dataModeNumeric, 4},
  282    -1 				{dataModeAlphanumeric, 8},
  283    -1 				{dataModeNumeric, 2},
  284    -1 			},
  285    -1 			[]testModeSegment{
  286    -1 				{dataModeAlphanumeric, 48},
  287    -1 			},
  288    -1 		},
  289    -1 		// HTTPS://ABC.DE/Q/393AABB699E877XYZ0518AUQCRVJN25
  290    -1 		// AAAAAAAAAAAAAAAAANNNAAAANNNANNNAAANNNNAAAAAAAANN
  291    -1 		// different to above---------^--------------------
  292    -1 		{
  293    -1 			dataEncoderType1To9,
  294    -1 			[]testModeSegment{
  295    -1 				{dataModeAlphanumeric, 17},
  296    -1 				{dataModeNumeric, 3},
  297    -1 				{dataModeAlphanumeric, 4},
  298    -1 				{dataModeNumeric, 3},
  299    -1 				{dataModeAlphanumeric, 1},
  300    -1 				{dataModeNumeric, 3},
  301    -1 				{dataModeAlphanumeric, 3},
  302    -1 				{dataModeNumeric, 4},
  303    -1 				{dataModeAlphanumeric, 8},
  304    -1 				{dataModeNumeric, 2},
  305    -1 			},
  306    -1 			[]testModeSegment{
  307    -1 				{dataModeAlphanumeric, 48},
  308    -1 			},
  309    -1 		},
  310    -1 		// 0123456789
  311    -1 		// NNNNNNNNNN
  312    -1 		{
  313    -1 			dataEncoderType1To9,
  314    -1 			[]testModeSegment{
  315    -1 				{dataModeNumeric, 10},
  316    -1 			},
  317    -1 			[]testModeSegment{
  318    -1 				{dataModeNumeric, 10},
  319    -1 			},
  320    -1 		},
  321    -1 	}
  322    -1 
  323    -1 	for _, test := range tests {
  324    -1 		numTotalChars := 0
  325    -1 		for _, v := range test.actual {
  326    -1 			numTotalChars += v.numChars
  327    -1 		}
  328    -1 
  329    -1 		data := make([]byte, numTotalChars)
  330    -1 
  331    -1 		i := 0
  332    -1 		for _, v := range test.actual {
  333    -1 			for j := 0; j < v.numChars; j++ {
  334    -1 				switch v.dataMode {
  335    -1 				case dataModeNumeric:
  336    -1 					data[i] = '1'
  337    -1 				case dataModeAlphanumeric:
  338    -1 					data[i] = 'A'
  339    -1 				case dataModeByte:
  340    -1 					data[i] = '#'
  341    -1 				default:
  342    -1 					t.Fatal("Unrecognised data mode")
  343    -1 				}
  344    -1 
  345    -1 				i++
  346    -1 			}
  347    -1 		}
  348    -1 
  349    -1 		encoder := newDataEncoder(test.dataEncoderType)
  350    -1 
  351    -1 		_, err := encoder.encode(data)
  352    -1 
  353    -1 		if err != nil {
  354    -1 			t.Errorf("Got %s, expected valid encoding", err.Error())
  355    -1 		} else {
  356    -1 			ok := true
  357    -1 
  358    -1 			if len(encoder.optimised) != len(test.optimised) {
  359    -1 				ok = false
  360    -1 			} else {
  361    -1 				for i, s := range test.optimised {
  362    -1 					if encoder.optimised[i].dataMode != s.dataMode ||
  363    -1 						len(encoder.optimised[i].data) != s.numChars {
  364    -1 						ok = false
  365    -1 						break
  366    -1 					}
  367    -1 				}
  368    -1 			}
  369    -1 
  370    -1 			if !ok {
  371    -1 				t.Errorf("got %s, expected %s", segmentsString(encoder.optimised),
  372    -1 					testModeSegmentsString(test.optimised))
  373    -1 			}
  374    -1 		}
  375    -1 	}
  376    -1 }
  377    -1 
  378    -1 func testModeSegmentsString(segments []testModeSegment) string {
  379    -1 	result := "["
  380    -1 
  381    -1 	for i, segment := range segments {
  382    -1 		if i > 0 {
  383    -1 			result += ", "
  384    -1 		}
  385    -1 
  386    -1 		result += fmt.Sprintf("%d*%s", segment.numChars,
  387    -1 			dataModeString(segment.dataMode))
  388    -1 	}
  389    -1 
  390    -1 	result += "]"
  391    -1 
  392    -1 	return result
  393    -1 }
  394    -1 
  395    -1 func segmentsString(segments []segment) string {
  396    -1 	result := "["
  397    -1 
  398    -1 	for i, segment := range segments {
  399    -1 		if i > 0 {
  400    -1 			result += ", "
  401    -1 		}
  402    -1 
  403    -1 		result += fmt.Sprintf("%d*%s", len(segment.data),
  404    -1 			dataModeString(segment.dataMode))
  405    -1 	}
  406    -1 
  407    -1 	result += "]"
  408    -1 
  409    -1 	return result
  410    -1 }

diff --git a/example_test.go b/example_test.go

@@ -1,53 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 /*
    4    -1 	Amendments Thu, 2017-December-14:
    5    -1 	- test integration (go test -v)
    6    -1 	- idiomatic go code
    7    -1 */
    8    -1 package qrcode
    9    -1 
   10    -1 import (
   11    -1 	"fmt"
   12    -1 	"image/color"
   13    -1 	"os"
   14    -1 	"testing"
   15    -1 )
   16    -1 
   17    -1 func TestExampleEncode(t *testing.T) {
   18    -1 	if png, err := Encode("https://example.org", Medium, 256); err != nil {
   19    -1 		t.Errorf("Error: %s", err.Error())
   20    -1 	} else {
   21    -1 		fmt.Printf("PNG is %d bytes long", len(png))
   22    -1 	}
   23    -1 }
   24    -1 
   25    -1 func TestExampleWriteFile(t *testing.T) {
   26    -1 	filename := "example.png"
   27    -1 	if err := WriteFile("https://example.org", Medium, 256, filename); err != nil {
   28    -1 		if err = os.Remove(filename); err != nil {
   29    -1 			t.Errorf("Error: %s", err.Error())
   30    -1 		}
   31    -1 	}
   32    -1 }
   33    -1 
   34    -1 func TestExampleEncodeWithColourAndWithoutBorder(t *testing.T) {
   35    -1 	q, err := New("https://example.org", Medium)
   36    -1 	if err != nil {
   37    -1 		t.Errorf("Error: %s", err)
   38    -1 		return
   39    -1 	}
   40    -1 
   41    -1 	// Optionally, disable the QR Code border.
   42    -1 	q.DisableBorder = true
   43    -1 
   44    -1 	// Optionally, set the colours.
   45    -1 	q.ForegroundColor = color.RGBA{R: 0x33, G: 0x33, B: 0x66, A: 0xff}
   46    -1 	q.BackgroundColor = color.RGBA{R: 0xef, G: 0xef, B: 0xef, A: 0xff}
   47    -1 
   48    -1 	err = q.WriteFile(256, "example2.png")
   49    -1 	if err != nil {
   50    -1 		t.Errorf("Error: %s", err)
   51    -1 		return
   52    -1 	}
   53    -1 }

diff --git a/qrcode_decode_test.go b/qrcode_decode_test.go

@@ -1,232 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import (
    7    -1 	"bytes"
    8    -1 	"flag"
    9    -1 	"fmt"
   10    -1 	"math/rand"
   11    -1 	"os/exec"
   12    -1 	"strings"
   13    -1 	"testing"
   14    -1 )
   15    -1 
   16    -1 // These tests use zbarimg to decode generated QR Codes to ensure they are
   17    -1 // readable. sudo apt-get install zbar-tools, or download from
   18    -1 // http://zbar.sourceforge.net.
   19    -1 //
   20    -1 // By default these tests are disabled to avoid a dependency on zbarimg if
   21    -1 // you're not running the tests. Use the -test-decode flag (go test
   22    -1 // -test-decode) to enable.
   23    -1 
   24    -1 var testDecode *bool = flag.Bool("test-decode",
   25    -1 	false,
   26    -1 	"Enable decode tests. Requires zbarimg installed.")
   27    -1 
   28    -1 var testDecodeFuzz *bool = flag.Bool("test-decode-fuzz",
   29    -1 	false,
   30    -1 	"Enable decode fuzz tests. Requires zbarimg installed.")
   31    -1 
   32    -1 func TestDecodeBasic(t *testing.T) {
   33    -1 	if !*testDecode {
   34    -1 		t.Skip("Decode tests not enabled")
   35    -1 	}
   36    -1 
   37    -1 	tests := []struct {
   38    -1 		content        string
   39    -1 		numRepetitions int
   40    -1 		level          RecoveryLevel
   41    -1 	}{
   42    -1 		{
   43    -1 			"A",
   44    -1 			1,
   45    -1 			Low,
   46    -1 		},
   47    -1 		{
   48    -1 			"A",
   49    -1 			1,
   50    -1 			Medium,
   51    -1 		},
   52    -1 		{
   53    -1 			"A",
   54    -1 			1,
   55    -1 			High,
   56    -1 		},
   57    -1 		{
   58    -1 			"A",
   59    -1 			1,
   60    -1 			Highest,
   61    -1 		},
   62    -1 		{
   63    -1 			"01234567",
   64    -1 			1,
   65    -1 			Medium,
   66    -1 		},
   67    -1 	}
   68    -1 
   69    -1 	for _, test := range tests {
   70    -1 		content := strings.Repeat(test.content, test.numRepetitions)
   71    -1 
   72    -1 		q, err := New(content, test.level)
   73    -1 		if err != nil {
   74    -1 			t.Error(err.Error())
   75    -1 		}
   76    -1 
   77    -1 		err = zbarimgCheck(q)
   78    -1 
   79    -1 		if err != nil {
   80    -1 			t.Error(err.Error())
   81    -1 		}
   82    -1 	}
   83    -1 }
   84    -1 
   85    -1 func TestDecodeAllVersionLevels(t *testing.T) {
   86    -1 	if !*testDecode {
   87    -1 		t.Skip("Decode tests not enabled")
   88    -1 	}
   89    -1 
   90    -1 	for version := 1; version <= 40; version++ {
   91    -1 		for _, level := range []RecoveryLevel{Low, Medium, High, Highest} {
   92    -1 			t.Logf("Version=%d Level=%d",
   93    -1 				version,
   94    -1 				level)
   95    -1 
   96    -1 			q, err := NewWithForcedVersion(
   97    -1 				fmt.Sprintf("v-%d l-%d", version, level), version, level)
   98    -1 			if err != nil {
   99    -1 				t.Fatal(err.Error())
  100    -1 				return
  101    -1 			}
  102    -1 
  103    -1 			err = zbarimgCheck(q)
  104    -1 
  105    -1 			if err != nil {
  106    -1 				t.Errorf("Version=%d Level=%d, err=%s, expected success",
  107    -1 					version,
  108    -1 					level,
  109    -1 					err.Error())
  110    -1 				continue
  111    -1 			}
  112    -1 		}
  113    -1 	}
  114    -1 }
  115    -1 
  116    -1 func TestDecodeAllCharacters(t *testing.T) {
  117    -1 	if !*testDecode {
  118    -1 		t.Skip("Decode tests not enabled")
  119    -1 	}
  120    -1 
  121    -1 	var content string
  122    -1 
  123    -1 	// zbarimg has trouble with null bytes, hence start from ASCII 1.
  124    -1 	for i := 1; i < 256; i++ {
  125    -1 		content += string(i)
  126    -1 	}
  127    -1 
  128    -1 	q, err := New(content, Low)
  129    -1 	if err != nil {
  130    -1 		t.Error(err.Error())
  131    -1 	}
  132    -1 
  133    -1 	err = zbarimgCheck(q)
  134    -1 
  135    -1 	if err != nil {
  136    -1 		t.Error(err.Error())
  137    -1 	}
  138    -1 }
  139    -1 
  140    -1 func TestDecodeFuzz(t *testing.T) {
  141    -1 	if !*testDecodeFuzz {
  142    -1 		t.Skip("Decode fuzz tests not enabled")
  143    -1 	}
  144    -1 
  145    -1 	r := rand.New(rand.NewSource(0))
  146    -1 
  147    -1 	const iterations int = 32
  148    -1 	const maxLength int = 128
  149    -1 
  150    -1 	for i := 0; i < iterations; i++ {
  151    -1 		len := r.Intn(maxLength-1) + 1
  152    -1 
  153    -1 		var content string
  154    -1 		for j := 0; j < len; j++ {
  155    -1 			// zbarimg seems to have trouble with special characters, test printable
  156    -1 			// characters only for now.
  157    -1 			content += string(32 + r.Intn(94))
  158    -1 		}
  159    -1 
  160    -1 		for _, level := range []RecoveryLevel{Low, Medium, High, Highest} {
  161    -1 			q, err := New(content, level)
  162    -1 			if err != nil {
  163    -1 				t.Error(err.Error())
  164    -1 			}
  165    -1 
  166    -1 			err = zbarimgCheck(q)
  167    -1 
  168    -1 			if err != nil {
  169    -1 				t.Error(err.Error())
  170    -1 			}
  171    -1 		}
  172    -1 	}
  173    -1 }
  174    -1 
  175    -1 func zbarimgCheck(q *QRCode) error {
  176    -1 	s, err := zbarimgDecode(q)
  177    -1 	if err != nil {
  178    -1 		return err
  179    -1 	}
  180    -1 
  181    -1 	if s != q.Content {
  182    -1 		q.WriteFile(256, fmt.Sprintf("%x.png", q.Content))
  183    -1 		return fmt.Errorf("got '%s' (%x) expected '%s' (%x)", s, s, q.Content, q.Content)
  184    -1 	}
  185    -1 
  186    -1 	return nil
  187    -1 }
  188    -1 
  189    -1 func zbarimgDecode(q *QRCode) (string, error) {
  190    -1 	var png []byte
  191    -1 
  192    -1 	// 512x512px
  193    -1 	png, err := q.PNG(512)
  194    -1 	if err != nil {
  195    -1 		return "", err
  196    -1 	}
  197    -1 
  198    -1 	cmd := exec.Command("zbarimg", "--quiet", "-Sdisable",
  199    -1 		"-Sqrcode.enable", "-")
  200    -1 
  201    -1 	var out bytes.Buffer
  202    -1 
  203    -1 	cmd.Stdin = bytes.NewBuffer(png)
  204    -1 	cmd.Stdout = &out
  205    -1 
  206    -1 	err = cmd.Run()
  207    -1 
  208    -1 	if err != nil {
  209    -1 		return "", err
  210    -1 	}
  211    -1 
  212    -1 	return strings.TrimSuffix(strings.TrimPrefix(out.String(), "QR-Code:"), "\n"), nil
  213    -1 }
  214    -1 
  215    -1 func BenchmarkDecodeTest(b *testing.B) {
  216    -1 	if !*testDecode {
  217    -1 		b.Skip("Decode benchmarks not enabled")
  218    -1 	}
  219    -1 
  220    -1 	for n := 0; n < b.N; n++ {
  221    -1 		q, err := New("content", Medium)
  222    -1 		if err != nil {
  223    -1 			b.Error(err.Error())
  224    -1 		}
  225    -1 
  226    -1 		err = zbarimgCheck(q)
  227    -1 
  228    -1 		if err != nil {
  229    -1 			b.Error(err.Error())
  230    -1 		}
  231    -1 	}
  232    -1 }

diff --git a/qrcode_test.go b/qrcode_test.go

@@ -1,175 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import (
    7    -1 	"strings"
    8    -1 	"testing"
    9    -1 )
   10    -1 
   11    -1 func TestQRCodeMaxCapacity(t *testing.T) {
   12    -1 	if testing.Short() {
   13    -1 		t.Skip("Skipping TestQRCodeCapacity")
   14    -1 	}
   15    -1 
   16    -1 	tests := []struct {
   17    -1 		string         string
   18    -1 		numRepetitions int
   19    -1 	}{
   20    -1 		{
   21    -1 			"0",
   22    -1 			7089,
   23    -1 		},
   24    -1 		{
   25    -1 			"A",
   26    -1 			4296,
   27    -1 		},
   28    -1 		{
   29    -1 			"#",
   30    -1 			2953,
   31    -1 		},
   32    -1 		// Alternate byte/numeric data types. Optimises to 2,952 bytes.
   33    -1 		{
   34    -1 			"#1",
   35    -1 			1476,
   36    -1 		},
   37    -1 	}
   38    -1 
   39    -1 	for _, test := range tests {
   40    -1 		_, err := New(strings.Repeat(test.string, test.numRepetitions), Low)
   41    -1 
   42    -1 		if err != nil {
   43    -1 			t.Errorf("%d x '%s' got %s expected success", test.numRepetitions,
   44    -1 				test.string, err.Error())
   45    -1 		}
   46    -1 	}
   47    -1 
   48    -1 	for _, test := range tests {
   49    -1 		_, err := New(strings.Repeat(test.string, test.numRepetitions+1), Low)
   50    -1 
   51    -1 		if err == nil {
   52    -1 			t.Errorf("%d x '%s' chars encodable, expected not encodable",
   53    -1 				test.numRepetitions+1, test.string)
   54    -1 		}
   55    -1 	}
   56    -1 }
   57    -1 
   58    -1 func TestQRCodeVersionCapacity(t *testing.T) {
   59    -1 	tests := []struct {
   60    -1 		version         int
   61    -1 		level           RecoveryLevel
   62    -1 		maxNumeric      int
   63    -1 		maxAlphanumeric int
   64    -1 		maxByte         int
   65    -1 	}{
   66    -1 		{
   67    -1 			1,
   68    -1 			Low,
   69    -1 			41,
   70    -1 			25,
   71    -1 			17,
   72    -1 		},
   73    -1 		{
   74    -1 			2,
   75    -1 			Low,
   76    -1 			77,
   77    -1 			47,
   78    -1 			32,
   79    -1 		},
   80    -1 		{
   81    -1 			2,
   82    -1 			Highest,
   83    -1 			34,
   84    -1 			20,
   85    -1 			14,
   86    -1 		},
   87    -1 		{
   88    -1 			40,
   89    -1 			Low,
   90    -1 			7089,
   91    -1 			4296,
   92    -1 			2953,
   93    -1 		},
   94    -1 		{
   95    -1 			40,
   96    -1 			Highest,
   97    -1 			3057,
   98    -1 			1852,
   99    -1 			1273,
  100    -1 		},
  101    -1 	}
  102    -1 
  103    -1 	for i, test := range tests {
  104    -1 		numericData := strings.Repeat("1", test.maxNumeric)
  105    -1 		alphanumericData := strings.Repeat("A", test.maxAlphanumeric)
  106    -1 		byteData := strings.Repeat("#", test.maxByte)
  107    -1 
  108    -1 		var n *QRCode
  109    -1 		var a *QRCode
  110    -1 		var b *QRCode
  111    -1 		var err error
  112    -1 
  113    -1 		n, err = New(numericData, test.level)
  114    -1 		if err != nil {
  115    -1 			t.Fatal(err.Error())
  116    -1 		}
  117    -1 
  118    -1 		a, err = New(alphanumericData, test.level)
  119    -1 		if err != nil {
  120    -1 			t.Fatal(err.Error())
  121    -1 		}
  122    -1 
  123    -1 		b, err = New(byteData, test.level)
  124    -1 		if err != nil {
  125    -1 			t.Fatal(err.Error())
  126    -1 		}
  127    -1 
  128    -1 		if n.VersionNumber != test.version {
  129    -1 			t.Fatalf("Test #%d numeric has version #%d, expected #%d", i,
  130    -1 				n.VersionNumber, test.version)
  131    -1 		}
  132    -1 
  133    -1 		if a.VersionNumber != test.version {
  134    -1 			t.Fatalf("Test #%d alphanumeric has version #%d, expected #%d", i,
  135    -1 				a.VersionNumber, test.version)
  136    -1 		}
  137    -1 
  138    -1 		if b.VersionNumber != test.version {
  139    -1 			t.Fatalf("Test #%d byte has version #%d, expected #%d", i,
  140    -1 				b.VersionNumber, test.version)
  141    -1 		}
  142    -1 	}
  143    -1 }
  144    -1 
  145    -1 func TestQRCodeISOAnnexIExample(t *testing.T) {
  146    -1 	var q *QRCode
  147    -1 	q, err := New("01234567", Medium)
  148    -1 
  149    -1 	if err != nil {
  150    -1 		t.Fatalf("Error producing ISO Annex I Example: %s, expected success",
  151    -1 			err.Error())
  152    -1 	}
  153    -1 
  154    -1 	q.encode()
  155    -1 
  156    -1 	const expectedMask int = 2
  157    -1 
  158    -1 	if q.mask != 2 {
  159    -1 		t.Errorf("ISO Annex I example mask got %d, expected %d\n", q.mask,
  160    -1 			expectedMask)
  161    -1 	}
  162    -1 }
  163    -1 
  164    -1 func BenchmarkQRCodeURLSize(b *testing.B) {
  165    -1 	for n := 0; n < b.N; n++ {
  166    -1 		New("http://www.example.org", Medium)
  167    -1 	}
  168    -1 }
  169    -1 
  170    -1 func BenchmarkQRCodeMaximumSize(b *testing.B) {
  171    -1 	for n := 0; n < b.N; n++ {
  172    -1 		// 7089 is the maximum encodable number of numeric digits.
  173    -1 		New(strings.Repeat("0", 7089), Low)
  174    -1 	}
  175    -1 }

diff --git a/reedsolomon/gf2_8_test.go b/reedsolomon/gf2_8_test.go

@@ -1,83 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package reedsolomon
    5    -1 
    6    -1 import "testing"
    7    -1 
    8    -1 func TestGFMultiplicationIdentities(t *testing.T) {
    9    -1 	for i := 0; i < 256; i++ {
   10    -1 		value := gfElement(i)
   11    -1 		if gfMultiply(gfZero, value) != gfZero {
   12    -1 			t.Errorf("0 . %d != 0", value)
   13    -1 		}
   14    -1 
   15    -1 		if gfMultiply(value, gfOne) != value {
   16    -1 			t.Errorf("%d . 1 == %d, want %d", value, gfMultiply(value, gfOne), value)
   17    -1 		}
   18    -1 	}
   19    -1 }
   20    -1 
   21    -1 func TestGFMultiplicationAndDivision(t *testing.T) {
   22    -1 	// a * b == result
   23    -1 	var tests = []struct {
   24    -1 		a      gfElement
   25    -1 		b      gfElement
   26    -1 		result gfElement
   27    -1 	}{
   28    -1 		{0, 29, 0},
   29    -1 		{1, 1, 1},
   30    -1 		{1, 32, 32},
   31    -1 		{2, 4, 8},
   32    -1 		{16, 128, 232},
   33    -1 		{17, 17, 28},
   34    -1 		{27, 9, 195},
   35    -1 	}
   36    -1 
   37    -1 	for _, test := range tests {
   38    -1 		result := gfMultiply(test.a, test.b)
   39    -1 
   40    -1 		if result != test.result {
   41    -1 			t.Errorf("%d * %d = %d, want %d", test.a, test.b, result, test.result)
   42    -1 		}
   43    -1 
   44    -1 		if test.b != gfZero && test.result != gfZero {
   45    -1 			b := gfDivide(test.result, test.a)
   46    -1 
   47    -1 			if b != test.b {
   48    -1 				t.Errorf("%d / %d = %d, want %d", test.result, test.a, b, test.b)
   49    -1 			}
   50    -1 		}
   51    -1 	}
   52    -1 }
   53    -1 
   54    -1 func TestGFInverse(t *testing.T) {
   55    -1 	for i := 1; i < 256; i++ {
   56    -1 		a := gfElement(i)
   57    -1 		inverse := gfInverse(a)
   58    -1 
   59    -1 		result := gfMultiply(a, inverse)
   60    -1 
   61    -1 		if result != gfOne {
   62    -1 			t.Errorf("%d * %d^-1 == %d, want %d", a, inverse, result, gfOne)
   63    -1 		}
   64    -1 	}
   65    -1 }
   66    -1 
   67    -1 func TestGFDivide(t *testing.T) {
   68    -1 	for i := 1; i < 256; i++ {
   69    -1 		for j := 1; j < 256; j++ {
   70    -1 			// a * b == product
   71    -1 			a := gfElement(i)
   72    -1 			b := gfElement(j)
   73    -1 			product := gfMultiply(a, b)
   74    -1 
   75    -1 			// product / b == a
   76    -1 			result := gfDivide(product, b)
   77    -1 
   78    -1 			if result != a {
   79    -1 				t.Errorf("%d / %d == %d, want %d", product, b, result, a)
   80    -1 			}
   81    -1 		}
   82    -1 	}
   83    -1 }

diff --git a/reedsolomon/gf_poly_test.go b/reedsolomon/gf_poly_test.go

@@ -1,182 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package reedsolomon
    5    -1 
    6    -1 import (
    7    -1 	"testing"
    8    -1 )
    9    -1 
   10    -1 func TestGFPolyAdd(t *testing.T) {
   11    -1 	// a + b == result
   12    -1 	var tests = []struct {
   13    -1 		a      gfPoly
   14    -1 		b      gfPoly
   15    -1 		result gfPoly
   16    -1 	}{
   17    -1 		{
   18    -1 			gfPoly{[]gfElement{0, 0, 0}},
   19    -1 			gfPoly{[]gfElement{0}},
   20    -1 			gfPoly{[]gfElement{}},
   21    -1 		},
   22    -1 		{
   23    -1 			gfPoly{[]gfElement{1, 0}},
   24    -1 			gfPoly{[]gfElement{1, 0}},
   25    -1 			gfPoly{[]gfElement{0, 0}},
   26    -1 		},
   27    -1 		{
   28    -1 			gfPoly{[]gfElement{0xA0, 0x80, 0xFF, 0x00}},
   29    -1 			gfPoly{[]gfElement{0x0A, 0x82}},
   30    -1 			gfPoly{[]gfElement{0xAA, 0x02, 0xFF}},
   31    -1 		},
   32    -1 	}
   33    -1 
   34    -1 	for _, test := range tests {
   35    -1 		result := gfPolyAdd(test.a, test.b)
   36    -1 
   37    -1 		if !test.result.equals(result) {
   38    -1 			t.Errorf("%s * %s != %s (got %s)\n", test.a.string(false), test.b.string(false),
   39    -1 				test.result.string(false), result.string(false))
   40    -1 		}
   41    -1 
   42    -1 		if len(result.term) > 0 && result.term[len(result.term)-1] == 0 {
   43    -1 			t.Errorf("Result's maximum term coefficient is zero")
   44    -1 		}
   45    -1 	}
   46    -1 }
   47    -1 
   48    -1 func TestGFPolyequals(t *testing.T) {
   49    -1 	// a == b if isEqual
   50    -1 	var tests = []struct {
   51    -1 		a       gfPoly
   52    -1 		b       gfPoly
   53    -1 		isEqual bool
   54    -1 	}{
   55    -1 		{
   56    -1 			gfPoly{[]gfElement{0}},
   57    -1 			gfPoly{[]gfElement{0}},
   58    -1 			true,
   59    -1 		},
   60    -1 		{
   61    -1 			gfPoly{[]gfElement{1}},
   62    -1 			gfPoly{[]gfElement{0}},
   63    -1 			false,
   64    -1 		},
   65    -1 		{
   66    -1 			gfPoly{[]gfElement{1, 0, 1, 0, 1}},
   67    -1 			gfPoly{[]gfElement{1, 0, 1, 0, 1}},
   68    -1 			true,
   69    -1 		},
   70    -1 		{
   71    -1 			gfPoly{[]gfElement{1, 0, 1}},
   72    -1 			gfPoly{[]gfElement{1, 0, 1, 0, 0}},
   73    -1 			true,
   74    -1 		},
   75    -1 	}
   76    -1 
   77    -1 	for _, test := range tests {
   78    -1 		isEqual := test.a.equals(test.b)
   79    -1 
   80    -1 		if isEqual != test.isEqual {
   81    -1 			t.Errorf("%s and %s equality is %t (got %t)\n", test.a.string(false), test.b.string(false),
   82    -1 				test.isEqual, isEqual)
   83    -1 		}
   84    -1 	}
   85    -1 }
   86    -1 
   87    -1 func TestGFPolyMultiply(t *testing.T) {
   88    -1 	// a * b == result
   89    -1 	var tests = []struct {
   90    -1 		a      gfPoly
   91    -1 		b      gfPoly
   92    -1 		result gfPoly
   93    -1 	}{
   94    -1 		{
   95    -1 			gfPoly{[]gfElement{0, 0, 1}},
   96    -1 			gfPoly{[]gfElement{9}},
   97    -1 			gfPoly{[]gfElement{0, 0, 9}},
   98    -1 		},
   99    -1 		{
  100    -1 			gfPoly{[]gfElement{0, 16, 1}},
  101    -1 			gfPoly{[]gfElement{128, 2}},
  102    -1 			gfPoly{[]gfElement{0, 232, 160, 2}},
  103    -1 		},
  104    -1 		{
  105    -1 			gfPoly{[]gfElement{254, 120, 88, 44, 11, 1}},
  106    -1 			gfPoly{[]gfElement{16, 2, 0, 51, 44}},
  107    -1 			gfPoly{[]gfElement{91, 50, 25, 184, 194, 105, 45, 244, 58, 44}},
  108    -1 		},
  109    -1 	}
  110    -1 
  111    -1 	for _, test := range tests {
  112    -1 		result := gfPolyMultiply(test.a, test.b)
  113    -1 
  114    -1 		if !test.result.equals(result) {
  115    -1 			t.Errorf("%s * %s = %s (got %s)\n",
  116    -1 				test.a.string(false),
  117    -1 				test.b.string(false),
  118    -1 				test.result.string(false),
  119    -1 				result.string(false))
  120    -1 		}
  121    -1 	}
  122    -1 }
  123    -1 
  124    -1 func TestGFPolyRemainder(t *testing.T) {
  125    -1 	// numerator / denominator == quotient + remainder.
  126    -1 	var tests = []struct {
  127    -1 		numerator   gfPoly
  128    -1 		denominator gfPoly
  129    -1 		remainder   gfPoly
  130    -1 	}{
  131    -1 		{
  132    -1 			gfPoly{[]gfElement{1}},
  133    -1 			gfPoly{[]gfElement{1}},
  134    -1 			gfPoly{[]gfElement{0}},
  135    -1 		},
  136    -1 		{
  137    -1 			gfPoly{[]gfElement{1, 0}},
  138    -1 			gfPoly{[]gfElement{1}},
  139    -1 			gfPoly{[]gfElement{0}},
  140    -1 		},
  141    -1 		{
  142    -1 			gfPoly{[]gfElement{1}},
  143    -1 			gfPoly{[]gfElement{1, 0}},
  144    -1 			gfPoly{[]gfElement{1}},
  145    -1 		},
  146    -1 		{
  147    -1 			gfPoly{[]gfElement{1, 0, 1}},
  148    -1 			gfPoly{[]gfElement{0, 1}},
  149    -1 			gfPoly{[]gfElement{1}},
  150    -1 		},
  151    -1 		// (x^12 + x^10) / (x^10 + x^8 + x^5 + x^4 + x^2 + x^1 + x^0) =
  152    -1 		//  (x^10 + x^8 + x^5 + x^4 + x^2 + x^1 + x^0) * x^2 +
  153    -1 		//  (x^7 + x^6 + x^4 + x^3 + x^2) (the remainder)
  154    -1 		{
  155    -1 			gfPoly{[]gfElement{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}},
  156    -1 			gfPoly{[]gfElement{1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1}},
  157    -1 			gfPoly{[]gfElement{0, 0, 1, 1, 1, 0, 1, 1}},
  158    -1 		},
  159    -1 		{
  160    -1 			gfPoly{[]gfElement{91, 50, 25, 184, 194, 105, 45, 244, 58, 44}},
  161    -1 			gfPoly{[]gfElement{254, 120, 88, 44, 11, 1}},
  162    -1 			gfPoly{[]gfElement{}},
  163    -1 		},
  164    -1 		{
  165    -1 			gfPoly{[]gfElement{0, 0, 0, 0, 0, 0, 195, 172, 24, 64}},
  166    -1 			gfPoly{[]gfElement{116, 147, 63, 198, 31, 1}},
  167    -1 			gfPoly{[]gfElement{48, 174, 34, 13, 134}},
  168    -1 		},
  169    -1 	}
  170    -1 
  171    -1 	for _, test := range tests {
  172    -1 		remainder := gfPolyRemainder(test.numerator, test.denominator)
  173    -1 
  174    -1 		if !test.remainder.equals(remainder) {
  175    -1 			t.Errorf("%s / %s, remainder = %s (got %s)\n",
  176    -1 				test.numerator.string(false),
  177    -1 				test.denominator.string(false),
  178    -1 				test.remainder.string(false),
  179    -1 				remainder.string(false))
  180    -1 		}
  181    -1 	}
  182    -1 }

diff --git a/reedsolomon/reed_solomon_test.go b/reedsolomon/reed_solomon_test.go

@@ -1,89 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package reedsolomon
    5    -1 
    6    -1 import (
    7    -1 	"testing"
    8    -1 
    9    -1 	bitset "github.com/skip2/go-qrcode/bitset"
   10    -1 )
   11    -1 
   12    -1 func TestGeneratorPoly(t *testing.T) {
   13    -1 	var tests = []struct {
   14    -1 		degree    int
   15    -1 		generator gfPoly
   16    -1 	}{
   17    -1 		// x^2 + 3x^1 + 2x^0 (the shortest generator poly)
   18    -1 		{
   19    -1 			2,
   20    -1 			gfPoly{term: []gfElement{2, 3, 1}},
   21    -1 		},
   22    -1 		// x^5 + 31x^4 + 198x^3 + 63x^2 + 147x^1 + 116x^0
   23    -1 		{
   24    -1 			5,
   25    -1 			gfPoly{term: []gfElement{116, 147, 63, 198, 31, 1}},
   26    -1 		},
   27    -1 		// x^68 + 131x^67 + 115x^66 + 9x^65 + 39x^64 + 18x^63 + 182x^62 + 60x^61 +
   28    -1 		// 94x^60 + 223x^59 + 230x^58 + 157x^57 + 142x^56 + 119x^55 + 85x^54 +
   29    -1 		// 107x^53 + 34x^52 + 174x^51 + 167x^50 + 109x^49 + 20x^48 + 185x^47 +
   30    -1 		// 112x^46 + 145x^45 + 172x^44 + 224x^43 + 170x^42 + 182x^41 + 107x^40 +
   31    -1 		// 38x^39 + 107x^38 + 71x^37 + 246x^36 + 230x^35 + 225x^34 + 144x^33 +
   32    -1 		// 20x^32 + 14x^31 + 175x^30 + 226x^29 + 245x^28 + 20x^27 + 219x^26 +
   33    -1 		// 212x^25 + 51x^24 + 158x^23 + 88x^22 + 63x^21 + 36x^20 + 199x^19 + 4x^18 +
   34    -1 		// 80x^17 + 157x^16 + 211x^15 + 239x^14 + 255x^13 + 7x^12 + 119x^11 + 11x^10
   35    -1 		// + 235x^9 + 12x^8 + 34x^7 + 149x^6 + 204x^5 + 8x^4 + 32x^3 + 29x^2 + 99x^1
   36    -1 		// + 11x^0 (the longest generator poly)
   37    -1 		{
   38    -1 			68,
   39    -1 			gfPoly{term: []gfElement{11, 99, 29, 32, 8, 204, 149, 34, 12,
   40    -1 				235, 11, 119, 7, 255, 239, 211, 157, 80, 4, 199, 36, 63, 88, 158, 51, 212,
   41    -1 				219, 20, 245, 226, 175, 14, 20, 144, 225, 230, 246, 71, 107, 38, 107, 182,
   42    -1 				170, 224, 172, 145, 112, 185, 20, 109, 167, 174, 34, 107, 85, 119, 142,
   43    -1 				157, 230, 223, 94, 60, 182, 18, 39, 9, 115, 131, 1}},
   44    -1 		},
   45    -1 	}
   46    -1 
   47    -1 	for _, test := range tests {
   48    -1 		generator := rsGeneratorPoly(test.degree)
   49    -1 
   50    -1 		if !generator.equals(test.generator) {
   51    -1 			t.Errorf("degree=%d generator=%s, want %s", test.degree,
   52    -1 				generator.string(true), test.generator.string(true))
   53    -1 		}
   54    -1 	}
   55    -1 }
   56    -1 
   57    -1 func TestEncode(t *testing.T) {
   58    -1 	var tests = []struct {
   59    -1 		numECBytes int
   60    -1 		data       string
   61    -1 		rsCode     string
   62    -1 	}{
   63    -1 		{
   64    -1 			5,
   65    -1 			"01000000 00011000 10101100 11000011 00000000",
   66    -1 			"01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000",
   67    -1 		},
   68    -1 		{
   69    -1 			10,
   70    -1 			"00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001",
   71    -1 			"00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 10100101 00100100 11010100 11000001 11101101 00110110 11000111 10000111 00101100 01010101",
   72    -1 		},
   73    -1 	}
   74    -1 
   75    -1 	for _, test := range tests {
   76    -1 		data := bitset.NewFromBase2String(test.data)
   77    -1 		rsCode := bitset.NewFromBase2String(test.rsCode)
   78    -1 
   79    -1 		result := Encode(data, test.numECBytes)
   80    -1 
   81    -1 		if !rsCode.Equals(result) {
   82    -1 			t.Errorf("data=%s, numECBytes=%d, encoded=%s, want %s",
   83    -1 				data.String(),
   84    -1 				test.numECBytes,
   85    -1 				result.String(),
   86    -1 				rsCode)
   87    -1 		}
   88    -1 	}
   89    -1 }

diff --git a/regular_symbol_test.go b/regular_symbol_test.go

@@ -1,31 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import (
    7    -1 	"fmt"
    8    -1 	"testing"
    9    -1 
   10    -1 	bitset "github.com/skip2/go-qrcode/bitset"
   11    -1 )
   12    -1 
   13    -1 func TestBuildRegularSymbol(t *testing.T) {
   14    -1 	for k := 0; k <= 7; k++ {
   15    -1 		v := getQRCodeVersion(Low, 1)
   16    -1 
   17    -1 		data := bitset.New()
   18    -1 		for i := 0; i < 26; i++ {
   19    -1 			data.AppendNumBools(8, false)
   20    -1 		}
   21    -1 
   22    -1 		s, err := buildRegularSymbol(*v, k, data, false)
   23    -1 
   24    -1 		if err != nil {
   25    -1 			fmt.Println(err.Error())
   26    -1 		} else {
   27    -1 			_ = s
   28    -1 			//fmt.Print(m.string())
   29    -1 		}
   30    -1 	}
   31    -1 }

diff --git a/symbol_test.go b/symbol_test.go

@@ -1,334 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import "testing"
    7    -1 
    8    -1 func TestSymbolBasic(t *testing.T) {
    9    -1 	size := 10
   10    -1 	quietZoneSize := 4
   11    -1 
   12    -1 	m := newSymbol(size, quietZoneSize)
   13    -1 
   14    -1 	if m.size != size+quietZoneSize*2 {
   15    -1 		t.Errorf("Symbol size is %d, expected %d", m.size, size+quietZoneSize*2)
   16    -1 	}
   17    -1 
   18    -1 	for i := 0; i < size; i++ {
   19    -1 		for j := 0; j < size; j++ {
   20    -1 
   21    -1 			v := m.get(i, j)
   22    -1 
   23    -1 			if v != false {
   24    -1 				t.Errorf("New symbol not empty")
   25    -1 			}
   26    -1 
   27    -1 			if !m.empty(i, j) {
   28    -1 				t.Errorf("New symbol is not empty")
   29    -1 			}
   30    -1 
   31    -1 			value := i*j%2 == 0
   32    -1 			m.set(i, j, value)
   33    -1 
   34    -1 			v = m.get(i, j)
   35    -1 
   36    -1 			if v != value {
   37    -1 				t.Errorf("Symbol ignores set bits")
   38    -1 			}
   39    -1 
   40    -1 			if m.empty(i, j) {
   41    -1 				t.Errorf("Symbol ignores set bits")
   42    -1 			}
   43    -1 		}
   44    -1 	}
   45    -1 }
   46    -1 
   47    -1 func TestSymbolPenalties(t *testing.T) {
   48    -1 	tests := []struct {
   49    -1 		pattern          [][]bool
   50    -1 		expectedPenalty1 int
   51    -1 		expectedPenalty2 int
   52    -1 		expectedPenalty3 int
   53    -1 		expectedPenalty4 int
   54    -1 	}{
   55    -1 		{
   56    -1 			[][]bool{
   57    -1 				{b0, b1, b0, b1, b0, b1},
   58    -1 				{b1, b0, b1, b0, b1, b0},
   59    -1 				{b0, b1, b0, b1, b0, b1},
   60    -1 				{b1, b0, b1, b0, b1, b0},
   61    -1 				{b0, b1, b0, b1, b0, b1},
   62    -1 				{b1, b0, b1, b0, b1, b0},
   63    -1 			},
   64    -1 			0, // No adjacent modules of same color.
   65    -1 			0, // No 2x2+ sized blocks.
   66    -1 			0, // No 1:1:3:1:1 pattern.
   67    -1 			-1,
   68    -1 		},
   69    -1 		{
   70    -1 			[][]bool{
   71    -1 				{b0, b0, b0, b1, b0, b1},
   72    -1 				{b1, b0, b1, b0, b1, b0},
   73    -1 				{b0, b1, b0, b1, b0, b1},
   74    -1 				{b1, b0, b1, b0, b1, b0},
   75    -1 				{b0, b1, b0, b1, b0, b1},
   76    -1 				{b1, b0, b1, b0, b1, b0},
   77    -1 			},
   78    -1 			0, // 5 adjacent modules of same colour, score = 0.
   79    -1 			0, // No 2x2+ sized blocks.
   80    -1 			0, // No 1:1:3:1:1 pattern.
   81    -1 			-1,
   82    -1 		},
   83    -1 		{
   84    -1 			[][]bool{
   85    -1 				{b0, b0, b0, b0, b0, b0},
   86    -1 				{b1, b0, b1, b0, b1, b0},
   87    -1 				{b0, b1, b0, b1, b0, b1},
   88    -1 				{b1, b0, b1, b0, b1, b0},
   89    -1 				{b0, b1, b0, b1, b0, b1},
   90    -1 				{b1, b0, b1, b0, b1, b0},
   91    -1 			},
   92    -1 			4, // 6 adjacent modules of same colour, score = 3 + (6-5)
   93    -1 			0, // No 2x2+ sized blocks.
   94    -1 			0, // No 1:1:3:1:1 pattern.
   95    -1 			-1,
   96    -1 		},
   97    -1 		{
   98    -1 			[][]bool{
   99    -1 				{b0, b0, b0, b0, b0, b0, b0},
  100    -1 				{b1, b0, b1, b0, b1, b0, b1},
  101    -1 				{b1, b0, b0, b0, b0, b0, b1},
  102    -1 				{b1, b0, b1, b0, b1, b0, b1},
  103    -1 				{b1, b0, b0, b0, b0, b0, b1},
  104    -1 				{b1, b0, b1, b0, b1, b0, b1},
  105    -1 				{b1, b0, b0, b0, b0, b0, b0},
  106    -1 			},
  107    -1 			28, // 3+(7-5) + 3+(6-5) + 3+(6-5) + 3+(6-5) + 3+(7-5) + 3+(7-5) = 28
  108    -1 			0,  // No 2x2+ sized blocks.
  109    -1 			0,  // No 1:1:3:1:1 pattern.
  110    -1 			-1,
  111    -1 		},
  112    -1 		{
  113    -1 			[][]bool{
  114    -1 				{b0, b0, b0, b1, b0, b1},
  115    -1 				{b0, b0, b1, b0, b1, b0},
  116    -1 				{b0, b1, b0, b1, b0, b1},
  117    -1 				{b1, b0, b1, b1, b1, b0},
  118    -1 				{b0, b1, b1, b1, b0, b1},
  119    -1 				{b1, b0, b1, b0, b1, b0},
  120    -1 			},
  121    -1 			-1,
  122    -1 			6, // 3*(2-1)*(2-1) + 3(2-1)*(2-1)
  123    -1 			0, // No 1:1:3:1:1 pattern.
  124    -1 			-1,
  125    -1 		},
  126    -1 		{
  127    -1 			[][]bool{
  128    -1 				{b0, b0, b0, b0, b0, b1},
  129    -1 				{b0, b0, b0, b0, b0, b1},
  130    -1 				{b0, b0, b0, b0, b0, b1},
  131    -1 				{b0, b0, b0, b0, b0, b1},
  132    -1 				{b0, b0, b0, b0, b0, b1},
  133    -1 				{b0, b0, b0, b0, b0, b1},
  134    -1 			},
  135    -1 			-1,
  136    -1 			60, // 3 * (5-1) * (6-1)
  137    -1 			0,  // No 1:1:3:1:1 pattern.
  138    -1 			-1,
  139    -1 		},
  140    -1 		{
  141    -1 			[][]bool{
  142    -1 				{b0, b0, b0, b0, b0, b1},
  143    -1 				{b0, b0, b0, b0, b0, b1},
  144    -1 				{b1, b1, b0, b1, b0, b1},
  145    -1 				{b1, b1, b0, b1, b0, b1},
  146    -1 				{b1, b1, b0, b1, b0, b1},
  147    -1 				{b1, b1, b0, b1, b0, b1},
  148    -1 			},
  149    -1 			-1,
  150    -1 			21, // 3*(5-1)*(2-1) + 3*(2-1)*(4-1) = 3*4 + 3*3
  151    -1 			0,  // No 1:1:3:1:1 pattern.
  152    -1 			-1,
  153    -1 		},
  154    -1 		{
  155    -1 			[][]bool{
  156    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  157    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  158    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  159    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  160    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  161    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  162    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  163    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  164    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  165    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  166    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  167    -1 				{b0, b0, b0, b0, b1, b0, b1, b1, b1, b0, b1, b0},
  168    -1 			},
  169    -1 			-1,
  170    -1 			-1,
  171    -1 			480, // 12* 1:1:3:1:1 patterns, 12 * 40.
  172    -1 			-1,
  173    -1 		},
  174    -1 		{
  175    -1 			[][]bool{
  176    -1 				{b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  177    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  178    -1 				{b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  179    -1 				{b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  180    -1 				{b1, b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  181    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  182    -1 				{b1, b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  183    -1 				{b0, b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  184    -1 				{b0, b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  185    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  186    -1 				{b0, b1, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  187    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  188    -1 			},
  189    -1 			-1,
  190    -1 			-1,
  191    -1 			80, // 2* 1:1:3:1:1 patterns, 2 * 40.
  192    -1 			-1,
  193    -1 		},
  194    -1 		{
  195    -1 			[][]bool{
  196    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  197    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  198    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  199    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  200    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  201    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  202    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  203    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  204    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  205    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  206    -1 			},
  207    -1 			-1,
  208    -1 			-1,
  209    -1 			-1,
  210    -1 			100, // 10 * (10 steps of 5% deviation from 50% black/white).
  211    -1 		},
  212    -1 		{
  213    -1 			[][]bool{
  214    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  215    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  216    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  217    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  218    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  219    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  220    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  221    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  222    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  223    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  224    -1 			},
  225    -1 			-1,
  226    -1 			-1,
  227    -1 			-1,
  228    -1 			100, // 10 * (10 steps of 5% deviation from 50% black/white).
  229    -1 		},
  230    -1 		{
  231    -1 			[][]bool{
  232    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  233    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  234    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  235    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  236    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  237    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  238    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  239    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  240    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  241    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  242    -1 			},
  243    -1 			-1,
  244    -1 			-1,
  245    -1 			-1,
  246    -1 			0, // Exactly 50%/50% black/white.
  247    -1 		},
  248    -1 		{
  249    -1 			[][]bool{
  250    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  251    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  252    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  253    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  254    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  255    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  256    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  257    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  258    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  259    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  260    -1 			},
  261    -1 			-1,
  262    -1 			-1,
  263    -1 			-1,
  264    -1 			20, // 10 * (2 steps of 5% deviation towards white).
  265    -1 		},
  266    -1 		{
  267    -1 			[][]bool{
  268    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  269    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  270    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  271    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  272    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  273    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  274    -1 				{b0, b0, b0, b0, b0, b0, b1, b1, b1, b1},
  275    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  276    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  277    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  278    -1 			},
  279    -1 			-1,
  280    -1 			-1,
  281    -1 			-1,
  282    -1 			30, // 10 * (3 steps of 5% deviation towards white).
  283    -1 		},
  284    -1 		{
  285    -1 			[][]bool{
  286    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  287    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  288    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  289    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  290    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  291    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b0},
  292    -1 				{b0, b0, b0, b0, b0, b0, b0, b0, b0, b1},
  293    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  294    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  295    -1 				{b1, b1, b1, b1, b1, b1, b1, b1, b1, b1},
  296    -1 			},
  297    -1 			-1,
  298    -1 			-1,
  299    -1 			-1,
  300    -1 			30, // 10 * (3 steps of 5% deviation towards white).
  301    -1 		},
  302    -1 	}
  303    -1 
  304    -1 	for i, test := range tests {
  305    -1 		s := newSymbol(len(test.pattern[0]), 4)
  306    -1 		s.set2dPattern(0, 0, test.pattern)
  307    -1 
  308    -1 		penalty1 := s.penalty1()
  309    -1 		penalty2 := s.penalty2()
  310    -1 		penalty3 := s.penalty3()
  311    -1 		penalty4 := s.penalty4()
  312    -1 
  313    -1 		ok := true
  314    -1 
  315    -1 		if test.expectedPenalty1 != -1 && test.expectedPenalty1 != penalty1 {
  316    -1 			ok = false
  317    -1 		}
  318    -1 		if test.expectedPenalty2 != -1 && test.expectedPenalty2 != penalty2 {
  319    -1 			ok = false
  320    -1 		}
  321    -1 		if test.expectedPenalty3 != -1 && test.expectedPenalty3 != penalty3 {
  322    -1 			ok = false
  323    -1 		}
  324    -1 		if test.expectedPenalty4 != -1 && test.expectedPenalty4 != penalty4 {
  325    -1 			ok = false
  326    -1 		}
  327    -1 
  328    -1 		if !ok {
  329    -1 			t.Fatalf("Penalty test #%d p1=%d, p2=%d, p3=%d, p4=%d (expected p1=%d, p2=%d, p3=%d, p4=%d)", i, penalty1, penalty2, penalty3, penalty4,
  330    -1 				test.expectedPenalty1, test.expectedPenalty2, test.expectedPenalty3,
  331    -1 				test.expectedPenalty4)
  332    -1 		}
  333    -1 	}
  334    -1 }

diff --git a/version_test.go b/version_test.go

@@ -1,158 +0,0 @@
    1    -1 // go-qrcode
    2    -1 // Copyright 2014 Tom Harwood
    3    -1 
    4    -1 package qrcode
    5    -1 
    6    -1 import (
    7    -1 	"testing"
    8    -1 
    9    -1 	bitset "github.com/skip2/go-qrcode/bitset"
   10    -1 )
   11    -1 
   12    -1 func TestFormatInfo(t *testing.T) {
   13    -1 	tests := []struct {
   14    -1 		level       RecoveryLevel
   15    -1 		maskPattern int
   16    -1 
   17    -1 		expected uint32
   18    -1 	}{
   19    -1 		{ // L=01 M=00 Q=11 H=10
   20    -1 			Low,
   21    -1 			1,
   22    -1 			0x72f3,
   23    -1 		},
   24    -1 		{
   25    -1 			Medium,
   26    -1 			2,
   27    -1 			0x5e7c,
   28    -1 		},
   29    -1 		{
   30    -1 			High,
   31    -1 			3,
   32    -1 			0x3a06,
   33    -1 		},
   34    -1 		{
   35    -1 			Highest,
   36    -1 			4,
   37    -1 			0x0762,
   38    -1 		},
   39    -1 		{
   40    -1 			Low,
   41    -1 			5,
   42    -1 			0x6318,
   43    -1 		},
   44    -1 		{
   45    -1 			Medium,
   46    -1 			6,
   47    -1 			0x4f97,
   48    -1 		},
   49    -1 		{
   50    -1 			High,
   51    -1 			7,
   52    -1 			0x2bed,
   53    -1 		},
   54    -1 	}
   55    -1 
   56    -1 	for i, test := range tests {
   57    -1 		v := getQRCodeVersion(test.level, 1)
   58    -1 
   59    -1 		result := v.formatInfo(test.maskPattern)
   60    -1 
   61    -1 		expected := bitset.New()
   62    -1 		expected.AppendUint32(test.expected, formatInfoLengthBits)
   63    -1 
   64    -1 		if !expected.Equals(result) {
   65    -1 			t.Errorf("formatInfo test #%d got %s, expected %s", i, result.String(),
   66    -1 				expected.String())
   67    -1 		}
   68    -1 	}
   69    -1 }
   70    -1 
   71    -1 func TestVersionInfo(t *testing.T) {
   72    -1 	tests := []struct {
   73    -1 		version  int
   74    -1 		expected uint32
   75    -1 	}{
   76    -1 		{
   77    -1 			7,
   78    -1 			0x007c94,
   79    -1 		},
   80    -1 		{
   81    -1 			10,
   82    -1 			0x00a4d3,
   83    -1 		},
   84    -1 		{
   85    -1 			20,
   86    -1 			0x0149a6,
   87    -1 		},
   88    -1 		{
   89    -1 			30,
   90    -1 			0x01ed75,
   91    -1 		},
   92    -1 		{
   93    -1 			40,
   94    -1 			0x028c69,
   95    -1 		},
   96    -1 	}
   97    -1 
   98    -1 	for i, test := range tests {
   99    -1 		var v *qrCodeVersion
  100    -1 
  101    -1 		v = getQRCodeVersion(Low, test.version)
  102    -1 
  103    -1 		result := v.versionInfo()
  104    -1 
  105    -1 		expected := bitset.New()
  106    -1 		expected.AppendUint32(test.expected, versionInfoLengthBits)
  107    -1 
  108    -1 		if !expected.Equals(result) {
  109    -1 			t.Errorf("versionInfo test #%d got %s, expected %s", i, result.String(),
  110    -1 				expected.String())
  111    -1 		}
  112    -1 	}
  113    -1 }
  114    -1 
  115    -1 func TestNumBitsToPadToCodeoword(t *testing.T) {
  116    -1 	tests := []struct {
  117    -1 		level   RecoveryLevel
  118    -1 		version int
  119    -1 
  120    -1 		numDataBits int
  121    -1 		expected    int
  122    -1 	}{
  123    -1 		{
  124    -1 			Low,
  125    -1 			1,
  126    -1 			0,
  127    -1 			0,
  128    -1 		}, {
  129    -1 			Low,
  130    -1 			1,
  131    -1 			1,
  132    -1 			7,
  133    -1 		}, {
  134    -1 			Low,
  135    -1 			1,
  136    -1 			7,
  137    -1 			1,
  138    -1 		}, {
  139    -1 			Low,
  140    -1 			1,
  141    -1 			8,
  142    -1 			0,
  143    -1 		},
  144    -1 	}
  145    -1 
  146    -1 	for i, test := range tests {
  147    -1 		var v *qrCodeVersion
  148    -1 
  149    -1 		v = getQRCodeVersion(test.level, test.version)
  150    -1 
  151    -1 		result := v.numBitsToPadToCodeword(test.numDataBits)
  152    -1 
  153    -1 		if result != test.expected {
  154    -1 			t.Errorf("numBitsToPadToCodeword test %d (version=%d numDataBits=%d), got %d, expected %d",
  155    -1 				i, test.version, test.numDataBits, result, test.expected)
  156    -1 		}
  157    -1 	}
  158    -1 }