public void testApplyMaskPenaltyRule4() { { // Dark cell ratio = 0% ByteMatrix matrix = new ByteMatrix(1, 1); matrix.set(0, 0, 0); Assert.AreEqual(100, MaskUtil.applyMaskPenaltyRule4(matrix)); } { // Dark cell ratio = 5% ByteMatrix matrix = new ByteMatrix(2, 1); matrix.set(0, 0, 0); matrix.set(0, 0, 1); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule4(matrix)); } { // Dark cell ratio = 66.67% ByteMatrix matrix = new ByteMatrix(6, 1); matrix.set(0, 0, 0); matrix.set(1, 0, 1); matrix.set(2, 0, 1); matrix.set(3, 0, 1); matrix.set(4, 0, 1); matrix.set(5, 0, 0); Assert.AreEqual(30, MaskUtil.applyMaskPenaltyRule4(matrix)); } }
public void PerformanceTest(int rules, ByteMatrix bMatrix, BitMatrix bitMatrix) { Stopwatch sw = new Stopwatch(); int timesofTest = 1000; Penalty penalty = new PenaltyFactory().CreateByRule((PenaltyRules)rules); string[] timeElapsed = new string[2]; sw.Start(); for (int i = 0; i < timesofTest; i++) { penalty.PenaltyCalculate(bitMatrix); } sw.Stop(); timeElapsed[0] = sw.ElapsedMilliseconds.ToString(); sw.Reset(); sw.Start(); for (int i = 0; i < timesofTest; i++) { switch (rules) { case 1: MaskUtil.applyMaskPenaltyRule1(bMatrix); break; case 2: MaskUtil.applyMaskPenaltyRule2(bMatrix); break; case 3: MaskUtil.applyMaskPenaltyRule3(bMatrix); break; case 4: MaskUtil.applyMaskPenaltyRule4(bMatrix); break; default: throw new InvalidOperationException(string.Format("Unsupport Rules {0}", rules.ToString())); } } sw.Stop(); timeElapsed[1] = sw.ElapsedMilliseconds.ToString(); Assert.Pass("Terminator performance {0} Tests~ QrCode.Net: {1} ZXing: {2}", timesofTest, timeElapsed[0], timeElapsed[1]); }
protected virtual TestCaseData GenerateRandomTestCaseData(int matrixSize, Random randomizer, MaskPatternType pattern, PenaltyRules rules) { ByteMatrix matrix; BitMatrix bitmatrix = GetOriginal(matrixSize, randomizer, out matrix); ApplyPattern(matrix, (int)pattern); int expect; switch (rules) { case PenaltyRules.Rule01: expect = MaskUtil.applyMaskPenaltyRule1(matrix); break; case PenaltyRules.Rule02: expect = MaskUtil.applyMaskPenaltyRule2(matrix); break; case PenaltyRules.Rule03: expect = MaskUtil.applyMaskPenaltyRule3(matrix); break; case PenaltyRules.Rule04: expect = MaskUtil.applyMaskPenaltyRule4(matrix); break; default: throw new InvalidOperationException(string.Format("Unsupport Rules {0}", rules.ToString())); } BitMatrix input = matrix.ToBitMatrix(); return(new TestCaseData(input, (int)rules, expect).SetName(string.Format(s_TestNameFormat, input.Width, rules.ToString(), expect))); }