File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,8 +86,10 @@ def calculate_checksum(self) -> int:
8686 def sum_ (x , y ):
8787 return int (x ) + int (y )
8888
89- evensum = reduce (sum_ , self .ean [- 2 ::- 2 ])
90- oddsum = reduce (sum_ , self .ean [- 1 ::- 2 ])
89+ ean_without_checksum = self .ean [: self .digits ]
90+
91+ evensum = reduce (sum_ , ean_without_checksum [- 2 ::- 2 ])
92+ oddsum = reduce (sum_ , ean_without_checksum [- 1 ::- 2 ])
9193 return (10 - ((evensum + oddsum * 3 ) % 10 )) % 10
9294
9395 def build (self ):
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from barcode .ean import EAN13
4+
5+
6+ def test_ean_checksum () -> None :
7+ ean = EAN13 ("842169142322" ) # input has 12 digits
8+ assert ean .calculate_checksum () == 0
9+
10+ ean = EAN13 ("8421691423220" ) # input has 13 digits
11+ assert ean .calculate_checksum () == 0
You can’t perform that action at this time.
0 commit comments