using System.Windows.Converters;
using System.Windows.Markup;
using System.Windows.Media;
+using System.Globalization;
namespace System.Windows {
}
public override int GetHashCode ()
- {
- throw new NotImplementedException ();
+ {\r
+ return (x.GetHashCode() ^ y.GetHashCode());
}
}
public static Point Parse (string source)
- {
- throw new NotImplementedException ();
+ {\r
+ string[] points = source.Split(',');\r
+\r
+ if (points.Length<2)\r
+ throw new InvalidOperationException ("source does not contain two numbers");\r
+ if (points.Length > 2)\r
+ throw new InvalidOperationException ("source contains too many delimiters");\r
+\r
+ CultureInfo ci = CultureInfo.InvariantCulture;
+ return new Point (Convert.ToDouble(points[0],ci), Convert.ToDouble(points[1],ci));
}
public override string ToString ()
- {
- return String.Format ("{0},{1}", x, y);
+ {\r
+ return this.ToString(null, null);
}
public string ToString (IFormatProvider formatProvider)
- {
- throw new NotImplementedException ();
+ {\r
+ return this.ToString(null,formatProvider);
+ }
+
+ private string ToString(string format,IFormatProvider formatProvider)\r
+ {\r
+ CultureInfo ci = (CultureInfo)formatProvider;\r
+\r
+ if (ci == null)\r
+ ci = CultureInfo.CurrentCulture;\r
+ string seperator = ci.NumberFormat.NumberDecimalSeparator;\r
+ if (seperator.Equals(","))\r
+ seperator = ";";\r
+ else\r
+ seperator = ",";\r
+ object[] ob = { this.x, seperator, this.y };\r
+\r
+ return string.Format(formatProvider, "{0:" + format + "}{1}{2:" + format + "}", ob);\r
}
string IFormattable.ToString (string format, IFormatProvider formatProvider)
- {
- throw new NotImplementedException ();
+ {\r
+ return this.ToString(format, formatProvider);
}
double x;
// Chris Toshok (toshok@ximian.com)
//
-using System;
+using System.Globalization;
+using System.Threading;
using System.Windows;
using System.Windows.Media;
using NUnit.Framework;
namespace MonoTests.System.Windows {
[TestFixture]
- [Category ("NotWorking")]
public class PointTest {
[Test]
Assert.IsFalse (p.Equals (new object()));
}
+ [Test]
+ public void getHashCodeTest()
+ {
+ Point p1 = new Point(-5, -4);
+ Point p2 = new Point(5, 4);
+ Point p3 = new Point(5, 4);
+
+ Assert.AreEqual(p2.GetHashCode(), p3.GetHashCode());
+ Assert.AreEqual(p1.GetHashCode(),p2.GetHashCode());
+ }
+
[Test]
public void ToStringTest ()
{
+ Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us");
Point p = new Point (4, 5);
Assert.AreEqual ("4,5", p.ToString());
+ Point p2 = new Point(4.1, 5.1);
+ Assert.AreEqual("4.1,5.1",p2.ToString());
+ Point p3 = new Point(0, 0);
+ Assert.AreEqual("0,0", p3.ToString());
+
+ Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-de");
+ Point p4 = new Point(4, 5);
+ Assert.AreEqual("4;5", p4.ToString());
+ Point p5 = new Point(4.1, 5.1);
+ Assert.AreEqual("4,1;5,1", p5.ToString());
+ Point p6 = new Point(0, 0);
+ Assert.AreEqual("0;0", p6.ToString());
}
[Test]
public void Parse ()
{
+ Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-fr");
+
Point p = Point.Parse ("4,5");
Assert.AreEqual (new Point (4, 5), p);
p = Point.Parse ("-4.4,-5.5");
Assert.AreEqual (new Point (-4.4, -5.5), p);
+
+ p = Point.Parse("4.4,5.5");
+ Assert.AreEqual(new Point(4.4, 5.5), p);
+
+ Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us");
+ Assert.AreEqual(new Point(4.4, 5.5), p);
}
[Test]