public void WriteAndReadBytesViaDiskFile() { var file = new Torch.IO.DiskFile("testF.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var data0 = new byte[4]; for (var i = 0; i < data0.Length; ++i) { data0[i] = (byte)i; } file.WriteBytes(data0); //Assert.AreEqual(data0.Length*sizeof(byte), file.Position); file.Seek(0); var data1 = new byte[data0.Length]; var rd = file.ReadBytes(data1, data0.Length); Assert.AreEqual(rd, data0.Length); //Assert.AreEqual(data0.Length * sizeof(byte), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(data0[i], data1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadStorageBytesViaDiskFile() { const int size = 10; var file = new Torch.IO.DiskFile("test15.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var storage0 = new AtenSharp.ByteTensor.ByteStorage(size); for (var i = 0; i < size; ++i) { storage0[i] = (byte)i; } file.WriteBytes(storage0); Assert.AreEqual(size * sizeof(byte), file.Position); file.Seek(0); var storage1 = new AtenSharp.ByteTensor.ByteStorage(size); var rd = file.ReadBytes(storage1); Assert.AreEqual(rd, size); Assert.AreEqual(size * sizeof(byte), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(storage0[i], storage1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }