private string ValidateCache(string cache) { Models.CoefModels.CoefRequestResult res = Models.CoefModels.CoefRequestResult.Parse(cache); bool AllEqualOne = true; // Test if there are negative bool NegativeCoef = false; foreach (var block in res.CoefBlocks) { foreach (var coef in block.Coeffs) { if (coef.HitCoeff != 1.0m || coef.MissCoeff != 1.0m) { AllEqualOne = false; } if (coef.HitCoeff < 0 || coef.MissCoeff < 0) { NegativeCoef = true; } } } if (AllEqualOne == true) // All coefficients are 1.0 thow exception with information. { return("All coefficients are equal to 1.0"); } if (NegativeCoef == true) // Negative coefficiente { return("Negative coefficients"); } return("OK"); }
public bool ValidateRequestResult(string result, out string errorMessage) { errorMessage = "OK"; // Parse result from coefficient API into objects Models.CoefModels.CoefRequestResult res = Models.CoefModels.CoefRequestResult.Parse(result); ////Test: Force all to 1: //foreach (var block in res.CoefBlocks) //{ // foreach (var coef in block.Coeffs) // { // coef.HitCoeff = 1.0m; // coef.MissCoeff = 1.0m; // } //} ////Test: Force negative //foreach (var block in res.CoefBlocks) //{ // foreach (var coef in block.Coeffs) // { // coef.HitCoeff = -1.0m; // break; // } // break; //} // Teste if all values are 1.0 bool AllEqualOne = true; // Test if there are negative bool NegativeCoef = false; foreach (var block in res.CoefBlocks) { foreach (var coef in block.Coeffs) { if (coef.HitCoeff != 1.0m || coef.MissCoeff != 1.0m) { AllEqualOne = false; } if (coef.HitCoeff < 0 || coef.MissCoeff < 0) { NegativeCoef = true; } } } if (AllEqualOne == true) // All coefficients are 1.0 thow exception with information. { errorMessage = "All coefficients are equal to 1.0"; return(false); } if (NegativeCoef == true) // Negative coefficiente { errorMessage = "Negative coefficients"; return(false); } return(true); }