mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Issue 886 updating failing actionscript core test
git-svn-id: https://zxing.googlecode.com/svn/trunk@1844 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
0ab511d129
commit
4e9c7e16c0
|
@ -69,17 +69,20 @@ package com.google.zxing {
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test(description="Encode a number, decode it, and compare.")]
|
[Test(description="Encode a number, decode it, and compare.")]
|
||||||
public function encodedEAN8shouldBeDecodedSuccessfully():void {
|
public function testEncodedEAN8shouldBeDecodedSuccessfully():void {
|
||||||
var testCode:Number = 48512343;
|
var testCode:Number = 48512343;
|
||||||
var decodedNumber:Number = encodeAndDecode(testCode);
|
var decodedNumber:Number = encodeAndDecode(testCode);
|
||||||
assertEquals(testCode, decodedNumber);
|
assertEquals(testCode, decodedNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test(description="Bug: Endoding and decoding 1 fails")]
|
[Test(description="Encodes EAN8 from 0 to 9999999.")]
|
||||||
public function shouldEncodeAndDecodeAnyValidEAN8number():void {
|
public function testEncodeAndDecodeAnyValidEAN8Number():void {
|
||||||
var testCode:Number = 12345678;
|
for (var testCode:Number = 9999999; testCode >= 0; testCode -= 1111111) {
|
||||||
var decodedNumber:Number = encodeAndDecode(testCode);
|
var checkSum:Number = calculateEANChecksumDigit(testCode);
|
||||||
assertEquals(testCode, decodedNumber);
|
var testCodeWithCheckSum:Number = testCode * 10 + checkSum;
|
||||||
|
var decodedNumber:Number = encodeAndDecode(testCodeWithCheckSum);
|
||||||
|
assertEquals(testCodeWithCheckSum, decodedNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function encodeAndDecode(testCode:Number):Number {
|
private function encodeAndDecode(testCode:Number):Number {
|
||||||
|
@ -125,7 +128,6 @@ package com.google.zxing {
|
||||||
|
|
||||||
private function generateImage(resultBits:Array, imageWidth:Number,
|
private function generateImage(resultBits:Array, imageWidth:Number,
|
||||||
imageHeight:Number):Bitmap {
|
imageHeight:Number):Bitmap {
|
||||||
// generate an image
|
|
||||||
var bitmapData:BitmapData = new BitmapData(imageWidth, imageHeight, false,
|
var bitmapData:BitmapData = new BitmapData(imageWidth, imageHeight, false,
|
||||||
0xFFFFFF);
|
0xFFFFFF);
|
||||||
var bitmap:Bitmap = new Bitmap(bitmapData);
|
var bitmap:Bitmap = new Bitmap(bitmapData);
|
||||||
|
@ -176,5 +178,22 @@ package com.google.zxing {
|
||||||
}
|
}
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function calculateEANChecksumDigit(number:Number):Number {
|
||||||
|
var checksum:Number = 0;
|
||||||
|
var weightedSumOfDigits:Number = 0;
|
||||||
|
var weight:Number = 3;
|
||||||
|
while (number > 0) {
|
||||||
|
var lastDigit:int = number % 10;
|
||||||
|
weightedSumOfDigits = weightedSumOfDigits + lastDigit * weight;
|
||||||
|
number = (number - lastDigit) / 10;
|
||||||
|
weight = weight == 3 ? 1 : 3;
|
||||||
|
}
|
||||||
|
var additionToTen:Number = weightedSumOfDigits % 10;
|
||||||
|
if (additionToTen > 0) {
|
||||||
|
checksum = 10 - additionToTen;
|
||||||
|
}
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue