Exemplo n.º 1
0
        public void WriteAndReadDoubleTensorViaDiskFile()
        {
            const int size = 10;

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

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

            var tensor0 = new DoubleTensor(size);

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

            file.WriteTensor(tensor0);
            Assert.Equal(size * sizeof(double), file.Position);
            file.Seek(0);

            var tensor1 = new DoubleTensor(size);
            var rd      = file.ReadTensor(tensor1);

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

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

            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 2
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.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void CreateReadWritableDiskFile()
        {
            var file = new DiskFile("test2.dat", "rwb");

            Assert.True(file.CanRead);
            Assert.True(file.CanWrite);
            Assert.True(file.IsBinary);
            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 6
0
        public void WriteCharToDiskFile()
        {
            var file = new DiskFile("test3c.dat", "wb");

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

            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 7
0
        public void CreateAutoSpacingDiskFile()
        {
            var file = new DiskFile("test1as.dat", "w");

            Assert.True(file.IsAutoSpacing);
            file.IsAutoSpacing = false;
            Assert.False(file.IsAutoSpacing);
            file.IsAutoSpacing = true;
            Assert.True(file.IsAutoSpacing);

            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 8
0
        public void CreateQuietDiskFile()
        {
            var file = new DiskFile("test1q.dat", "w");

            Assert.False(file.IsQuiet);
            file.IsQuiet = true;
            Assert.True(file.IsQuiet);
            file.IsQuiet = false;
            Assert.False(file.IsQuiet);

            file.Close();
            Assert.False(file.IsOpen);
        }
Exemplo n.º 9
0
        public void WriteAndReadDoubleViaDiskFile()
        {
            var file = new DiskFile("testE.dat", "rwb");

            Assert.NotNull(file);
            Assert.True(file.CanWrite);
            file.WriteDouble(13);
            file.WriteDouble(17);
            file.Seek(0);
            var rd = file.ReadDouble();

            Assert.Equal(13, rd);
            rd = file.ReadDouble();
            Assert.Equal(17, rd);

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