Exemple #1
0
        private static void CoOrdsChange(BasicTypesStruct.CoOrdsClass coOrds)
        {
            Random _rndm = new Random(DateTime.Now.Millisecond);

            coOrds.x = _rndm.Next();
            coOrds.y = _rndm.Next();
        }
Exemple #2
0
        public void StructTestMethod()
        {
            //value type modification
            BasicTypesStruct.CoOrdsStruct _bts1 = BasicTypesStruct.GetCoOrdsStruct();
            BasicTypesStruct.CoOrdsStruct _bts2 = BasicTypesStruct.GetCoOrdsStruct();
            CoOrdsNoChange(_bts1);
            try
            {
                Assert.AreSame(_bts1, _bts2);
                Assert.Fail();
            }
            catch (AssertFailedException) { }
            Assert.AreEqual(_bts1, _bts2);
            Assert.IsTrue(_bts1.x == _bts2.x);
            Assert.IsTrue(_bts1.y == _bts2.y);
            //
            CoOrdsChange(ref _bts1);
            try
            {
                Assert.AreSame(_bts1, _bts2);
                Assert.Fail();
            }
            catch (AssertFailedException)
            {
            }
            Assert.AreNotEqual(_bts1, _bts2);
            Assert.IsTrue(_bts1.x != _bts2.x);
            Assert.IsTrue(_bts1.y != _bts2.y);

            //Reference type modification
            BasicTypesStruct.CoOrdsClass _btscoc1 = new BasicTypesStruct.CoOrdsClass(1, 2);
            BasicTypesStruct.CoOrdsClass _btscoc2 = new BasicTypesStruct.CoOrdsClass(1, 2);
            CoOrdsChange(_btscoc1);
            Assert.AreNotSame(_btscoc1, _btscoc2);
            Assert.AreNotEqual(_btscoc1, _btscoc2);
            Assert.IsTrue(_btscoc1.x != _btscoc2.x);
            Assert.IsTrue(_btscoc1.y != _btscoc2.y);
        }