Exemplo n.º 1
0
        public void test_should_raise_exception_if_all_bounds_are_not_calculated()
        {
            IBondPricer local = new NodePricer();
            IBondPricer grid  = new GridPricer();

            BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
            var bonds = GenerateBonds(4, 2, 6);

            Assert.ThrowsException <Exception>(() => bonds[0].Price());
        }
Exemplo n.º 2
0
        public void test_optimal_for_simple_instance3()
        {
            IBondPricer local = new NodePricer();
            IBondPricer grid  = new GridPricer();

            BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
            var bonds  = GenerateBonds(1, 1, 0);
            var result = strategy(bonds, calculator);

            Assert.AreEqual(7, calculator.ComputingTime);
        }
Exemplo n.º 3
0
        public void test_optimal_for_simple_instance()
        {
            IBondPricer local = new NodePricer();
            IBondPricer grid  = new GridPricer();

            BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
            var bonds = new List <Bond> {
                new Bond(BondType.SemiFast), new Bond(BondType.Long), new Bond(BondType.Fast)
            };
            var result = strategy(bonds, calculator);

            Assert.AreEqual(13, calculator.ComputingTime);
        }
Exemplo n.º 4
0
        public void test_grid_should_not_waste_node()
        {
            IBondPricer local = new NodePricer();
            IBondPricer grid  = new GridPricer();

            BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
            var bonds = GenerateBonds(1, 1, 2);

            strategy(bonds, calculator);

            GridPricer castedGrid = (GridPricer)grid;

            Assert.AreEqual(2, castedGrid.NumberOfNodes());
        }
Exemplo n.º 5
0
        public void test_must_calculate_all_bonds()
        {
            IBondPricer local = new NodePricer();
            IBondPricer grid  = new GridPricer();

            BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
            var bonds  = GenerateBonds(4, 2, 6);
            var result = strategy(bonds, calculator);

            foreach (var bond in bonds)
            {
                Assert.AreEqual(bond.Price(), 42);
            }
        }
Exemplo n.º 6
0
 public void test_should_take_less_than_18_seconds()
 {
     for (int i = 0; i < 20; i++)
     {
         for (int j = 0; j < 20; j++)
         {
             for (int z = 0; z < 20; z++)
             {
                 IBondPricer           local      = new NodePricer();
                 IBondPricer           grid       = new GridPricer();
                 BondPricer.BondPricer calculator = new BondPricer.BondPricer(local, grid);
                 var bonds  = GenerateBonds(4, 2, 0);
                 var result = strategy(bonds, calculator);
                 Assert.AreEqual(10, calculator.ComputingTime);
             }
         }
     }
 }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var b1 = new Bond(BondType.Fast);
            var b2 = new Bond(BondType.Long);
            var b3 = new Bond(BondType.SemiFast);

            var bonds = new List <Bond> {
                b1, b2, b3
            };

            var local = new NodePricer();
            var grid  = new GridPricer();

            var calculator = new BondPricer(local, grid);

            b1.ResultComputed += (obj, e) => { Console.WriteLine("Price available for : " + obj.ToString()); };

            var result = PricingStratey.GreedyStrategy(bonds, calculator);

            // shoud be equal 13
            Console.WriteLine(calculator.ComputingTime);
        }