public void MultiTransform()
        {
            var c = new DataCube2 <int, int, int>();

            c.Set(0, 0, 1);
            c.Set(0, 1, 10);
            c.Set(1, 0, 100);
            c.Set(1, 1, 1000);

            // Transforms each position to all "lower" positions.
            var transformed = c.MultiTransform(
                p =>
            {
                var range1 = Enumerable.Range(0, p.ProductValue1 + 1);
                var range2 = Enumerable.Range(0, p.ProductValue2 + 1);
                return(range1.SelectMany(r1 => range2.Select(r2 => Position2.Create(r1, r2))));
            },
                (a, b) => a + b
                );

            Assert.Equal(1111, transformed.Get(0, 0).Get());
            Assert.Equal(1010, transformed.Get(0, 1).Get());
            Assert.Equal(1100, transformed.Get(1, 0).Get());
            Assert.Equal(1000, transformed.Get(1, 1).Get());
        }
        public void Contains()
        {
            var c = new DataCube2 <int, string, int>();

            c.Set(1, "foo", 42);
            Assert.True(c.Contains(Position2.Create(1, "foo")));
            Assert.True(c.Contains(1, "foo"));

            c.Set(2, "bar", 123);
            Assert.True(c.Contains(Position2.Create(2, "bar")));
            Assert.True(c.Contains(2, "bar"));

            Assert.False(c.Contains(Position2.Create(1, "bar")));
            Assert.False(c.Contains(1, "bar"));
        }
        public void GetOrElseSet()
        {
            var c = new DataCube2 <int, string, int>();

            c.Set(1, "foo", 42);

            Assert.Equal(42, c.GetOrElseSet(Position2.Create(1, "foo"), _ => 123));
            Assert.Equal(42, c.Get(1, "foo").Get());
            Assert.Equal(42, c.GetOrElseSet(1, "foo", _ => 123));
            Assert.Equal(42, c.Get(1, "foo").Get());

            Assert.Equal(123, c.GetOrElseSet(Position2.Create(2, "bar"), _ => 123));
            Assert.Equal(123, c.Get(2, "bar").Get());
            Assert.Equal(456, c.GetOrElseSet(3, "baz", _ => 456));
            Assert.Equal(456, c.Get(3, "baz").Get());
        }
        public void Positions()
        {
            var c = new DataCube2 <int, string, int>();

            Assert.Empty(c.Positions);

            c.Set(1, "foo", 42);
            Assert.Single(c.Positions);
            Assert.Contains(Position2.Create(1, "foo"), c.Positions);

            c.Set(1, "foo", 43);
            Assert.Single(c.Positions);
            Assert.Contains(Position2.Create(1, "foo"), c.Positions);

            c.Set(2, "bar", 123);
            Assert.Equal(2, c.Positions.Count());
            Assert.Contains(Position2.Create(1, "foo"), c.Positions);
            Assert.Contains(Position2.Create(2, "bar"), c.Positions);
        }