예제 #1
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);
        }
예제 #2
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);
            }
        }
예제 #3
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);
        }