Ejemplo n.º 1
0
        public void AddIncorrectNumberOfKeys()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube = new Cube.Cube <CubeValueDouble>(axisSet);

            try
            {
                cube.AddItem(new object [] { "Value1" }, new CubeValueDouble(2));
                Assert.Fail("Should have thrown");
            }
            catch
            {
            }

            try
            {
                cube.AddItem(new object [] { "Value1", DateTime.Today, 2.3 }, new CubeValueDouble(2));
                Assert.Fail("Should have thrown");
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        public void AddOverridingValues()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Axis 2", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube = new Cube.Cube <CubeValueDouble>(axisSet);

            var refDate = DateTime.Today;
            var keys    = new object [] { "Val1", "Val2", refDate };
            var keys2   = new object [] { "Val1", "Val2", refDate };

            var val1 = new CubeValueDouble(2.3);
            var val2 = new CubeValueDouble(3.7);

            Assert.IsTrue(cube.AddItem(keys, val1));
            Assert.IsFalse(cube.AddItem(keys, val2));

            Assert.AreEqual(1, cube.Count());
            var combinedValue = cube.First();

            Assert.AreNotSame(val1, combinedValue.CubeValue);
            Assert.AreNotSame(val2, combinedValue.CubeValue);
            Assert.AreEqual(2.3 + 3.7, combinedValue.CubeValue.Val);
        }
Ejemplo n.º 3
0
        public void GetEnumerator_Validate()
        {
            var items = new Tuple <string, Type, bool> []
            {
                Tuple.Create("Axis1", typeof(string), true),
                Tuple.Create("Axis2", typeof(double), true),
                Tuple.Create("Axis3", typeof(float), true),
            };

            var axisSet = new AxisSet(items.Select(tuple => new Axis(tuple.Item1, tuple.Item2, tuple.Item3)).ToArray());

            var enumerator1 = items.GetEnumerator();
            var enumerator2 = axisSet.GetEnumerator();

            while (enumerator1.MoveNext())
            {
                Assert.IsTrue(enumerator2.MoveNext());

                var current = (Tuple <string, Type, bool>)enumerator1.Current;

                Assert.AreEqual(current.Item1, enumerator2.Current.Name);
                Assert.AreEqual(current.Item2, enumerator2.Current.DataType);
                Assert.AreEqual(current.Item3, enumerator2.Current.AllowTotals);
            }

            Assert.IsFalse(enumerator2.MoveNext());
        }
Ejemplo n.º 4
0
            public void NoOverlappingAxes()
            {
                var axisSet1 = new AxisSet(new Axis("Axis 1", typeof(string)));
                var axisSet2 = new AxisSet(new Axis("Axis 2", typeof(string)));

                var cube1 = new Cube <DoubleValue>(axisSet1);
                var cube2 = new Cube <DoubleValue>(axisSet2);

                Assert.IsFalse(CubeUtils.TryCombineObjectsAsCubes(new object [] { cube1, cube2 }, out var cube, out var cubeValueType));
            }
Ejemplo n.º 5
0
        public void HandleDuplicateAxisNames()
        {
            try
            {
                var axisSet = new AxisSet(
                    new Axis("Axis", typeof(string), true),
                    new Axis("Axis", typeof(string), false));

                Assert.Fail("Duplicate axis allowed");
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 6
0
        public void AddRelevantError()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube = new Cube.Cube <CubeValueDouble>(axisSet);

            var errorKeys = new Dictionary <string, object>();

            errorKeys ["Axis 1"] = "Bob";
            cube.AddError(errorKeys, "Error");
        }
Ejemplo n.º 7
0
        public void RandomAccess()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Axis 2", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube             = new Cube.Cube <CubeValueDouble>(axisSet);
            var simpleDictionary = new Dictionary <DictionaryKey, double>();

            var refDate = DateTime.Today;

            for (int loopIdx1 = 0; loopIdx1 < 10; loopIdx1++)
            {
                for (int loopIdx2 = 0; loopIdx2 < 10; loopIdx2++)
                {
                    for (int loopIdx3 = 0; loopIdx3 < 30; loopIdx3++)
                    {
                        object [] keys = new object [3];
                        keys [0] = string.Format("Axis 1 - {0}", loopIdx1);
                        keys [1] = string.Format("Axis 2 - {0}", loopIdx2);
                        keys [2] = refDate.AddDays(loopIdx3);

                        CubeValueDouble val = new CubeValueDouble();
                        val.Val  = loopIdx1 * 1000;
                        val.Val += loopIdx2 * 100;
                        val.Val += loopIdx3;
                        cube.AddItem(keys, val);
                    }
                }
            }

            // Check random access
            {
                CubeValueDouble matchedValue;
                Assert.IsTrue(cube.TryGetValue(new object [] { "Axis 1 - 5", "Axis 2 - 7", refDate.AddDays(22) }, out matchedValue));
                Assert.AreEqual(5722, matchedValue.Val);
            }
        }
Ejemplo n.º 8
0
        public void AddErrorWithWrongDataType()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube = new Cube.Cube <CubeValueDouble>(axisSet);

            var errorKeys = new Dictionary <string, object>();

            errorKeys ["Axis 1 "] = DateTime.Today;

            try
            {
                cube.AddError(errorKeys, "Error");
                Assert.Fail("Shouldn't be able to add error");
            }
            catch
            {
            }
        }
Ejemplo n.º 9
0
        public void Iteration()
        {
            var axisSet = new AxisSet(new Axis []
            {
                new Axis("Axis 1", typeof(string), true),
                new Axis("Axis 2", typeof(string), true),
                new Axis("Expiry Date", typeof(DateTime), true)
            });

            var cube             = new Cube.Cube <CubeValueDouble>(axisSet);
            var simpleDictionary = new Dictionary <DictionaryKey, double>();

            var refDate = DateTime.Today;

            for (int loopIdx1 = 0; loopIdx1 < 10; loopIdx1++)
            {
                for (int loopIdx2 = 0; loopIdx2 < 10; loopIdx2++)
                {
                    for (int loopIdx3 = 0; loopIdx3 < 100; loopIdx3++)
                    {
                        object [] keys = new object [3];
                        keys [0] = string.Format("Axis 1 - {0}", loopIdx1);
                        keys [1] = string.Format("Axis 2 - {0}", loopIdx2);
                        keys [2] = refDate.AddDays(loopIdx3);

                        CubeValueDouble val = new CubeValueDouble();
                        val.Val  = loopIdx1 * 1000;
                        val.Val += loopIdx2 * 100;
                        val.Val += loopIdx3;
                        cube.AddItem(keys, val);

                        simpleDictionary [new DictionaryKey((string)keys [0], (string)keys [1], (DateTime)keys [2])] = val.Val;
                    }
                }
            }

            // Check random access
            {
                CubeValueDouble matchedValue;
                Assert.IsTrue(cube.TryGetValue(new object [] { "Axis 1 - 5", "Axis 2 - 7", refDate.AddDays(22) }, out matchedValue));
                Assert.AreEqual(5722, matchedValue.Val);
            }

            // Ensure that we can iterate over each point in a cube
            foreach (var cubePoint in cube)
            {
                string   axis1 = (string)cubePoint.GetAxisValue(0);
                string   axis2 = (string)cubePoint.GetAxisValue(1);
                DateTime date  = (DateTime)cubePoint.GetAxisValue(2);

                var    dictKey = new DictionaryKey(axis1, axis2, date);
                double expectedValue;
                if (!simpleDictionary.TryGetValue(dictKey, out expectedValue))
                {
                    Assert.Fail("No value found for key");
                }

                simpleDictionary.Remove(dictKey);

                Assert.AreEqual(expectedValue, cubePoint.CubeValue.Val);
            }

            Assert.AreEqual(0, simpleDictionary.Count);
        }