public void Extract() { BlockArray ba; BlockArray ex; //------------------------- ba = new BlockArray(); ex = ba.Extract(0, 0); Assert.Equal(0, ex.Size); Assert.Equal(0, ex.Count); //------------------------- ba = new BlockArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); ex = ba.Extract(0, 10); Assert.Equal(10, ex.Size); Assert.Equal(1, ex.Count); Assert.Equal(0, ex.GetBlock(0).Offset); Assert.Equal(10, ex.GetBlock(0).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.GetBlock(0).Buffer); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ba.GetBlock(0).Offset = 5; ba.GetBlock(0).Length = 5; ba.Reload(); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ba.ToByteArray()); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); //------------------------- ba = new BlockArray(new Block(new byte[] { 0, 0, 0, 0, 0, 0, 1, 2, 3, 4 }, 5, 5), new Block(new byte[] { 0, 0, 0, 0, 0, 5, 6, 7, 8, 9 }, 5, 5)); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ba.ToByteArray()); ex = ba.Extract(0, 10); Assert.Equal(2, ex.Count); Assert.Equal(5, ex.GetBlock(0).Offset); Assert.Equal(5, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(5, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ex = ba.Extract(2, 5); Assert.Equal(2, ex.Count); Assert.Equal(7, ex.GetBlock(0).Offset); Assert.Equal(3, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(2, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 2, 3, 4, 5, 6 }, ex.ToByteArray()); ex = ba.Extract(5); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ex.ToByteArray()); }
public void AddFromBlockArray() { BlockArray ba1; BlockArray ba2; ba1 = new BlockArray(); ba1.Append(new byte[] { 0, 1, 2, 3, 4 }); ba2 = new BlockArray(); ba2.Append(new byte[] { 5, 6, 7, 8, 9 }); ba2.Append(new byte[] { 10, 11, 12, 13, 14 }); ba2.Append(new byte[] { 15, 16, 17, 18, 19 }); ba2.Append(new byte[] { 20, 21, 22, 23, 24 }); ba1.Append(ba2, 2, 2); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }, ba1.ToByteArray()); ba1.SetExactSize(5); Assert.Equal(new byte[] { 0, 1, 2, 3, 4 }, ba1.ToByteArray()); ba1.Append(ba2); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }, ba1.ToByteArray()); }