public void AddAcceptingStates() { //Arrange int errRej = 2; double p = 0.6; PercentageRegenerationAutomaton percentageRegenerationAutomaton = new PercentageRegenerationAutomaton(); int bufferLength = (int)Math.Ceiling(p / ((double)1 - p) * errRej); int diffNum = (int)((1.0 - p) * 100.0); int simNum = (int)(p * 100.0); percentageRegenerationAutomaton.GreatestCommonDivisor(ref diffNum, ref simNum); var transitionTableZero = new Dictionary<string, string>(); var transitionTableOne = new Dictionary<string, string>(); var transitionTableX = new Dictionary<string, string>(); //Act percentageRegenerationAutomaton.AddRejectingStates(transitionTableZero, transitionTableOne, transitionTableX, simNum, errRej); percentageRegenerationAutomaton.AddAcceptingStates(transitionTableZero, transitionTableOne, transitionTableX, diffNum, bufferLength); percentageRegenerationAutomaton.AddTransitionBetweenStates(transitionTableZero, transitionTableOne, transitionTableX, simNum, errRej, diffNum, bufferLength, true); //Assert Assert.AreEqual(transitionTableZero["Q+1"], "Q+1.0"); }
public void Next() { String input = inputTextBox.Text; String input2 = input2TextBox.Text; int checkWordsReturnValue = RegenerationAutomatonWojComputations.ValidateInput(input, input2, percentTextBox.Text); switch (checkWordsReturnValue) { case Constants.EVERYTING_OK: //procent błedu ktory akceptujemy double chance = double.Parse(percentTextBox.Text) / 100; bool isError = treatAsError.IsChecked.Value; //------------------- PercentageRegenerationAutomaton percentageRegenerationAutomaton = new PercentageRegenerationAutomaton(); int inputLength = 0; string finalInput = RegenerationAutomatonWojComputations.PrepareInput(input, input2, ref inputLength); bool accepted = percentageRegenerationAutomaton.ComputeAnswer(finalInput, chance, int.Parse(maxNumOfErrors.Text), isError); ShowSolution(accepted); break; default: RegenerationAutomatonWojComputations.DetermineError(checkWordsReturnValue); break; } }
public void GreatestCommonDivisorUnitTest() { //Arrange PercentageRegenerationAutomaton percentageRegenerationAutomaton = new PercentageRegenerationAutomaton(); double p = 0.6; int diffNum = (int)((1.0 - p) * 100.0); int simNum = (int)(p * 100.0); //Act percentageRegenerationAutomaton.GreatestCommonDivisor(ref diffNum, ref simNum); //Assert Assert.AreEqual(simNum, 3); Assert.AreEqual(diffNum, 2); }
public void ComputeAnswerUnitTest() { string finalInput = "111111010101"; double p = 0.5; int errRej = 2; bool isXSim = false; PercentageRegenerationAutomaton method = new PercentageRegenerationAutomaton(); bool answer = method.ComputeAnswer(finalInput, p, errRej, isXSim); string finalInput2 = "11111011111111101110"; double p2 = 0.2; bool answer2 = method.ComputeAnswer(finalInput2, p2, errRej, isXSim); Assert.AreEqual(false,answer); Assert.AreEqual(true, answer2); }
public void PerformCalculationUnitTest() { PercentageRegenerationAutomaton method = new PercentageRegenerationAutomaton(); var transitionTableZero = new Dictionary<string, string>(); var transitionTableOne = new Dictionary<string, string>(); var transitionTableX = new Dictionary<string, string>(); Tuple<Dictionary<string, string>, Dictionary<string, string>, Dictionary<string, string>> transtionTable = method.CreateTranstionTable(0.5, 3, false); transitionTableZero = transtionTable.Item1; transitionTableOne = transtionTable.Item2; transitionTableX = transtionTable.Item3; bool answer = PercentageRegenerationAutomaton.PerformCalculation("1111111001111111011110", transitionTableZero, transitionTableOne, transitionTableX); Tuple<Dictionary<string, string>, Dictionary<string, string>, Dictionary<string, string>> transtionTable2 = method.CreateTranstionTable(0.1, 4, false); transitionTableZero = transtionTable2.Item1; transitionTableOne = transtionTable2.Item2; transitionTableX = transtionTable2.Item3; bool answer2 = PercentageRegenerationAutomaton.PerformCalculation("11011110011X111X011010", transitionTableZero, transitionTableOne, transitionTableX); bool answer3 = PercentageRegenerationAutomaton.PerformCalculation("1001101010101110XXX1010", transitionTableZero, transitionTableOne, transitionTableX); Assert.AreEqual(true, answer); Assert.AreEqual(true, answer2); Assert.AreEqual(false, answer3); }