Example #1
0
        public void WriteAndReadDoublesViaDiskFile()
        {
            var file = new DiskFile("test14.dat", "rwb");

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

            var data0 = new double[4];

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

            var data1 = new double[data0.Length];
            var rd    = file.ReadDoubles(data1, data0.Length);

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

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

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

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

            var storage0 = new DoubleTensor.DoubleStorage(size);

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

            file.WriteDoubles(storage0);
            Assert.Equal(size * sizeof(double), file.Position);
            file.Seek(0);

            var storage1 = new DoubleTensor.DoubleStorage(size);
            var rd       = file.ReadDoubles(storage1);

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

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

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