Example #1
0
        public void ReadThatGoesOverTheEndThrows()
        {
            var mem = new VirtualMemory();
            var buf = new byte[20];

            Assert.Throws <IndexOutOfRangeException>(() => mem.Read(0, buf));

            mem.Attach(0, new FixedMemory(5));
            mem.Attach(5, new FixedMemory(5));

            Assert.Throws <IndexOutOfRangeException>(() => mem.Read(0, buf));
            Assert.Throws <IndexOutOfRangeException>(() => mem.Read(7, buf));
            Assert.Throws <IndexOutOfRangeException>(() => mem.Read(15, buf));
        }
Example #2
0
        public void ReadContainedInOneMemory()
        {
            var mem  = new VirtualMemory();
            var ram1 = CreateFixedMemory(10);

            mem.Attach(0, ram1);

            var buf = new byte[5];

            mem.Read(1, buf);
            Assert.Equal(new byte[] { 2, 3, 4, 5, 6 }, buf);
        }
Example #3
0
        public void ReadSpanningTwoAdjacentMemories()
        {
            var mem  = new VirtualMemory();
            var ram1 = CreateFixedMemory(10);
            var ram2 = CreateFixedMemory(10);

            mem.Attach(0, ram1);
            mem.Attach(10, ram2);

            var buf = new byte[5];

            mem.Read(8, buf);
            Assert.Equal(new byte[] { 9, 10, 1, 2, 3 }, buf);
        }
Example #4
0
        public void ReadOutsideOfAnyMemoryProducesAllZeros()
        {
            var mem  = new VirtualMemory();
            var ram1 = CreateFixedMemory(5);
            var ram2 = CreateFixedMemory(5);

            mem.Attach(0, ram1);
            mem.Attach(20, ram2);

            var buf = new byte[5];

            mem.Read(10, buf);
            Assert.True(buf.All(b => b == 0));
        }
Example #5
0
        public void ReadSpanningTwoMemoriesWithAGap()
        {
            var mem  = new VirtualMemory();
            var ram1 = CreateFixedMemory(10);
            var ram2 = CreateFixedMemory(10);

            mem.Attach(0, ram1);
            mem.Attach(15, ram2);

            var buf = new byte[15];

            mem.Read(5, buf);
            Assert.Equal(new byte[] {
                6, 7, 8, 9, 10,
                0, 0, 0, 0, 0,
                1, 2, 3, 4, 5
            }, buf);
        }
Example #6
0
        public void ReadDoesNotIncludeDetachedMemory()
        {
            var mem  = new VirtualMemory();
            var ram1 = CreateFixedMemory(10);
            var ram2 = CreateFixedMemory(10);

            mem.Attach(0, ram1);
            mem.Attach(15, ram2);
            mem.Detach(ram1);

            var buf = new byte[15];

            mem.Read(5, buf);
            Assert.Equal(new byte[] {
                0, 0, 0, 0, 0,
                0, 0, 0, 0, 0,
                1, 2, 3, 4, 5
            }, buf);
        }