public void float1d() { using (var Container = new TempH5FileContainer()) { var hf = Container.Content(); var dims = new long[] { 7L }; dset1d <float> DSET = hf.Root.CreateDataset("tempdata", 1, dims, typeof(float)) as dset1d <float>; Assert.NotNull(DSET); Assert.Equal(dims, DSET.Dims); var expect = new float[7] { 1, 0, 2, 9, 5, 3, 1 }; DSET.Values = expect; var actual = DSET.Values; Assert.Equal(expect, actual); Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1]); Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[9]); DSET.Dispose(); } }
public void Elements() { using (H5File hf = H5File.Open(testfile, mode: "r")) { using (dset1d <int> DSET = hf.Root["datasets/int1d"] as dset1d <int>) { Assert.NotNull(DSET); var actual = DSET.Elements().ToArray(); var expected = new int[] { 0, 1, 2, 3, 4, 5, 6 }; Assert.Equal(expected, actual); } using (dset2d <int> DSET = hf.Root["datasets/int2d"] as dset2d <int>) { Assert.NotNull(DSET); var actual = DSET.Elements().Skip(5 * 7 + 4).Take(7).ToArray(); var expected = new int[7] { 0, 25, 0, 0, 1, 4, 9 }; Assert.Equal(expected, actual); } } }
public void double1d() { using (var container = new TempH5FileContainer()) { H5Group ROOT = container.Content().Root; int rank = 1; var dims = new long[] { 3 }; using (dset1d <double> DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(double)) as dset1d <double>) { Assert.NotNull(DSET); Assert.Equal(dims, DSET.Dims); DSET[0] = 3.14; DSET[1] = 3.14; DSET[2] = 3.14; Assert.Throws <IndexOutOfRangeException>(() => DSET[3]); Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = 3.14); Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]); Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = 3.14); } } }
public void AttemptToWriteClosedFileFails() { string path = Path.GetTempFileName(); H5File FILE = H5File.Open(path, mode: "w"); // create some stuff.. H5Group GROUP = FILE.Root.SubGroup("foo", create: true); GROUP.CreateDataset("bar", 1, new long[] { 7L }, typeof(byte)); dset1d <byte> DSET = GROUP["bar"] as dset1d <byte>; Assert.NotNull(DSET); DSET[3] = 5; // close all H5Objects manually in this test-scenario: GROUP.Dispose(); DSET.Dispose(); FILE.Dispose(); // the file.ID becomes the H5F.close() return value, which is often // (but not guaranteed to be) zero / non-negative: Assert.Equal((H5Ohm.hid_t) 0, FILE.ID); Assert.Equal((H5Ohm.hid_t) 0, FILE.Root.ID); Assert.Equal((H5Ohm.hid_t) 0, DSET.ID); Assert.Equal((H5Ohm.hid_t) 0, GROUP.ID); Assert.Throws <InvalidOperationException>(() => FILE.Root["foo/bar"]); Assert.Throws <InvalidOperationException>(() => DSET[5] = 3); Assert.Throws <InvalidOperationException>(() => GROUP["bar"]); }
public void float1d() { using (H5File hf = H5File.Open(testfile, mode: "r")) { dset1d <float> DSET = hf.Root["datasets/float1d"] as dset1d <float>; Assert.NotNull(DSET); Assert.Equal(Edge, DSET.Length); Assert.Equal(typeof(float), DSET.PrimitiveType); float[] expected = new float[] { 0, 1, 2, 3, 4, 5, 6 }; float[] actual = new float[Edge]; for (long i = 0; i < DSET.Dims[0]; i++) { actual[i] = DSET[i]; } Assert.Equal(expected, actual); } }