skip2 / go-qrcode

:sparkles: QR Code encoder (Go)
http://go-qrcode.appspot.com
MIT License
2.64k stars 338 forks source link

Mistake in gf_poly_test.go? #27

Closed enzoh closed 4 years ago

enzoh commented 4 years ago

Apologies in advance if I have misread your code. I was looking at test case #3 for TestGFPolyRemainder with

numerator = gfPoly{[]gfElement{1}},
denominator = gfPoly{[]gfElement{1, 0}}
remainder = gfPoly{[]gfElement{1}}

where coefficients are of the form a0 + a1 x + a2 x^2 + a3 x^3... I read this test case as 1 mod (1 + 0 * x) = 1 mod 1 = 0 != 1 Did you mean to write remainder = gfPoly{[]gfElement{0}}?

skip2 commented 4 years ago

Hello :)

I think you're correct. The gfPolyRemainder() code expects the []gfElement{}s to be specified in our "normalised" form, that is, the last coefficient should be 1, not 0. This allows for easy determining of the degree of the polynomial. The test violates this assumption, and also has the wrong answer.

I've fixed this in f7f7eae5c66797549ecc55be0144bf46bccdfc92 .The qrcode library should be only using normalised form anyway. I'll have a look around to see if any other similar cases need fixing.

thanks!