Пример #1
0
        public void StructTestMethod()
        {
            //value type modification
            CoordinatesStruct _coordinate1 = CoordinatesStruct.GetCoordinates(1, 2);
            CoordinatesStruct _coordinate2 = CoordinatesStruct.GetCoordinates(1, 2);

            CoordinatesNoChange(_coordinate1);
            Assert.AreEqual(_coordinate1, _coordinate2);
            Assert.AreEqual(_coordinate1.x, _coordinate2.x);
            Assert.AreEqual(_coordinate1.y, _coordinate2.y);
            CoordinatesChange(ref _coordinate1);
            Assert.AreNotEqual(_coordinate1, _coordinate2);
            Assert.AreNotEqual(_coordinate1.x, _coordinate2.x);
            Assert.AreNotEqual(_coordinate1.y, _coordinate2.y);

            //Reference type modification
            CoordinatesClass _coordinateReference1 = null;

            Assert.IsNull(_coordinateReference1);
            _coordinateReference1 = new CoordinatesClass(1, 2);
            CoordinatesClass _coordinateReference2 = new CoordinatesClass(1, 2);

            Assert.AreEqual(_coordinateReference1.x, _coordinateReference2.x);
            Assert.AreEqual(_coordinateReference1.y, _coordinateReference2.y);
            Assert.AreNotEqual(_coordinateReference1, _coordinateReference2);
            Assert.AreNotSame(_coordinateReference1, _coordinateReference2);
            CoordinatesChange(_coordinateReference1);
            Assert.AreNotEqual(_coordinateReference1.x, _coordinateReference2.x);
            Assert.AreNotEqual(_coordinateReference1.y, _coordinateReference2.y);
        }
Пример #2
0
 private static void CoordinatesChange(ref CoordinatesStruct coordinates)
 {
     coordinates.x = m_RandomGenerator.Next();
     coordinates.y = m_RandomGenerator.Next();
 }