public void testApplyMaskPenaltyRule2() { var matrix = new ByteMatrix(1, 1); matrix.set(0, 0, 0); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 1); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(3, 3); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); matrix.set(2, 1, 0); matrix.set(0, 2, 0); matrix.set(1, 2, 0); matrix.set(2, 2, 0); // Four instances of 2x2 blocks. Assert.AreEqual(3 * 4, MaskUtil.applyMaskPenaltyRule2(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))); }