예제 #1
0
            public void string2d_To2dArray()
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    string2d DSET = hf.Root["datasets/string2d"] as string2d;

                    Assert.NotNull(DSET);
                    Assert.Equal(5 * 5, DSET.Length);

                    var expect = new string[5, 5] {
                        { "foo", "", "", "", "", },
                        { "", "bar", "", "", "", },
                        { "", "", "zoom", "", "", },
                        { "", "", "", "grok", "", },
                        { "foo", "bar", "zoom", "grok", "yom" },
                    };

                    var actual = DSET.Values;

                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Assert.Equal(expect[i, j], actual[i, j]);
                        }
                    }
                }
            }
예제 #2
0
            [InlineData("datasets/string2d_32")]        //  32 byte string length
            public void string2d(string key)
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    string2d DSET = hf.Root[key] as string2d;

                    Assert.NotNull(DSET);
                    Assert.Equal(25, DSET.Length);
                    Assert.Equal(typeof(string), DSET.PrimitiveType);

                    string[] expect = { "foo", "bar", "zoom", "grok", "yom" };

                    Assert.Equal(expect, DSET[4]);

                    for (long i = 0; i < DSET.Dims[0]; i++)
                    {
                        Assert.Equal(expect[i], DSET[i, i]);
                    }
                }
            }
예제 #3
0
                public void string2d()
                {
                    using (var container = new TempH5FileContainer())
                    {
                        H5Group ROOT = container.Content().Root;

                        int rank = 2;
                        var dims = new long[] { 3, 2 };

                        using (string2d DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(string)) as string2d)
                        {
                            Assert.NotNull(DSET);
                            Assert.Equal(dims, DSET.Dims);

                            DSET[0, 0] = "foo";
                            DSET[2, 1] = "bar";
                            DSET[1]    = new string[] { "zoom", "grok" };

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = new string[] { "foo", "bar" });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = new string[] { "foo", "bar" });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[0] = new string[] { "foo", "bar", "zoom" });
                        }
                    }
                }
예제 #4
0
                public void string2d()
                {
                    using (var Container = new TempH5FileContainer())
                    {
                        var hf = Container.Content();

                        var dims = new long[] { 3L, 2L };

                        string2d DSET = hf.Root.CreateDataset("tempdata", 2, dims, typeof(string)) as string2d;

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        var expect = new string[3, 2] {
                            { "foo", "bar" },
                            { "zoom", "grok" },
                            { "", "a;seoliruo345uta;gojasd;gljasdlkfjas;eitj;lefgj" },
                        };

                        DSET.Values = expect;

                        var actual = DSET.Values;

                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 2; j++)
                            {
                                Assert.Equal(expect[i, j], actual[i, j]);
                            }
                        }

                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[1, 1]);
                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[1, 5]);

                        DSET.Dispose();
                    }
                }