[longomatch] Override some equality functions to fix unit tests.



commit 8cc44e7cfc7ffb8fd3be4f0295bb9ceb72d108c5
Author: Julien Moutte <julien fluendo com>
Date:   Wed Apr 22 16:31:57 2015 +0200

    Override some equality functions to fix unit tests.

 LongoMatch.Core/Common/Area.cs        |   42 +++++++++++++++++++++++++++++++++
 LongoMatch.Core/Store/CameraConfig.cs |   35 +++++++++++++++++++++++++++
 LongoMatch.Core/Store/Point.cs        |   20 +++++++++++++++-
 3 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Area.cs b/LongoMatch.Core/Common/Area.cs
index 2f9f93f..4799aad 100644
--- a/LongoMatch.Core/Common/Area.cs
+++ b/LongoMatch.Core/Common/Area.cs
@@ -24,6 +24,13 @@ namespace LongoMatch.Core.Common
        [JsonObject (MemberSerialization.OptIn)]
        public class Area
        {
+               public Area ()
+               {
+                       Start = new Point (0, 0);
+                       Width = 0;
+                       Height = 0;
+               }
+
                public Area (double x, double y, double width, double height)
                {
                        Start = new Point (x, y);
@@ -139,6 +146,41 @@ namespace LongoMatch.Core.Common
                        (Top >= area.Bottom) || (Bottom <= area.Top));
                }
 
+               public override bool Equals (object obj)
+               {
+                       Area a = obj as Area;
+                       if (a == null)
+                               return false;
+                       if (a.Start != Start ||
+                           a.Width != Width || a.Height != Height) {
+                               return false;
+                       }
+                       return true;
+               }
+
+               public override int GetHashCode ()
+               {
+                       return base.GetHashCode ();
+               }
+
+               public static bool operator == (Area a1, Area a2)
+               {
+                       if (Object.ReferenceEquals (a1, a2)) {
+                               return true;
+                       }
+
+                       if ((object)a1 == null || (object)a2 == null) {
+                               return false;
+                       }
+
+                       return a1.Equals (a2);
+               }
+
+               public static bool operator != (Area a1, Area a2)
+               {
+                       return !(a1 == a2);
+               }
+
                public override string ToString ()
                {
                        return string.Format ("[Area: Start={0}, Width={1}, Height={2}]", Start, Width, 
Height);
diff --git a/LongoMatch.Core/Store/CameraConfig.cs b/LongoMatch.Core/Store/CameraConfig.cs
index f187af3..5fca0ba 100644
--- a/LongoMatch.Core/Store/CameraConfig.cs
+++ b/LongoMatch.Core/Store/CameraConfig.cs
@@ -49,6 +49,41 @@ namespace LongoMatch.Core.Store
                        get;
                        set;
                }
+
+               public override bool Equals (object obj)
+               {
+                       CameraConfig config = obj as CameraConfig;
+                       if (config == null)
+                               return false;
+                       if (config.Index != Index ||
+                           config.RegionOfInterest != RegionOfInterest) {
+                               return false;
+                       }
+                       return true;
+               }
+
+               public override int GetHashCode ()
+               {
+                       return base.GetHashCode ();
+               }
+
+               public static bool operator == (CameraConfig c1, CameraConfig c2)
+               {
+                       if (Object.ReferenceEquals (c1, c2)) {
+                               return true;
+                       }
+
+                       if ((object)c1 == null || (object)c2 == null) {
+                               return false;
+                       }
+
+                       return c1.Equals (c2);
+               }
+
+               public static bool operator != (CameraConfig c1, CameraConfig c2)
+               {
+                       return !(c1 == c2);
+               }
        }
 }
 
diff --git a/LongoMatch.Core/Store/Point.cs b/LongoMatch.Core/Store/Point.cs
index 537d5fa..33af9cf 100644
--- a/LongoMatch.Core/Store/Point.cs
+++ b/LongoMatch.Core/Store/Point.cs
@@ -74,10 +74,28 @@ namespace LongoMatch.Core.Common
                        Point p = obj as Point;
                        if (p == null)
                                return false;
-                               
+
                        return p.X == X && p.Y == Y;
                }
 
+               public static bool operator == (Point p1, Point p2)
+               {
+                       if (Object.ReferenceEquals (p1, p2)) {
+                               return true;
+                       }
+
+                       if ((object)p1 == null || (object)p2 == null) {
+                               return false;
+                       }
+
+                       return p1.Equals (p2);
+               }
+
+               public static bool operator != (Point p1, Point p2)
+               {
+                       return !(p1 == p2);
+               }
+
                public override int GetHashCode ()
                {
                        return (X.ToString () + "-" + Y.ToString ()).GetHashCode ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]