Exemplo n.º 1
0
        public void WriteAndReadIntsViaDiskFile()
        {
            var file = new DiskFile("test11.dat", "rwb");

            file.UseNativeEndianEncoding();
            Assert.NotNull(file);
            Assert.True(file.CanWrite);
            Assert.True(file.IsBinary);

            var data0 = new int[4];

            for (var i = 0; i < data0.Length; ++i)
            {
                data0[i] = i + 32000000;
            }
            file.WriteInts(data0);
            file.Flush();
            Assert.Equal(data0.Length * sizeof(int), file.Position);
            file.Seek(0);

            var data1 = new int[data0.Length];
            var rd    = file.ReadInts(data1, data0.Length);

            Assert.Equal(rd, data0.Length);
            Assert.Equal(data0.Length * sizeof(int), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.Equal(data0[i], data1[i]);
            }
            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 2
0
        public void WriteAndReadStorageIntsViaDiskFile()
        {
            const int size = 10;

            var file = new DiskFile("test17.dat", "rwb");

            Assert.NotNull(file);
            Assert.True(file.CanWrite);

            var storage0 = new IntTensor.IntStorage(size);

            for (var i = 0; i < size; ++i)
            {
                storage0[i] = i;
            }

            file.WriteInts(storage0);
            Assert.Equal(size * sizeof(int), file.Position);
            file.Seek(0);

            var storage1 = new IntTensor.IntStorage(size);
            var rd       = file.ReadInts(storage1);

            Assert.Equal(rd, size);
            Assert.Equal(size * sizeof(int), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.Equal(storage0[i], storage1[i]);
            }

            file.Close();
            Assert.False(file.IsOpen);
        }