예제 #1
0
        public void TestIndexedNumsStream_negative2()
        {
            var streamlength = 50;
            var ins          = new IndexedNumsStream(streamlength);

            // test for negative -> should be set to 0
            ins.SetLength(-1);
            Assert.AreEqual(0, ins.Length);

            // other case is set to that length
            ins.SetLength(100);
            Assert.AreEqual(100, ins.Length);
        }
        static void Main(string[] args)
        {
            NumberedTextWriter NTW = new NumberedTextWriter(Console.Out);

            NTW.WriteLine("Hello World!");
            NTW.WriteLine("Hi");
            NTW.WriteLine("Hello World!");

            IndexedNumsStream ins = new IndexedNumsStream(20);

            byte[] buffer = new byte[20];
            ins.Read(buffer, 5, 10);
            foreach (byte i in buffer)
            {
                Console.WriteLine(i);
            }
            ins.Read(buffer, 0, 20);
            foreach (byte i in buffer)
            {
                Console.WriteLine(i);
            }
            ins.Read(buffer, 2, 13);
            foreach (byte i in buffer)
            {
                NTW.WriteLine(i.ToString());
            }
            ins.SetLength(10);
            ins.Read(buffer, 2, 13);
            foreach (byte i in buffer)
            {
                NTW.WriteLine(i.ToString());
            }
            ins.Position = -5;
            ins.Read(buffer, 2, 13);
            foreach (byte i in buffer)
            {
                NTW.WriteLine(i.ToString());
            }
        }
예제 #3
0
파일: main.cs 프로젝트: tymicruz/4dos2
    public static void Main()
    {
        Console.WriteLine("hello, hw1");
        CS422.NumberedTextWriter writer = new CS422.NumberedTextWriter(Console.Out);

        Console.WriteLine("--- NumberedTextWriter Test 1 Constructor ---");
        writer.WriteLine("one");
        writer.WriteLine("two");
        writer.WriteLine("three");
        writer.WriteLine("four");
        writer.WriteLine("five");
        writer.WriteLine("siz");
        writer.WriteLine("seven");
        writer.WriteLine("eight");

        writer = new CS422.NumberedTextWriter(Console.Out, 5);

        Console.WriteLine("--- NumberedTextWriter Test 2 Constructor ---");
        writer.WriteLine("five");
        writer.WriteLine("six");
        writer.WriteLine("seven");
        writer.WriteLine("eight");
        writer.WriteLine("nine");
        writer.WriteLine("ten");
        writer.WriteLine("eleven");
        writer.WriteLine("twelve");

        CS422.IndexedNumsStream stream = new CS422.IndexedNumsStream(256);
        byte[] barry = new byte[5];

        Console.WriteLine("--- IndexedNumsStream Tests ---");

        Console.WriteLine("byte array: ");

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- read 5 from beginning of stream ---");

        stream.Read(barry, 0, 5);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- read another 5 ---");

        stream.Read(barry, 0, 5);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- read another 4 ---");

        stream.Read(barry, 0, 4);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- read another 2 into last 2 ---");

        stream.Read(barry, barry.Length - 2, 2);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- pos = 253, but read 5 (first 3 should change only)---");
        stream.Position = 253;

        stream.Read(barry, 0, 5);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- try read 5 from end, no change ---");

        stream.Read(barry, 0, 5);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }

        Console.WriteLine("--- change stream Length, read 5 ---");
        stream.SetLength(512);
        stream.Read(barry, 0, 5);

        for (int i = 0; i < barry.Length; i++)
        {
            Console.WriteLine(barry[i]);
        }
    }