Esempio n. 1
0
        public void DifferentPointsHaveDifferentHashcode()
        {
            Point a = new Point(0, 0);
            Point b = new Point(0, 5);
            Point c = new Point(5, 0);
            Point d = new Point(5, 5);

            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(a.Equals(b));
            Assert.AreNotEqual(a.GetHashCode(), c.GetHashCode());
            Assert.IsFalse(a.Equals(c));
            Assert.IsFalse(a.Equals(c));
            Assert.AreNotEqual(a.GetHashCode(), d.GetHashCode());
            Assert.IsFalse(a.Equals(d));
            Assert.IsFalse(a.Equals(d));

            Assert.AreNotEqual(b.GetHashCode(), c.GetHashCode());
            Assert.IsFalse(b.Equals(c));
            Assert.IsFalse(b.Equals(c));
            Assert.AreNotEqual(b.GetHashCode(), d.GetHashCode());
            Assert.IsFalse(b.Equals(d));
            Assert.IsFalse(b.Equals(d));

            Assert.AreNotEqual(c.GetHashCode(), d.GetHashCode());
            Assert.IsFalse(c.Equals(d));
            Assert.IsFalse(c.Equals(d));
        }
Esempio n. 2
0
 public void PointHashCodeTest()
 {
     Assert.AreNotEqual(_p1.GetHashCode(), _p3.GetHashCode(), "Hash codes of points 1 and 3 are equal");
     Assert.AreEqual(_p1.GetHashCode(), _p2.GetHashCode(), 0.0001, "Hash codes of points 1 and 2 are not equal");
     Assert.AreNotEqual(_p1.GetHashCode(), _p4.GetHashCode(), "Hash codes of points 1 and 4 are equal");
     Assert.AreNotEqual(_p4.GetHashCode(), _p6.GetHashCode(), "Hash codes of points 4 and 6 are equal");
 }
Esempio n. 3
0
        public void GetHashCodeTest()
        {
            var point = new Point(10, 10);

            Assert.Equal(point.GetHashCode(), new Point(10, 10).GetHashCode());
            Assert.NotEqual(point.GetHashCode(), new Point(20, 10).GetHashCode());
            Assert.NotEqual(point.GetHashCode(), new Point(10, 20).GetHashCode());
        }
        public void GetHashCodeTakesYIntoAccount()
        {
            var point = new Point(1, 2);

            var c1 = point.GetHashCode();

            point.Y = 3;
            Assert.AreNotEqual(c1, point.GetHashCode());
        }
Esempio n. 5
0
        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());
        }
 /// <summary>
 /// Gets a hash code for this instance.
 /// </summary>
 /// <returns>A hash code.</returns>
 public override int GetHashCode()
 {
     return(_alpha.GetHashCode() ^ _rotationAngle.GetHashCode() ^ _zoom.GetHashCode()
            ^ _extraImageRotationAngle.GetHashCode() ^ _backColorGradientRotationAngle.GetHashCode()
            ^ _backColor.GetHashCode() ^ _backColor2.GetHashCode() ^ _foreColor.GetHashCode()
            ^ _textHaloColor.GetHashCode() ^ _textHaloWidth.GetHashCode()
            ^ _textRotationAngle.GetHashCode() ^ _textZoom.GetHashCode()
            ^ _imageOffset.GetHashCode() ^ _shadowOffset.GetHashCode()
            ^ _shadowOffset.GetHashCode());
 }
Esempio n. 7
0
        public void TestGetHashCode_Point()
        {
            Point p1 = new Point(3, 4);

            Console.WriteLine(p1.GetHashCode());

            p1.X = 6;
            p1.Y = 8;
            Console.WriteLine(p1.GetHashCode());
        }
Esempio n. 8
0
        public void HashCode()
        {
            var point1 = new Point();
            var point2 = new Point();
            var point3 = new Point(1.0, 2.0);
            var point4 = new Point(1.0, 2.0);

            Assert.AreEqual(point1.GetHashCode(), point2.GetHashCode());
            Assert.AreNotEqual(point1.GetHashCode(), point3.GetHashCode());
            Assert.AreEqual(point3.GetHashCode(), point4.GetHashCode());
        }
Esempio n. 9
0
        public Edge(Corner begin, Corner end, Center left, Center right)
        {
            River        = 0;
            VoronoiStart = begin;
            VoronoiEnd   = end;

            DelaunayStart = left;
            DelaunayEnd   = right;

            Midpoint = new Point((VoronoiStart.Point.X + VoronoiEnd.Point.X) / 2, (VoronoiStart.Point.Y + VoronoiEnd.Point.Y) / 2);
            Key      = Midpoint.GetHashCode();
            Index    = Midpoint.GetHashCode();
        }
Esempio n. 10
0
        public void Calling_GetHashCode_on_two_distinct_instances_with_same_values_Should_return_the_same_hash()
        {
            // Arrange
            var other    = new Point <double>(_calculator, _subject.X, _subject.Y);
            var expected = other.GetHashCode();

            // Act
            var actual = _subject.GetHashCode();

            // Assert
            actual.Should().Be(expected);
            _subject.Equals((object)other).Should().BeTrue();
        }
Esempio n. 11
0
        public static (Rectangle, Action <Graphics>) Render(TheaterType theater, OverlayType[] tiberiumOrGoldTypes, OverlayType[] gemTypes, Point topLeft, Size tileSize, int tileScale, Overlay overlay)
        {
            var name = overlay.Type.Name;

            if (overlay.Type.IsGem)
            {
                name = gemTypes[new Random(randomSeed ^ topLeft.GetHashCode()).Next(tiberiumOrGoldTypes.Length)].Name;
            }
            else if (overlay.Type.IsTiberiumOrGold)
            {
                name = tiberiumOrGoldTypes[new Random(randomSeed ^ topLeft.GetHashCode()).Next(tiberiumOrGoldTypes.Length)].Name;
            }

            if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, name, overlay.Icon, out Tile tile))
            {
                var size     = (overlay.Type.IsCrate || overlay.Type.IsFlag) ? new Size(tile.Image.Width / tileScale, tile.Image.Height / tileScale) : tileSize;
                var location = new Point(topLeft.X * tileSize.Width, topLeft.Y * tileSize.Height)
                               + new Size(tileSize.Width / 2, tileSize.Height / 2)
                               - new Size(size.Width / 2, size.Height / 2);
                var overlayBounds = new Rectangle(location, size);

                var tint = overlay.Tint;
                void render(Graphics g)
                {
                    var imageAttributes = new ImageAttributes();

                    if (tint != Color.White)
                    {
                        var colorMatrix = new ColorMatrix(new float[][]
                        {
                            new float[] { tint.R / 255.0f, 0, 0, 0, 0 },
                            new float[] { 0, tint.G / 255.0f, 0, 0, 0 },
                            new float[] { 0, 0, tint.B / 255.0f, 0, 0 },
                            new float[] { 0, 0, 0, tint.A / 255.0f, 0 },
                            new float[] { 0, 0, 0, 0, 1 },
                        }
                                                          );
                        imageAttributes.SetColorMatrix(colorMatrix);
                    }

                    g.DrawImage(tile.Image, overlayBounds, 0, 0, tile.Image.Width, tile.Image.Height, GraphicsUnit.Pixel, imageAttributes);
                }

                return(overlayBounds, render);
            }
            else
            {
                Debug.Print(string.Format("Overlay {0} ({1}) not found", overlay.Type.Name, overlay.Icon));
                return(Rectangle.Empty, (g) => { });
            }
        }
        public Center(double x, double y)
        {
            polyNorm = new Vector3D(0, 0, 0);
            Point    = new Point(x, y);
            Key      = Point.GetHashCode();
            Index    = Point.GetHashCode();

            Water     = Coast = Ocean = Border = false;
            Elevation = Moisture = 0.0d;

            Neighbours = new HashSet <Center>(new CenterComparer());
            Borders    = new HashSet <Edge>(new EdgeComparer());
            Corners    = new HashSet <Corner>(new CornerComparer());
        }
Esempio n. 13
0
        public Corner(double ax, double ay)
        {
            Point     = new Point(ax, ay);
            Key       = Point.GetHashCode();
            Index     = Point.GetHashCode();
            Ocean     = Water = Coast = Border = false;
            Moisture  = 0.0d;
            Elevation = 100.0d;

            Touches   = new HashSet <Center>(new CenterComparer());
            Protrudes = new HashSet <Edge>(new EdgeComparer());
            Adjacents = new HashSet <Corner>(new CornerComparer());

            River = WatershedSize = 0;
        }
Esempio n. 14
0
    static void Test1()
    {
        Console.WriteLine("# Test1");
        var pt1 = new Point(10, 10);
        var pt2 = new Point(20, 20);
        var pt3 = new Point(10, 10);
        var pt4 = new Point2(10, 10);
        var pt5 = new Point2(20, 20);

        Console.WriteLine(pt1.GetHashCode() == pt2.GetHashCode());
        Console.WriteLine(pt1.GetHashCode() == pt3.GetHashCode());
        Console.WriteLine(pt1.GetHashCode() == pt4.GetHashCode());
        Console.WriteLine(pt1.GetHashCode() == pt5.GetHashCode());
        Console.WriteLine(pt2.GetHashCode() == pt4.GetHashCode());
        Console.WriteLine(pt2.GetHashCode() == pt5.GetHashCode());
    }
Esempio n. 15
0
        public void HashCodePositiveTest()
        {
            Point pointA = new Point(3, 3);
            Point pointB = new Point(3, 3);

            Assert.AreEqual(pointA.GetHashCode(), pointB.GetHashCode());
        }
Esempio n. 16
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Start != null ? Start.GetHashCode() : 0) * 397) ^ (End != null ? End.GetHashCode() : 0));
     }
 }
Esempio n. 17
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Point != null ? Point.GetHashCode() : 0) * 397) ^ Radius);
     }
 }
Esempio n. 18
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((Location.GetHashCode() * 397) ^ Size.GetHashCode());
     }
 }
Esempio n. 19
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(Point.GetHashCode() * 397);
     }
 }
Esempio n. 20
0
        public void SamePointsWithSameHashcode()
        {
            Point a = new Point(0, 0, "green");
            Point b = new Point(0, 0, "green");
            Point c = new Point(0, 0, "red");

            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
            Assert.IsTrue(a.Equals(b));
            Assert.IsTrue(b.Equals(a));
            Assert.AreEqual(b.GetHashCode(), c.GetHashCode());
            Assert.IsTrue(b.Equals(c));
            Assert.IsTrue(c.Equals(b));
            Assert.AreEqual(a.GetHashCode(), c.GetHashCode());
            Assert.IsTrue(a.Equals(c));
            Assert.IsTrue(c.Equals(a));
        }
Esempio n. 21
0
        public void ShouldGenerateDifferentHashCodes3D()
        {
            var point1 = new Point(1, 135.37340722, 11.92245761, 35.1201208);
            var point2 = new Point(1, 135.37340722, 11.92245761, 35.1201209);

            point1.GetHashCode().Should().NotBe(point2.GetHashCode());
        }
Esempio n. 22
0
        public void HashCodeNegativeTest()
        {
            Point pointA = new Point(3, 3);
            Point pointB = new Point(4, 3);

            Assert.AreNotEqual(pointA.GetHashCode(), pointB.GetHashCode());
        }
Esempio n. 23
0
        public void ShouldGenerateIdenticalHashCodes3DWhenZisNaN()
        {
            var point1 = new Point(1, 135.37340722, 11.92245761, double.NaN);
            var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN);

            point1.GetHashCode().Should().Be(point2.GetHashCode());
        }
Esempio n. 24
0
 /// <summary>
 ///     Returns the hash code for this instance.
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode()
 {
     unchecked
     {
         return((Center.GetHashCode() * 397) ^ Radius.GetHashCode());
     }
 }
Esempio n. 25
0
 public void Point()
 {
     //Do various Point method calls to cover the point class with sufficient testing
     Point p0 = new Point();
     Point p1 = new Point(0, 0);
     Point p2 = new Point(450, 120);
     Assert.IsTrue(p0.IsEmpty());
     Assert.IsFalse(p1.IsEmpty());
     Assert.AreNotEqual(p0, p1);
     Assert.AreEqual(450, p2.X);
     Assert.AreEqual(120, p2.Y);
     Assert.AreNotSame(p2.Clone(), p2);
     p0 = p2.Clone();
     p0.X += 100;
     p0.Y = 150;
     p0[0] += p0[1];
     Assert.AreEqual(new Point(700, 150), p0);
     Assert.AreEqual(p2, p2.GetBoundingBox().Min);
     Assert.AreEqual(p2, p2.GetBoundingBox().Max);
     Assert.IsTrue(p2.IsSimple());
     Assert.IsFalse(p2.IsEmpty());
     Assert.AreEqual(2, p2.NumOrdinates);
     Assert.AreEqual(new Point(400, 100), p2 + new Point(-50, -20));
     Assert.AreEqual(new Point(500, 100), p2 - new Point(-50, 20));
     Assert.AreEqual(new Point(900, 240), p2*2);
     Assert.AreEqual(0, p2.Dimension);
     Assert.AreEqual(450, p2[0]);
     Assert.AreEqual(120, p2[1]);
     Assert.IsNull(p2.Boundary());
     Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
     Assert.Greater(p2.CompareTo(p1), 0);
     Assert.Less(p1.CompareTo(p2), 0);
     Assert.AreEqual(p2.CompareTo(new Point(450, 120)), 0);
 }
Esempio n. 26
0
 public override int GetHashCode()
 {
     unchecked
     {
         return (Page * 397) ^ Location.GetHashCode();
     }
 }
Esempio n. 27
0
        static void Main(string[] args)
        {
            //Point? p = new Point() { X = 1};
            //p = null;
            Point p = new Point(6, 8);

            Changeme(p);
            Console.WriteLine(p.X);

            int x = 2;

            Change(ref x);
            Console.WriteLine(x);

            Point p1 = new Point(1, 2);
            Point p2 = p1;

            Console.WriteLine(p1.Equals(p2)); // true
            p1.X = 12;
            Console.WriteLine(p2.X);          // 1
            Console.WriteLine(p1.Equals(p2)); // false

            Employee e1 = new Employee()
            {
                Age = 20
            };
            Employee e2 = e1;

            e1.Age = 30;
            Console.WriteLine(e2.Age); // 30

            Console.WriteLine(p1.GetHashCode());
            Console.WriteLine(1.GetHashCode());
        }
Esempio n. 28
0
        public void ShouldGenerateIdenticalHashCodes2D()
        {
            var point1 = new Point(1, 135.37340722, 11.92245761);
            var point2 = new Point(1, 135.37340722, 11.92245761);

            point1.GetHashCode().Should().Be(point2.GetHashCode());
        }
Esempio n. 29
0
        public void ShouldGenerateDifferentHashCodes2DAnd3D()
        {
            var point1 = new Point(1, 135.37340722, 11.92245761);
            var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN);

            point1.GetHashCode().Should().NotBe(point2.GetHashCode());
        }
Esempio n. 30
0
            public static void Run()
            {
                Console.Clear();
                // notice if we use default Draw() , `* character`
                // and call Draw() twice or more , the function will work and re draw every thing
                // but this is  unnecessary , but we can not prevent this because we does not use caching
                // until now

                // notice : when executing next two lines ,
                // the values stored in Cash object will be 8 not 16
                // but we still will override drawing shapr from '*' to '#'
                // we can prevent this by adding static property to LineToPointsAdapter , to check last adding status
                // or latest length , but no need to do that
                // because we use caching only to prevent additional operations/calculations
                // and in drawing we may need to draw shape over shape [layering] so we can not prevent this behaviour
                Draw();
                Draw('#');
                // Draw('#');
                Console.WriteLine(LineToPointsAdapter.CallingCount);
                Console.WriteLine(LineToPointsAdapter.PrintingCount);

                var point1 = new Point(0, 5);
                var point2 = new Point(0, 5);
                var line1  = new Line(point1, point2);
                var line2  = new Line(point1, point2);

                Console.WriteLine(point1.GetHashCode());
                Console.WriteLine(point2.GetHashCode());
                Console.WriteLine(line1.GetHashCode());
                Console.WriteLine(line2.GetHashCode());
            }
Esempio n. 31
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((SegmentId * 397) ^ CoordsInSegment.GetHashCode());
     }
 }
Esempio n. 32
0
 public static void Main()
 {
     Point p = new Point(7, 3);
     p.Print();
     Console.WriteLine(p.ToString()); // Redefinido em Point
     Console.WriteLine(p.GetType()); // box + call
     Console.WriteLine(p.GetHashCode()); // Herdado de Object
 }
Esempio n. 33
0
        public void Equals_IsTrue (int p1x, int p1y, int p2x, int p2y)
        {
            var p1 = new Point(p1x, p1y);
            var p2 = new Point(p2x, p2y);

            (p1 == p2).Should().BeTrue();
            (p1 != p2).Should().BeFalse();
            (p1.GetHashCode() == p2.GetHashCode()).Should().BeTrue();
        }
Esempio n. 34
0
 public void Point_GetHashCode_returns_same_hash_for_same_object()
 {
     var p1 = new Point(1.0f, 1.2f, 1.9f);
     var p2 = p1;
     var hash1 = p1.GetHashCode();
     var hash2 = p2.GetHashCode();
     Assert.AreEqual(hash1, hash2);
 }
Esempio n. 35
0
 public static void GetHashCodeTest()
 {
     var point = new Point(10, 10);
     Assert.Equal(point.GetHashCode(), new Point(10, 10).GetHashCode());
     Assert.NotEqual(point.GetHashCode(), new Point(20, 10).GetHashCode());
     Assert.NotEqual(point.GetHashCode(), new Point(10, 20).GetHashCode());
 }
Esempio n. 36
0
    private bool CheckCollisionWhitCollectedObject(Point currentPoint)
    {
        bool isCollectedObject = false;

        foreach (var obj in gameObjectsList)
        {
            foreach (var point in obj.PositionsCoordinates)
            {
                if (point.GetHashCode() == currentPoint.GetHashCode())
                {
                    if (obj is CollectedObject)
                    {
                        return true;
                    }
                }
            }
        }

        return isCollectedObject;
    }
Esempio n. 37
0
    private bool CheckCollisionWhitOtherObject(Point point)
    {
        bool haveCollision = false;

        foreach (var obj in gameObjectsList)
        {
            foreach (var o in obj.PositionsCoordinates)
            {
                if (point.GetHashCode() == o.GetHashCode())
                {
                    obj.HaveCollision = true;
                    return true;
                }
            }
        }

        return haveCollision;
    }
Esempio n. 38
0
 public void Point_GetHashCode_returns()
 {
     var p = new Point(1.0f, 1.2f, 1.9f);
     p.GetHashCode();
 }
Esempio n. 39
0
        public void GetHashCodeTakesYIntoAccount()
        {
            var point = new Point(1, 2);

            var c1 = point.GetHashCode();

            point.Y = 3;
            Assert.AreNotEqual(c1, point.GetHashCode());
        }
Esempio n. 40
0
 public void Point_GetHashCode_returns_different_hashes_for_different_objects()
 {
     var p1 = new Point(1.0f, 1.2f, 1.9f);
     var p2 = new Point(-1.0f, -1.2f, -1.9f);
     var hash1 = p1.GetHashCode();
     var hash2 = p2.GetHashCode();
     Assert.AreNotEqual(hash1, hash2);
 }
Esempio n. 41
0
        public void EqualityTest(int x, int y)
        {
            Point p1 = new Point(x, y);
            Point p2 = new Point(x / 2 - 1, y / 2 - 1);
            Point p3 = new Point(x, y);

            Assert.True(p1 == p3);
            Assert.True(p1 != p2);
            Assert.True(p2 != p3);

            Assert.True(p1.Equals(p3));
            Assert.False(p1.Equals(p2));
            Assert.False(p2.Equals(p3));

            Assert.Equal(p1.GetHashCode(), p3.GetHashCode());
        }