Пример #1
0
        public void RotateCopyTest2()
        {
            int[] data = { 1, 2, 3, 4, 5 };

            IList <int> lst = new List <int>();

            using (IInputIterator <int> inputIterator = new InputIterator <int>(data))
            {
                IShallowClone cloneable = (IShallowClone)inputIterator;

                IInputIterator <int> cloneObj = cloneable.ShallowClone() as IInputIterator <int>;
                cloneObj.End();

                ICursor cursor = (ICursor)cloneObj;
                cursor.SetPosition(cursor.GetPosition() - 2);

                //set the first element to 4element position

                using (IOutputIterator <int> outputIterator = new BackInsertIterator <int>(lst))
                {
                    Algorithm.RotateCopy(inputIterator, cloneObj, outputIterator);
                }
            }

            bool isCorrectData = (lst[0] == 4 && lst[1] == 5 &&
                                  lst[2] == 1 && lst[3] == 2 &&
                                  lst[4] == 3);

            Assert.IsTrue(isCorrectData);
        }
Пример #2
0
        public void RotateTest2()
        {
            int[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            IList <int> lst = new List <int>();

            using (IForwardIterator <int> inputIterator = new ForwardIterator <int>(data))
            {
                IShallowClone cloneable = (IShallowClone)inputIterator;

                IForwardIterator <int> cloneObj = cloneable.ShallowClone() as IForwardIterator <int>;
                cloneObj.End();

                ICursor cursor = (ICursor)cloneObj;
                cursor.SetPosition(cursor.GetPosition() - 2);

                //set the first element to 8 element position

                Algorithm.Rotate(inputIterator, cloneObj);

                inputIterator.Begin();

                using (IOutputIterator <int> outputIterator = new BackInsertIterator <int>(lst))
                {
                    Algorithm.Copy(inputIterator, outputIterator);
                }
            }

            bool isCorrectData = (lst[0] == 8 && lst[1] == 9 &&
                                  lst[2] == 1 && lst[3] == 2 &&
                                  lst[4] == 3 && lst[5] == 4 &&
                                  lst[6] == 5 && lst[7] == 6 &&
                                  lst[8] == 7);

            Assert.IsTrue(isCorrectData);
        }
Пример #3
0
 /// <summary>
 /// 获取类型的浅表副本,浅表副本为原内存区域
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static T ShallowClone <T>(IShallowClone <T> value)
 {
     return((T)(object)value);
 }