Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdf417/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func getLeftCodeWord(rowNum int, rows int, columns int, securityLevel byte) int

switch tableId {
case 0:
x = (rows - 3) / 3
x = (rows - 1) / 3
case 1:
x = int(securityLevel) * 3
x += (rows - 1) % 3
Expand Down
43 changes: 43 additions & 0 deletions pdf417/encoder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pdf417

import "testing"

func TestRowIndicatorCodewords(t *testing.T) {
tests := []struct {
name string
rowNum int
rows int
columns int
securityLevel byte
wantLeft int
wantRight int
}{
{"table0/group0", 0, 17, 6, 3, 5, 5},
{"table1/group0", 1, 17, 6, 3, 10, 5},
{"table2/group0", 2, 17, 6, 3, 5, 10},
{"table0/group1", 3, 17, 6, 3, 35, 35},
{"table1/group1", 4, 17, 6, 3, 40, 35},
{"table2/group1", 5, 17, 6, 3, 35, 40},
{"table1/group5", 16, 17, 6, 3, 160, 155},
{"table0/rowsMod1", 0, 16, 6, 3, 5, 5},
{"table0/maxParams", 0, maxRows, maxCols, 8, 9, 29},
{"table1/maxParams", 1, maxRows, maxCols, 8, 26, 9},
{"table2/maxParams", 2, maxRows, maxCols, 8, 29, 26},
{"table0/lastRow", maxRows - 3, maxRows, maxCols, 8, 279, 299},
{"table1/lastRow", maxRows - 2, maxRows, maxCols, 8, 296, 279},
{"table2/lastRow", maxRows - 1, maxRows, maxCols, 8, 299, 296},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getLeftCodeWord(tt.rowNum, tt.rows, tt.columns, tt.securityLevel); got != tt.wantLeft {
t.Errorf("getLeftCodeWord(rowNum=%d, rows=%d, columns=%d, securityLevel=%d) = %d, want %d",
tt.rowNum, tt.rows, tt.columns, tt.securityLevel, got, tt.wantLeft)
}
if got := getRightCodeWord(tt.rowNum, tt.rows, tt.columns, tt.securityLevel); got != tt.wantRight {
t.Errorf("getRightCodeWord(rowNum=%d, rows=%d, columns=%d, securityLevel=%d) = %d, want %d",
tt.rowNum, tt.rows, tt.columns, tt.securityLevel, got, tt.wantRight)
}
})
}
}
Loading