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));
        }
Beispiel #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);
        }
Beispiel #3
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);
		}
Beispiel #4
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());
				
			}
		}
 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))
     });
        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");

            }
        }
Beispiel #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");
            }
        }
Beispiel #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));
            }
        }
Beispiel #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();
            }
        }
Beispiel #10
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();
         
     }
 }
Beispiel #11
0
		public override void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
		{
			base.Test_against_reference_implementation(input, penaltyRule, expected);
		}
Beispiel #12
0
 public override void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
 {
     base.Test_against_reference_implementation(input, penaltyRule, expected);
 }
Beispiel #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());
     }
 }
Beispiel #14
0
 public virtual void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
 {
     TestPenaltyRule(input, penaltyRule, expected);
 }
        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)));
        }
Beispiel #16
0
		public virtual void Test_against_reference_implementation(BitMatrix input, PenaltyRules penaltyRule, int expected)
		{
			TestPenaltyRule(input, penaltyRule, expected);
		}