private IEnumerable<string> GetCoefficientStrings(EditPeakScoringModelDlg editDlg)
 {
     for (int i = 0; i < editDlg.PeakCalculatorsGrid.Items.Count; i++)
     {
         double? weight = editDlg.PeakCalculatorsGrid.Items[i].Weight;
         if (weight.HasValue)
             yield return string.Format(CultureInfo.InvariantCulture, "{0:F04}", weight.Value);
         else
             yield return " null ";  // To help values line up
     }
 }
 private void ValidateCoefficients(EditPeakScoringModelDlg editDlgFromSrm, int coeffIndex)
 {
     string coefficients = string.Join(@"|", GetCoefficientStrings(editDlgFromSrm));
     if (IsRecordMode)
         Console.WriteLine(@"""{0}"", // Not L10N", coefficients);  // Not L10N
     else
         AssertEx.AreEqualLines(EXPECTED_COEFFICIENTS[coeffIndex], coefficients);
 }
 protected void VerifyScores(EditPeakScoringModelDlg editDlg,
     bool isPresent,
     Type[] scoreTypes)
 {
     List<double?> scores;
     VerifyScores(editDlg, isPresent, scoreTypes, out scores);
 }
 protected void VerifyScores(EditPeakScoringModelDlg editDlg, 
     bool isPresent,
     Type[] scoreTypes,
     out List<double?> scores)
 {
     scores = new List<double?>();
     foreach (var scoreType in scoreTypes)
     {
         Assert.AreEqual(IsActiveCalculator(editDlg, scoreType), isPresent);
         scores.Add(ValueCalculator(editDlg, scoreType));
     }
 }
 protected bool IsActiveCalculator(EditPeakScoringModelDlg editDlg, Type calcType)
 {
     var index = GetIndex(editDlg, calcType);
     return editDlg.PeakCalculatorsGrid.Items[index].IsEnabled;
 }
 protected double? ValueCalculator(EditPeakScoringModelDlg editDlg, Type calcType)
 {
     var index = GetIndex(editDlg, calcType);
     return editDlg.PeakCalculatorsGrid.Items[index].Weight;
 }
 protected int GetIndex(EditPeakScoringModelDlg editDlg, Type calcType)
 {
     var calculators = editDlg.PeakScoringModel.PeakFeatureCalculators;
     var calculator = calculators.FirstOrDefault(calc => calc.GetType() == calcType);
     Assert.IsNotNull(calculator);
     return calculators.IndexOf(calculator);
 }
 protected EditPeakScoringModelDlg.HistogramGroup GetHistogramForScoreIndex(EditPeakScoringModelDlg editDlg, int scoreIndex)
 {
     EditPeakScoringModelDlg.HistogramGroup scoreHistograms;
     EditPeakScoringModelDlg.HistogramGroup pValueHistograms;
     EditPeakScoringModelDlg.HistogramGroup qValueHistograms;
     PointPairList piZeroLine;
     editDlg.GetPoints(
         scoreIndex,
         out scoreHistograms,
         out pValueHistograms,
         out qValueHistograms,
         out piZeroLine);
     return scoreHistograms;
 }
 protected EditPeakScoringModelDlg.HistogramGroup GetHistogramForScore(EditPeakScoringModelDlg editDlg, Type scoreType)
 {
     int index = GetIndex(editDlg, scoreType);
     return GetHistogramForScoreIndex(editDlg, index);
 }
        private void VerifyCellValues(EditPeakScoringModelDlg editDlg, string expectedValueString, double sumWeights = 1.0, bool isRecording = true)
        {
            // Parse the expected values
            var expectedFields = expectedValueString.Split(new[] { '|', ';' });
            expectedFields = expectedFields.Take(expectedFields.Length - 1).ToArray();
            Assert.AreEqual(expectedFields.Length % 3, 0);
            int numRows = expectedFields.Length / 3;
            // Verify expected number of rows.
            Assert.AreEqual(editDlg.PeakCalculatorsGrid.RowCount, numRows);
            // Verify normalized weights add to 1
            double sumNormWeights = 0;
            var readModeSb = new StringBuilder();
            int fieldNum = 0;
            string expectedValue = null;
            for (int row = 0; row < numRows; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    if(col != 1)
                        expectedValue = expectedFields[fieldNum++];

                    // Verify cell value.
                    var actualValue = editDlg.PeakCalculatorsGrid.GetCellValue(col, row);
                    if (IsRecordMode && isRecording)
                    {
                        if (col == 0)
                        {
                            readModeSb.Append(actualValue == null ? "" : actualValue + '|');
                        }
                        if (col == 2)
                        {
                            readModeSb.Append((string.IsNullOrEmpty(actualValue) ? "" : double.Parse(actualValue).ToString(editDlg.PeakCalculatorWeightFormat)) + '|');
                        }
                        if (col == 3)
                        {
                            readModeSb.Append((string.IsNullOrEmpty(actualValue) ? "" : double.Parse(actualValue).ToString(editDlg.PeakCalculatorPercentContributionFormat)) + ";");
                        }
                    }
                    if (col == 2  && !string.IsNullOrEmpty(actualValue))
                        actualValue = double.Parse(actualValue).ToString(editDlg.PeakCalculatorWeightFormat);
                    if (col == 3 && !string.IsNullOrEmpty(actualValue))
                    {
                        sumNormWeights += double.Parse(actualValue);
                        actualValue = double.Parse(actualValue).ToString(editDlg.PeakCalculatorPercentContributionFormat);
                    }
                    if(!IsRecordMode && col != 1)
                    {
                        // Normalize decimal separator
                        if (actualValue != null)
                        {
                            actualValue = actualValue.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
                                  CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator);
                        }
                        Assert.AreEqual(expectedValue, actualValue);
                    }
                }
            }
            if(IsRecordMode && isRecording)
                Console.WriteLine(@"""{0}"",", readModeSb);
            Assert.AreEqual(sumNormWeights, sumWeights, 0.005);
        }
 private void VerifyBias(EditPeakScoringModelDlg editDlg, string bias, bool isRecording = true)
 {
     if (IsRecordMode)
     {
         if(isRecording)
             Console.WriteLine(@"""{0}"",", editDlg.PeakScoringModel.Parameters.Bias.ToString(CultureInfo.CurrentCulture));
     }
     else
     {
         double biasNum;
         Assert.IsTrue(double.TryParse(bias, NumberStyles.Float, CultureInfo.InvariantCulture, out biasNum));
         Assert.AreEqual(editDlg.PeakScoringModel.Parameters.Bias, biasNum, 1e-5);
     }
 }