/// <summary> /// Performs the playback of actions in this module. /// </summary> /// <remarks>You should not call this method directly, instead pass the module /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method /// that will in turn invoke this method.</remarks> void ITestModule.Run() { Mouse.DefaultMoveTime = 0; Keyboard.DefaultKeyPressTime = 0; Delay.SpeedFactor = 0.0; var repo = global::AutomatedSystemTests.AutomatedSystemTestsRepository.Instance; var dataSectionScenariosView = BuildDataScenariosView(jsonDataScenariosView); var table = repo.RiskeerMainWindow.ContainerMultipleViews.DocumentViewContainer.ScenariosView.Table.Self; var rows = table.Rows; var rowHeader = rows[0]; int indexInFinalRating = GetIndex(rowHeader, "In oordeel"); int indexContribution = GetIndex(rowHeader, "Bijdrage aan"); int indexName = GetIndex(rowHeader, "Naam"); int indexFailureProbability = GetIndex(rowHeader, "Faalkans"); var dataView = new DataRowsTableSectionScenariosView(); rows.RemoveAt(0); foreach (var row in rows) { var calcInfo = new CalculationInformationInScenariosView(); Cell currentCell; currentCell = row.Cells[indexInFinalRating]; currentCell.Select(); calcInfo.InFinalRating = GetAV(currentCell) == "True"; currentCell = row.Cells[indexContribution]; currentCell.Select(); calcInfo.Contribution = Double.Parse(GetAV(currentCell)); currentCell = row.Cells[indexName]; currentCell.Select(); calcInfo.Name = GetAV(currentCell); currentCell = row.Cells[indexFailureProbability]; currentCell.Select(); calcInfo.FailureProbability = GetAV(currentCell).ToInvariantCulture(); dataView.DataScenariosViewList.Add(calcInfo); } var dataFM = new DataSectionScenariosView(); dataFM.IndexSection = Int32.Parse(sectionIndex); dataFM.NameSection = sectionname; dataFM.DataSection = dataView; dataSectionScenariosView.Add(dataFM); jsonDataScenariosView = JsonConvert.SerializeObject(dataSectionScenariosView, Formatting.Indented); }
private double GetExpectedSumWeightedProbs(DataSectionScenariosView data, System.Globalization.CultureInfo currentCulture) { double expectedSumWeightedProbs = 0; for (int i = 0; i < data.DataSection.DataScenariosViewList.Count; i++) { var currentCalculation = data.DataSection.DataScenariosViewList[i]; if (currentCalculation.InFinalRating) { string expectedProbNoSeparators = currentCalculation.FailureProbability.Replace(currentCulture.NumberFormat.NumberGroupSeparator, String.Empty); string expectedNumeratorNoSeparators = expectedProbNoSeparators.Substring(2, expectedProbNoSeparators.Length - 2); long expectedNumeratorInt = Int64.Parse(expectedNumeratorNoSeparators); double currentCalcProbability = 1.0 / expectedNumeratorInt; expectedSumWeightedProbs += currentCalcProbability * currentCalculation.Contribution; } } return(expectedSumWeightedProbs / 100); }
private void ValidateSectionResult(DataSectionScenariosView data, string actualProb) { System.Globalization.CultureInfo currentCulture = CultureInfo.CurrentCulture; double expectedSumWeightedProbs = GetExpectedSumWeightedProbs(data, currentCulture); string expectedProbNoSeparators = "1/" + ((long)Math.Round(1 / expectedSumWeightedProbs)).ToString(); string actualProbNoSeparators = actualProb.Replace(currentCulture.NumberFormat.NumberGroupSeparator, String.Empty); if (expectedProbNoSeparators == actualProbNoSeparators) { Report.Info("Validating if expected probability (" + expectedProbNoSeparators + ") is exactly equal to actual one (" + actualProbNoSeparators + ")."); Validate.AreEqual(actualProbNoSeparators, expectedProbNoSeparators); } else { Report.Info("Expected probability (" + expectedProbNoSeparators + "), calculated based on data from Scenarios view, is not exactly equal to actual one (" + actualProbNoSeparators + ")."); Report.Info("Validating if they are almost equal (within 0.2 %)."); double relativeDeviation = CalculateRelativeDeviation(actualProbNoSeparators, expectedProbNoSeparators); Report.Info("Relative deviation: " + Math.Round((relativeDeviation * 100), 4).ToString() + "%"); Validate.IsTrue(relativeDeviation < 0.002); } }