Example #1
0
        public void testArgumentOutOfRangeException()
        {
            IndexedNumsStream ins = new IndexedNumsStream(600);

            byte[] buffer = new byte[100];
            try{
                ins.Read(buffer, -10, 10);
            } catch (ArgumentOutOfRangeException) {
                Assert.IsTrue(true);
            }

            try{
                ins.Read(buffer, 10, -10);
            } catch (ArgumentOutOfRangeException) {
                Assert.IsTrue(true);
            }
        }
        public void EndOfStreamTest()
        {
            IndexedNumsStream indexedNumStream = new IndexedNumsStream(10L);

            byte[] buffer = new byte[6];

            Console.WriteLine(indexedNumStream.Read(buffer, 0, 4));
            Assert.Pass();
        }
Example #3
0
        public void canBufferHoldData()
        {
            IndexedNumsStream ins = new IndexedNumsStream(600);

            byte[] buffer = new byte[10];

            try{
                ins.Read(buffer, 5, 6);
                Assert.IsTrue(false);
            } catch (ArgumentException) {
                Assert.IsTrue(true);
            }

            try{
                ins.Read(buffer, 5, 5);
            } catch (ArgumentException) {
                Assert.IsTrue(true);
            }
        }
Example #4
0
        public void IndexedNumsStream_negativeCount_Expect0()
        {
            //arrange
            byte[]            buffer = new byte[256];
            IndexedNumsStream test   = new IndexedNumsStream(256);

            //act
            test.Read(buffer, 0, -1);
            //assert
            Assert.AreEqual(0, buffer[0]);
        }
Example #5
0
        public void IndexedNumsStream_TooBigCount_ExpectPass()
        {
            //arrange
            byte[]            buffer = new byte[256];
            IndexedNumsStream test   = new IndexedNumsStream(long.MaxValue);

            //act
            test.Read(buffer, 0, 2086165146);
            //assert
            Assert.AreEqual(2086165146 % 256, buffer[2086165145]);
        }
Example #6
0
        public void testStreamLeftToRead()
        {
            IndexedNumsStream ins = new IndexedNumsStream(7);

            byte[] buffer = new byte[100];

            ins.Seek(4, System.IO.SeekOrigin.Begin);
            int nBytes = ins.Read(buffer, 0, 7);

            Assert.AreEqual(3, nBytes);
        }
Example #7
0
        public void testEndOfStream()
        {
            IndexedNumsStream ins = new IndexedNumsStream(600);

            byte[] buffer = new byte[100];

            ins.Seek(0, System.IO.SeekOrigin.End);
            int actual = ins.Read(buffer, 10, 10);

            Assert.AreEqual(0, actual);
        }
Example #8
0
        public void testNullBuffer()
        {
            IndexedNumsStream ins = new IndexedNumsStream(600);

            byte[] buffer = null;
            try{
                ins.Read(buffer, 10, 10);
            } catch (NullReferenceException) {
                Assert.IsTrue(true);
            }
        }
Example #9
0
        public static void Main(string[] args)
        {
            Console.WriteLine("INS Testing:");
            byte[]            buf1 = new byte[257];
            byte[]            buf2 = new byte[BSIZE];
            IndexedNumsStream ins  = new IndexedNumsStream(SSIZE);

            ins.Read(buf1, 0, 257);
            ins.Read(buf2, 0, COUNT);

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

            for (int i = 0; i < BSIZE; i++)
            {
                Console.WriteLine(buf2[i]);
            }
        }
Example #10
0
        public void testStreamStructure()
        {
            IndexedNumsStream ins = new IndexedNumsStream(600);

            byte[] buffer = new byte[500];
            ins.Read(buffer, 0, 500);

            for (int i = 0; i < buffer.Length; i++)
            {
                Assert.AreEqual(i % 256, buffer [i]);
            }
        }
Example #11
0
        public void IndexedNumsStream_Regular256Buff_ExpectPass()
        {
            //arrange
            byte[]            buffer = new byte[256];
            IndexedNumsStream test   = new IndexedNumsStream(256);

            //act
            test.Read(buffer, 0, 256);
            //assert
            for (int i = 0; i < 256; i++)
            {
                Assert.AreEqual(i % 256, buffer[i]);
            }
        }
Example #12
0
        public void IndexReadWithNoOffset(int offset, int count)
        {
            //Arrange
            IndexedNumsStream stream = new IndexedNumsStream();

            byte[] buffer = new byte[1000];

            //Act
            stream.Read(buffer, offset, count);

            //Assert
            Assert.AreEqual(stream.Length, 255);
            Assert.AreEqual(0, buffer[0]);
            Assert.AreEqual(1, buffer[1]);
            Assert.AreEqual(2, buffer[2]);
        }
Example #13
0
        public void IndexReadToEnd(int offset, int count)
        {
            //Arrange
            IndexedNumsStream stream = new IndexedNumsStream(30);

            byte[] buffer = new byte[1000];
            stream.Position = 29;

            //Act
            stream.Read(buffer, offset, count);

            //Assert
            Assert.AreEqual(30, stream.Length);
            Assert.AreEqual(29, buffer[0]);
            Assert.AreEqual(30, buffer[1]);
            Assert.AreEqual(0, buffer[2]);
        }
Example #14
0
        public void IndexReadOverModBoundry(int offset, int count)
        {
            //Arrange
            IndexedNumsStream stream = new IndexedNumsStream(550);

            byte[] buffer = new byte[1000];
            stream.Position = 254;

            //Act
            stream.Read(buffer, offset, count);

            //Assert
            Assert.AreEqual(550, stream.Length);
            Assert.AreEqual(254, buffer[0]);
            Assert.AreEqual(255, buffer[1]);
            Assert.AreEqual(0, buffer[2]);
        }
        public void BufferTest()
        {
            IndexedNumsStream indexedNumsStream = new IndexedNumsStream(long.MaxValue);

            byte[] buffer = new byte[byte.MaxValue * 2];

            indexedNumsStream.Read(buffer, 0, buffer.Length);

            for (var b = 0; b < buffer.Length; ++b)
            {
                if (buffer[b] != (b % (byte.MaxValue + 1)))
                {
                    Console.WriteLine(b); Assert.Fail();
                }
            }

            Assert.Pass();
        }
Example #16
0
        static void Main(string[] args)
        {
            //Program p = new Program();

            //test NumberedTextWriter
            NumberedTextWriter ntw = new NumberedTextWriter(Console.Out);

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

            //test IndexedNumsStream,
            IndexedNumsStream ins = new IndexedNumsStream(0);

            byte[] buffer = new byte[512];

            ins.SetLength(512);

            ins.Read(buffer, 0, 512);

            foreach (byte num in buffer)
            {
                Console.WriteLine(num);
            }
        }