public void ToStringTest()
{
// Issue 51:
PolynomialRegression poly = new PolynomialRegression(2);
var x = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var y = new double[] { 1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321 };
poly.Regress(x, y);
{
string expected = "y(x) = 3x^2 + 1.99999999999999x^1 + 1.00000000000006x^0";
expected = expected.Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
string actual = poly.ToString();
Assert.AreEqual(expected, actual);
}
{
string expected = "y(x) = 3x^2 + 1.99999999999999x^1 + 1.00000000000006x^0";
string actual = poly.ToString(null, System.Globalization.CultureInfo.GetCultureInfo("en-US"));
Assert.AreEqual(expected, actual);
}
{
string expected = "y(x) = 3.0x^2 + 2.0x^1 + 1.0x^0";
string actual = poly.ToString("N1", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
Assert.AreEqual(expected, actual);
}
{
string expected = "y(x) = 3,00x^2 + 2,00x^1 + 1,00x^0";
string actual = poly.ToString("N2", System.Globalization.CultureInfo.GetCultureInfo("pt-BR"));
Assert.AreEqual(expected, actual);
}
}
}