Exemple #1
0
        public void CopyTo()
        {
            const string      initBufContent = "123456";
            SplitArray <char> sary           = new SplitArray <char>(5, 8);

            char[] buf;
            sary.Insert(0, "hogepiyo".ToCharArray());

            // before head to middle
            buf = initBufContent.ToCharArray();
            MyAssert.Throws <AssertException>(delegate {
                sary.CopyTo(-1, 5, buf);
            });

            // begin to middle
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 5, buf);
            Assert.AreEqual("hogep6", new String(buf));

            // middle to middle
            buf = initBufContent.ToCharArray();
            sary.CopyTo(1, 5, buf);
            Assert.AreEqual("ogep56", new String(buf));

            // middle to end
            buf = initBufContent.ToCharArray();
            sary.CopyTo(5, 8, buf);
            Assert.AreEqual("iyo456", new String(buf));

            // end to after end
            buf = initBufContent.ToCharArray();
            MyAssert.Throws <AssertException>(delegate {
                sary.CopyTo(5, 9, buf);
            });

            // Range before the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 1, buf);
            Assert.AreEqual("h23456", new String(buf));

            // Range including the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 4, buf);
            Assert.AreEqual("hoge56", new String(buf));

            // Range after the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(4, 8, buf);
            Assert.AreEqual("piyo56", new String(buf));
        }
        static void Test_CopyTo()
        {
            const string      initBufContent = "123456";
            SplitArray <char> sary           = new SplitArray <char>(5, 8);

            char[] buf;
            sary.Insert(0, "hogepiyo".ToCharArray());

            // before head to middle
            buf = initBufContent.ToCharArray();
            try{ sary.CopyTo(-1, 5, buf); Debug.Fail("Exception wasn't thrown as expected."); }
            catch (Exception ex) { TestUtl.AssertType <AssertException>(ex); }

            // begin to middle
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 5, buf);
            TestUtl.AssertEquals("hogep6", new String(buf));

            // middle to middle
            buf = initBufContent.ToCharArray();
            sary.CopyTo(1, 5, buf);
            TestUtl.AssertEquals("ogep56", new String(buf));

            // middle to end
            buf = initBufContent.ToCharArray();
            sary.CopyTo(5, 8, buf);
            TestUtl.AssertEquals("iyo456", new String(buf));

            // end to after end
            buf = initBufContent.ToCharArray();
            try{ sary.CopyTo(5, 9, buf); Debug.Fail("Exception wasn't thrown as expected."); }
            catch (Exception ex) { TestUtl.AssertType <AssertException>(ex); }

            // Range before the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 1, buf);
            TestUtl.AssertEquals("h23456", new String(buf));

            // Range including the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(0, 4, buf);
            TestUtl.AssertEquals("hoge56", new String(buf));

            // Range after the gap
            MoveGap(sary, 2);
            buf = initBufContent.ToCharArray();
            sary.CopyTo(4, 8, buf);
            TestUtl.AssertEquals("piyo56", new String(buf));
        }