public void EvaluatePolicy() { // Make sure lists have been updated in view NotifyPropertyChanged("Drivers"); NotifyPropertyChanged("Claims"); // Check rules to see if policy is valid IDeclineFactory decline = new DeclineFactory(); DeclineRuleSet declineRules = decline.create(); Result result = declineRules.assessRules(_policy); if (result.isSuccess) { // Run rules to calculate premium ICalculationFactory calculate = new CalculationFactory(); CalculationRuleSet rules = calculate.create(); // Set total to premium Premium = rules.assessRules(_policy); Output = "Premium updated successfully"; } else { Output = result.message; } }
public ActionResult <string> Get(int id) { double initialInvst = 200000; double discountRate = .04; List <double> yearlyCashFlows = new List <double>(); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); FinancialReturnInputs finROIInputs = new FinancialReturnInputs(); finROIInputs.InitialInvestment = initialInvst; finROIInputs.CashInFlows = yearlyCashFlows; finROIInputs.DiscountRate = discountRate; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed = calcuationNPV.Execute(); return(calcuationNPV.Result.ToString()); }
static void Main(string[] args) { var calc = CalculationFactory.CreateCalculation(); calc.GetInput(); calc.RunCalculation(); calc.DisplayOutput(); }
public void TestInitialize() { expected = 5; a = 20; b = 4; factory = new CalculationFactory(); }
private void button1_Click(object sender, EventArgs e) { ITaxInterface taxSelected = CalculationFactory.CreateTaxClass(comboBox1.SelectedIndex); taxSelected.Amount = decimal.ToDouble(numericUpDown1.Value); DialogResult res = MessageBox.Show( "This is the tax for your region:\n" + taxSelected.CalculateTax().ToString(), "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="amount">The amount.</param> /// <param name="discountingType">The discounting type.</param> /// <param name="effectiveDate">The base date.</param> /// <param name="tenor">The maturity tenor.</param> /// <param name="fxdDayFraction">The fixed leg day fraction.</param> /// <param name="businessCenters">The payment business centers.</param> /// <param name="businessDayConvention">The payment business day convention.</param> /// <param name="fxdFrequency">The business day adjustments.</param> /// <param name="underlyingRateIndex">Index of the rate.</param> /// <param name="fixedRate">The fixed rate.</param> /// <param name="id">The identifier.</param> /// <param name="baseDate">The base date.</param> /// <param name="currency">THe currency.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> public PriceableSimpleIRSwap(string id, DateTime baseDate, string currency, decimal amount, DiscountingTypeEnum?discountingType, DateTime effectiveDate, string tenor, string fxdDayFraction, string businessCenters, string businessDayConvention, string fxdFrequency, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : this(baseDate, SimpleIrsHelper.Parse(id, currency, fxdDayFraction, tenor, fxdFrequency, id), effectiveDate, CalculationFactory.CreateFixed(fixedRate.value, MoneyHelper.GetAmount(amount, currency), DayCountFractionHelper.Parse(fxdDayFraction), discountingType), BusinessDayAdjustmentsHelper.Create(businessDayConvention, businessCenters), underlyingRateIndex, fixingCalendar, paymentCalendar, fixedRate) { }
public void ControllerErrorPayloadTooLargeOrSmall(CalculationType calculationType) { // arrange var calcFactory = new CalculationFactory(); // act var calc = calcFactory.Build(calculationType); // assert calc.GetType().Name.Should().Contain(calculationType.ToString()); }
public void NegateOperatorChangesNegativeNumberStringToPositiveNumberString() { //ARRANGE var tester = new CalculationFactory(); string firstNumberString = "-34"; //ACT var actual = tester.NegationOperation(firstNumberString); //ASSERT Assert.That(actual, Is.EqualTo("34")); }
public void ToTestForZeroDivision() { //ARRANGE var tester = new CalculationFactory(); string firstNumberString = "60"; string secondNumberString = "0"; //ACT & ASSERT Assert.Throws <DivideByZeroException>( () => tester.DivisionOperation(firstNumberString, secondNumberString) ); }
public void ToTestThatAddtionMethodReturnsCorrectStringValueOfAddingTwoStrings() { //ARRANGE var tester = new CalculationFactory(); string firstNumberString = "67"; string secondNumberString = "10"; //ACT var actual = tester.AdditionOperation(firstNumberString, secondNumberString); //ASSERT Assert.That(actual, Is.EqualTo("77")); }
public void TestMultiAdd() { // Arrange var creator = new CalculationFactory(); ICalculate calculate = creator.FactoryMethod(CalculationCreator.OperationType.BigSum); List <string> mylist = new List <string>(new string[] { "121556550", "15589455452", "2254564555565552", "5554525455454554565" }); // Act string multiResult = calculate.Calculate(mylist); // Assert Assert.AreEqual(multiResult, "5556780035721132119"); }
private static void perform(CalculationFactory factory) { Console.WriteLine(); Console.WriteLine("--- Using CalculationFactory : " + factory.GetType() + " ---"); Value val1 = factory.createOneElement(); Value val2 = factory.createAddOperation().Add(val1, val1); Value val3 = factory.createAddOperation().Add(val2, val2); Console.WriteLine("OneElement = " + val1.GetStringValue()); Console.WriteLine("OneElement+OneElement = " + val2.GetStringValue()); Console.WriteLine("OneElement+OneElement+OneElement+OneElement = " + val3.GetStringValue()); Console.WriteLine(); }
static void Main(string[] args) { var locations = new List <string> { "Portugal", "Spain", "Italy" }; foreach (var location in locations) { var paymentService = CalculationFactory.GetInstanceFor(location); paymentService.CalculatePayment(10, 40); Console.WriteLine(); Console.WriteLine("*************************************************"); Console.WriteLine(); } Console.ReadLine(); }
public static void RegisterTypes(IUnityContainer container) { HandlerFactory.RegisterHandlers(container); CalculationFactory.RegisterCalculations(container); RegisterDataEntryServices(container); container.RegisterType <IFactorsService>( new InjectionFactory(c => CreateFactorsService())); container.RegisterType <IAccountService, AccountService>( new HierarchicalLifetimeManager(), new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>()); container.RegisterType <ISourceDataContext, SourceDataContext>( new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>()); container.RegisterType <ICalculationDataContext, CalculationDataContext>( new HierarchicalLifetimeManager(), new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>()); container.RegisterType <IDataEntriesUnitOfWork, DataEntriesUnitOfWork>( new HierarchicalLifetimeManager(), new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>()); container.RegisterType <IDataSourceService, DataSourceService>( new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>()); container.RegisterType <DataContext, DataContext>(); container.RegisterType <ISliceService, SliceService>(); container.RegisterType <IEmailManager, EmailManager>(); container.RegisterType <ICalculationFactory, CalculationFactory>(); container.RegisterType <IHandlerFactory, HandlerFactory>(); container.RegisterType <IStreamManager, StreamManager>(); container.RegisterType <ITreeWalkService, TreeWalkService>(); container.RegisterType <TreeWalkController, TreeWalkController>(); container.RegisterType <OverviewReportController, OverviewReportController>(); }
public static IHostBuilder CreateHostBuilder(string[] args) { return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, config) => { config.AddJsonFile("appsettings.json", optional: true, true); config.AddEnvironmentVariables(); if (args != null) { config.AddCommandLine(args); } }) .ConfigureServices((hostContext, services) => { services.AddOptions(); var nLogConfig = hostContext.Configuration.GetSection("NLog"); LogManager.Configuration = new NLogLoggingConfiguration(nLogConfig); ILogger logger = LogManager.GetCurrentClassLogger(); services.AddSingleton(logger); services.Configure <AlgorithmServiceConfige>(hostContext.Configuration.GetSection("AlgorithmServiceConfige")); var dataProvider = hostContext.Configuration.GetSection("DataProvider").Get <DataProvider>(); IMapper mapper = DownloaderProvider.AutoMapperConfiguration.Configure().CreateMapper(); IServiceActions serviceActions = new ServiceActions(dataProvider.KarmaDownloader, mapper); ITaskActions taskActions = new TaskActions(dataProvider.KarmaDownloader, mapper); IMapper cbrDownloaderMapper = CbrDownloader.AutoMapperConfiguration.Configure().CreateMapper(); ICbrDownloader cbrDownloader = new CbrProvider(logger, cbrDownloaderMapper); IMapper moexMapper = MoexProvider.AutoMapperConfiguration.Configure().CreateMapper(); IMoexDownloader moexDownloader = new MoexDownloader(moexMapper, logger); IXmlSaver xmlSaver = new XmlSaver.XmlSaver(); ICsvSaver csvSaver = new CsvSaver.CsvSaver(); IConverterFactory converterFactory = new ConverterFactory(); IMapper saverMurrMapper = SaverMurrData.AutoMapperConfiguration.Configure().CreateMapper(); ISaverMurrData saverMurrData = new SaverMurrProvider(logger, saverMurrMapper, dataProvider.KarmaSaver); ICalculationFactory calculationFactory = new CalculationFactory(logger, taskActions, cbrDownloader, moexDownloader, xmlSaver, csvSaver, converterFactory, saverMurrData); services.AddSingleton <IAlgorithmServiceProvider>(new AlgorithmServiceProvider(taskActions, serviceActions, logger, calculationFactory)); var schedulerMapper = DownloaderProvider.AutoMapperConfiguration.Configure().CreateMapper(); services.AddSingleton <IServiceActions>(new ServiceActions(dataProvider.KarmaDownloader, schedulerMapper)); services.AddHostedService <Worker>(); }).UseWindowsService()); }
static void Main(string[] args) { CalculationFactory factory = new CalculationFactory(); decimal a = 10; decimal b = 2; decimal result = factory.Divide(a, b); Console.WriteLine("Result of dividing " + a.ToString() + " by " + b.ToString() + " is " + result.ToString()); Console.WriteLine(); Console.WriteLine("***************************************************************"); Console.WriteLine(); //Invalid password string password = "******"; //Valid Password //string password = "******"; Console.WriteLine("Password selected: " + password); Console.WriteLine(); //var validationtext = ValidatePassword.PassWordValid(password); var validationtext = RefactoredValidatePassword.PassWordValid(password); if (!string.IsNullOrEmpty(validationtext)) { Console.WriteLine("Selected password is a NOT a VALID password "); Console.WriteLine(); Console.WriteLine("**********************************************************************************"); Console.WriteLine(validationtext); Console.WriteLine("**********************************************************************************"); } else { Console.WriteLine("Selected password is a valid password"); } Console.ReadLine(); }
public void AllMethodsThrowForInvalidNumberStringInput() { //ARRANGE var tester = new CalculationFactory(); string firstNumberString = "r7"; string secondNumberString = "10"; //ACT & ASSERT Assert.Throws <ArgumentException>( () => tester.AdditionOperation(firstNumberString, secondNumberString) ); Assert.Throws <ArgumentException>( () => tester.MultiplyOperation(firstNumberString, secondNumberString) ); Assert.Throws <ArgumentException>( () => tester.DivisionOperation(firstNumberString, secondNumberString) ); Assert.Throws <ArgumentException>( () => tester.SubtractionOperation(firstNumberString, secondNumberString) ); Assert.Throws <ArgumentException>( () => tester.NegationOperation(firstNumberString) ); }
static void Main(string[] args) { Console.WriteLine("Hello World Calculation Engine!"); Console.WriteLine("-------------------------------"); double initialInvst = 10000; double discountRate = .1; double yearlycashIn = 3000; double noofYears = 5; FinancialReturnInputs finROIInputs = new FinancialReturnInputs(); finROIInputs.IsCashinFlowFixed = true; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.NumberofYears = noofYears; finROIInputs.FixedCashinFlow = yearlycashIn; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed = calcuationNPV.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : NPV={4}", initialInvst, discountRate, yearlycashIn, noofYears, calcuationNPV.Result)); initialInvst = 200000; discountRate = .04; List <double> yearlyCashFlows = new List <double>(); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); finROIInputs.IsCashinFlowFixed = false; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.CashInFlows = yearlyCashFlows; ; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV2 = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed2 = calcuationNPV2.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : IRR={4}", initialInvst, discountRate, yearlycashIn, noofYears, calcuationNPV2.Result)); finROIInputs.IsCashinFlowFixed = true; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.NumberofYears = noofYears; finROIInputs.FixedCashinFlow = yearlycashIn; finROIInputs.MaxDiscountRate = .9; ICalcuation calculationIRR = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.IRR, finROIInputs); bool executedIRR = calculationIRR.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : IRR={4}", initialInvst, discountRate, yearlycashIn, noofYears, calculationIRR.Result)); Console.ReadLine(); }
/// <summary> /// For calculations within a network involving the size of the instance. /// </summary> private void AddSizeParamsForNWCalculations() { if (this.ContainedParameters == null) { return; } // create the size parameters List <Parameter.Parameter> parameters = Parameter.Parameter.GetSizeParametersForInstancing(); this.AddParametersFromList(parameters); // create the corresponding calculations ObservableConcurrentDictionary <string, Parameter.Parameter> p_in; ObservableConcurrentDictionary <string, Parameter.Parameter> p_out; Calculation calc; CalculationState calc_state = CalculationState.VALID; p_in = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "x2", parameters[3] }, { "x3", parameters[4] } }; p_out = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "out01", parameters[7] } }; calc = new Calculation("x2*x3", "Amax-calc", p_in, p_out); this.TestAndSaveCalculationInEditMode(ComponentManagerType.ADMINISTRATOR, calc, ref calc_state); if (calc_state != CalculationState.VALID) { MessageBox.Show(CalculationFactory.CalcStateToStringDE(calc_state), "Fehler bei der automatisierten Gleichungserstellung", MessageBoxButton.OK, MessageBoxImage.Error); } calc_state = CalculationState.VALID; p_in = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "x2", parameters[0] }, { "x3", parameters[1] } }; p_out = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "out01", parameters[6] } }; calc = new Calculation("x2*x3", "Amin-calc", p_in, p_out); this.TestAndSaveCalculationInEditMode(ComponentManagerType.ADMINISTRATOR, calc, ref calc_state); if (calc_state != CalculationState.VALID) { MessageBox.Show(CalculationFactory.CalcStateToStringDE(calc_state), "Fehler bei der automatisierten Gleichungserstellung", MessageBoxButton.OK, MessageBoxImage.Error); } calc_state = CalculationState.VALID; p_in = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "x2", parameters[7] }, { "x3", parameters[5] } }; p_out = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "out01", parameters[9] } }; calc = new Calculation("x2*x3", "Vmax-calc", p_in, p_out); this.TestAndSaveCalculationInEditMode(ComponentManagerType.ADMINISTRATOR, calc, ref calc_state); if (calc_state != CalculationState.VALID) { MessageBox.Show(CalculationFactory.CalcStateToStringDE(calc_state), "Fehler bei der automatisierten Gleichungserstellung", MessageBoxButton.OK, MessageBoxImage.Error); } calc_state = CalculationState.VALID; p_in = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "x2", parameters[6] }, { "x3", parameters[2] } }; p_out = new ObservableConcurrentDictionary <string, Parameter.Parameter> { { "out01", parameters[8] } }; calc = new Calculation("x2*x3", "Vmin-calc", p_in, p_out); this.TestAndSaveCalculationInEditMode(ComponentManagerType.ADMINISTRATOR, calc, ref calc_state); if (calc_state != CalculationState.VALID) { MessageBox.Show(CalculationFactory.CalcStateToStringDE(calc_state), "Fehler bei der automatisierten Gleichungserstellung", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ShuntingYardCalculatorEngine(CalculationFactory calculationFactory, ShuntingYardParser parser) { _parser = parser; _calculationFactory = calculationFactory; }
public ValuesController(ICalculator calculator, CalculationFactory factory) { _caclulator = calculator; _factory = factory; }
public CalculationFactoryTests() { this.sut = new CalculationFactory(); }