2008-11-06 Felix Eisele <felix_eisele@gmx.de>
authorAlan McGovern <alan.mcgovern@gmail.com>
Thu, 6 Nov 2008 11:54:57 +0000 (11:54 -0000)
committerAlan McGovern <alan.mcgovern@gmail.com>
Thu, 6 Nov 2008 11:54:57 +0000 (11:54 -0000)
        * Test/System.Windows/PointTest.cs:
        All Tests pass now
        * System.Windows/Point.cs
        Complete the implementation of the class

svn path=/trunk/mcs/; revision=118101

mcs/class/WindowsBase/ChangeLog
mcs/class/WindowsBase/System.Windows/Point.cs
mcs/class/WindowsBase/Test/System.Windows/PointTest.cs

index f25c3d1c11fafc1faca180722da003f54a45d883..241793bb4f37cfb68c35dd2a6bc1da845c974c0f 100644 (file)
@@ -1,3 +1,10 @@
+2008-11-06 Felix Eisele <felix_eisele@gmx.de>
+       * Test/System.Windows/PointTest.cs:
+       All Tests pass now
+       * System.Windows/Point.cs
+       Complete the implementation of the class
+       
+
 2008-11-05  Brian O'Keefe  <zer0keefie@gmail.com>
  
        * System.Collections.ObjectModel/ObservableCollection.cs:
index 511f201d321bcf6b95a7777cb069ee1ba2e24f30..c72a171353669f0554a37d0714a1537a443d9302 100644 (file)
@@ -28,6 +28,7 @@ using System.ComponentModel;
 using System.Windows.Converters;
 using System.Windows.Markup;
 using System.Windows.Media;
+using System.Globalization;
 
 namespace System.Windows {
 
@@ -65,8 +66,8 @@ namespace System.Windows {
                }
 
                public override int GetHashCode ()
-               {
-                       throw new NotImplementedException ();
+               {\r
+                   return (x.GetHashCode() ^ y.GetHashCode());
                }
 
 
@@ -145,23 +146,47 @@ namespace System.Windows {
                }
 
                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;
index e5065ed17791768e074be55983e5ad0789f2d4a2..9c7f3af54060c62bb4b0c4fd969bfee2c1e9580b 100644 (file)
@@ -23,7 +23,8 @@
 //     Chris Toshok (toshok@ximian.com)
 //
 
-using System;
+using System.Globalization;
+using System.Threading;
 using System.Windows;
 using System.Windows.Media;
 using NUnit.Framework;
@@ -31,7 +32,6 @@ using NUnit.Framework;
 namespace MonoTests.System.Windows {
 
        [TestFixture]
-       [Category ("NotWorking")]
        public class PointTest {
 
                [Test]
@@ -51,16 +51,42 @@ namespace MonoTests.System.Windows {
                        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);
 
@@ -69,6 +95,12 @@ namespace MonoTests.System.Windows {
 
                        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]