コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: PenaltyTestBase.cs プロジェクト: fengdc/QrCode.Net
		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);
		}
コード例 #4
0
ファイル: PenaltyTestBase.cs プロジェクト: fengdc/QrCode.Net
		protected static void AssertIntEquals(int expected, int actual, BitMatrix matrix, PenaltyRules penaltyRule)
        {
			if(expected != actual)
			{
				GenerateFaultyRecord(matrix, penaltyRule, expected, actual);
				Assert.Fail("Penalty scores are different.\nExpected:{0}Actual:{1}.", expected.ToString(), actual.ToString());
				
			}
		}
コード例 #5
0
 internal Penalty CreateByRule(PenaltyRules penaltyRule)
 {
     return(penaltyRule switch
     {
         PenaltyRules.Rule01 => new Penalty1(),
         PenaltyRules.Rule02 => new Penalty2(),
         PenaltyRules.Rule03 => new Penalty3(),
         PenaltyRules.Rule04 => new Penalty4(),
         _ => throw new ArgumentException($"Unsupport penalty rule: {penaltyRule}", nameof(penaltyRule))
     });
コード例 #6
0
        internal Penalty CreateByRule(PenaltyRules penaltyRule)
        {
            switch(penaltyRule)
            {
                case PenaltyRules.Rule01:
                    return new Penalty1();
                case PenaltyRules.Rule02:
                    return new Penalty2();
                case PenaltyRules.Rule03:
                    return new Penalty3();
                case PenaltyRules.Rule04:
                    return new Penalty4();
                default:
                    throw new ArgumentException(string.Format("Unsupport penalty rule : {0}", penaltyRule), "penaltyRule");

            }
        }
コード例 #7
0
        internal Penalty CreateByRule(PenaltyRules penaltyRule)
        {
            switch (penaltyRule)
            {
            case PenaltyRules.Rule01:
                return(new Penalty1());

            case PenaltyRules.Rule02:
                return(new Penalty2());

            case PenaltyRules.Rule03:
                return(new Penalty3());

            case PenaltyRules.Rule04:
                return(new Penalty4());

            default:
                throw new ArgumentException(string.Format("Unsupport penalty rule : {0}", penaltyRule), "penaltyRule");
            }
        }
コード例 #8
0
        internal Penalty CreateByRule(PenaltyRules penaltyRule)
        {
            switch (penaltyRule)
            {
            case PenaltyRules.Rule01:
                return(new Penalty1());

            case PenaltyRules.Rule02:
                return(new Penalty2());

            case PenaltyRules.Rule03:
                return(new Penalty3());

            case PenaltyRules.Rule04:
                return(new Penalty4());

            default:
                throw new ArgumentException($"Unsupport penalty rule : {penaltyRule}", nameof(penaltyRule));
            }
        }
コード例 #9
0
        public static void GenerateFaultyRecord(BitMatrix matrix, PenaltyRules penaltyRule, int expected, int actual)
        {
            string path = Path.Combine(Path.GetTempPath(), s_TxtFileName);

            if (!File.Exists(path))
            {
                using (StreamWriter file = File.CreateText(path))
                {
                    file.WriteLine();
                }
            }

            using (var file = File.AppendText(path))
            {
                file.Write(penaltyRule.ToString());
                file.Write(string.Format(" Expected: {0}, Actual: {0}", expected.ToString(), actual.ToString()));
                matrix.ToGraphic(file);
                file.WriteLine("=====");
                file.Close();
            }
        }
コード例 #10
0
ファイル: PenaltyTestBase.cs プロジェクト: fengdc/QrCode.Net
 public static void GenerateFaultyRecord(BitMatrix matrix, PenaltyRules penaltyRule, int expected, int actual)
 {
     string path = Path.Combine(Path.GetTempPath(), s_TxtFileName);
     
     if(!File.Exists(path))
     {
     	using (StreamWriter file = File.CreateText(path)) 
       	{
     		file.WriteLine();
     	}
     }
     
     using (var file = File.AppendText(path))
     {
     	file.Write(penaltyRule.ToString());
     	file.Write(string.Format(" Expected: {0}, Actual: {0}", expected.ToString(), actual.ToString()));
         matrix.ToGraphic(file);
         file.WriteLine("=====");
         file.Close();
         
     }
 }
コード例 #11
0
ファイル: Penalty2Test.cs プロジェクト: fengdc/QrCode.Net
		public override void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
		{
			base.Test_against_reference_implementation(input, penaltyRule, expected);
		}
コード例 #12
0
ファイル: Penalty4Test.cs プロジェクト: nopara73/QrCode.Net
 public override void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
 {
     base.Test_against_reference_implementation(input, penaltyRule, expected);
 }
コード例 #13
0
 protected static void AssertIntEquals(int expected, int actual, BitMatrix matrix, PenaltyRules penaltyRule)
 {
     if (expected != actual)
     {
         GenerateFaultyRecord(matrix, penaltyRule, expected, actual);
         Assert.Fail("Penalty scores are different.\nExpected:{0}Actual:{1}.", expected.ToString(), actual.ToString());
     }
 }
コード例 #14
0
 public virtual void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
 {
     TestPenaltyRule(input, penaltyRule, expected);
 }
コード例 #15
0
        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)));
        }
コード例 #16
0
ファイル: PenaltyTestBase.cs プロジェクト: fengdc/QrCode.Net
		public virtual void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
		{
			TestPenaltyRule(input, penaltyRule, expected);
		}