private void TestPenaltyRule(BitMatrix input, PenaltyRules penaltyRule, int expected) { Penalty penalty = new PenaltyFactory().CreateByRule(penaltyRule); int result = penalty.PenaltyCalculate(input); AssertIntEquals(expected, result, input, penaltyRule); }
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]); }