浏览代码

Test data type optimisation close to the maximum encodable limit of 2953 bytes.

Tom Harwood 11 年之前
父节点
当前提交
f7be08535c
共有 2 个文件被更改,包括 32 次插入11 次删除
  1. 16 1
      encoder_test.go
  2. 16 10
      qrcode_test.go

+ 16 - 1
encoder_test.go

@@ -144,7 +144,6 @@ type testModeSegment struct {
 }
 
 func TestOptimiseEncoding(t *testing.T) {
-
 	tests := []struct {
 		dataEncoderType dataEncoderType
 		actual          []testModeSegment
@@ -221,6 +220,22 @@ func TestOptimiseEncoding(t *testing.T) {
 				{dataModeAlphanumeric, 26},
 			},
 		},
+		{
+			dataEncoderType27To40,
+			[]testModeSegment{
+				{dataModeByte, 1},
+				{dataModeNumeric, 1},
+				{dataModeByte, 1},
+				{dataModeNumeric, 1},
+				{dataModeByte, 1},
+				{dataModeNumeric, 1},
+				{dataModeByte, 1},
+				{dataModeNumeric, 1},
+			},
+			[]testModeSegment{
+				{dataModeByte, 8},
+			},
+		},
 	}
 
 	for _, test := range tests {

+ 16 - 10
qrcode_test.go

@@ -14,37 +14,43 @@ func TestQRCodeMaxCapacity(t *testing.T) {
 	}
 
 	tests := []struct {
-		char     byte
-		maxChars int
+		string string
+		numRepetitions int
 	}{
 		{
-			'0',
+			"0",
 			7089,
 		},
 		{
-			'A',
+			"A",
 			4296,
 		},
 		{
-			'#',
+			"#",
 			2953,
 		},
+		// Alternate byte/numeric data types. Optimises to 2,952 bytes.
+		{
+			"#1",
+			1476,
+		},
 	}
 
 	for _, test := range tests {
-		_, err := New(strings.Repeat(string(test.char), test.maxChars), Low)
+		_, err := New(strings.Repeat(test.string, test.numRepetitions), Low)
 
 		if err != nil {
-			t.Errorf("%d x '%c' got %s expected success", test.maxChars, test.char, err.Error())
+			t.Errorf("%d x '%s' got %s expected success", test.numRepetitions,
+				test.string, err.Error())
 		}
 	}
 
 	for _, test := range tests {
-		_, err := New(strings.Repeat(string(test.char), test.maxChars+1), Low)
+		_, err := New(strings.Repeat(test.string, test.numRepetitions+1), Low)
 
 		if err == nil {
-			t.Errorf("%d x '%c' chars encodable, expected not encodable",
-				test.maxChars+1, test.char)
+			t.Errorf("%d x '%s' chars encodable, expected not encodable",
+				test.numRepetitions+1, test.string)
 		}
 	}
 }