git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/datamatrix/errorcorrection_test.go (about)

     1  package datamatrix
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func Test_CalcECC(t *testing.T) {
     9  	data := []byte{142, 164, 186}
    10  	var size *dmCodeSize = nil
    11  	for _, s := range codeSizes {
    12  		if s.DataCodewords() >= len(data) {
    13  			size = s
    14  			break
    15  		}
    16  	}
    17  	if size == nil {
    18  		t.Error("size not found")
    19  	}
    20  
    21  	if bytes.Compare(ec.calcECC(data, size), []byte{142, 164, 186, 114, 25, 5, 88, 102}) != 0 {
    22  		t.Error("ECC Test 1 failed")
    23  	}
    24  	data = []byte{66, 129, 70}
    25  	if bytes.Compare(ec.calcECC(data, size), []byte{66, 129, 70, 138, 234, 82, 82, 95}) != 0 {
    26  		t.Error("ECC Test 2 failed")
    27  	}
    28  }