static void Main(string[] args) { float x = 42f; Function f; CalculatorFactory fact = new CalculatorFactory( ); while (true) { Console.Write("> "); string s = Console.ReadLine( ); try { f = fact.Get(s); Console.WriteLine(f(x)); } catch (CompileException e) { Console.WriteLine("Errors:"); foreach (CompilerError err in e.Errors) { Console.WriteLine(err.ErrorText); } } } }
public void test_SP_Straight_Calculation() { Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >(); setupTestTeams(pitcherDataByTeam); Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam); SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam); IUsageCalculator calculator = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_BASIC, teamReportFile, buildTeam("TEST1", IN_DIVISION)); List <Dictionary <int, int> > results = calculator.calculate(); verifyBasicLineupStructure(results); // Test L-1R runLineupTest(results, createTestTeamLineup("L", "1R", "1R"), 11); // Test L 9L->9R runLineupTest(results, createTestTeamLineup("L", "9L", "9R"), 152); // Test R 9R->9R runLineupTest(results, createTestTeamLineup("R", "9L", "9R"), 473); // Test R E runLineupTest(results, createTestTeamLineup("R", "E", "E"), 61); // Test R 6R-9R runLineupTest(results, createTestTeamLineup("R", "6R", "9R"), 24); // Test L 6R-8R runLineupTest(results, createTestTeamLineup("L", "6R", "8R"), 0); }
public void Generate(IGeneratorSettings generatorSettings) { if (String.IsNullOrWhiteSpace(this.txtPassword.Text)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IEntropyCalculator entropyCalculator = CalculatorFactory.Create <IEntropyCalculator>(); IStrengthCalculator strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>(); ISecurityCalculator securityCalculator = CalculatorFactory.Create <ISecurityCalculator>(); String password = this.txtPassword.Text; Double entropy = entropyCalculator.Calculate(password); Strength strength = strengthCalculator.Calculate(entropy); Scenario scenario = this.cmbScenario.SelectedValue as Scenario; // Don't change this order. this.cntEntropy.Strength = strength; this.cntEntropy.Entropy = entropy; this.cntEntropy.Percent = strengthCalculator.ToPercent(entropy); this.cntEntropy.Summary = strengthCalculator.ToSummary(strength); if (entropy > 0d) { Duration duration = securityCalculator.Calculate(scenario, entropy); this.cntDuration.SetDuration(duration); } }
public Cashier GetCashier(String strategy) { CalculatorFactory factory = new CalculatorFactory(); ITaxCalculator taxCal = factory.GetTaxCalculator(strategy); return(new Cashier(taxCal)); }
private void columnsToolStripMenuItem_Click(object sender, EventArgs e) { SaveDo(() => { var shownRawColumns = _settings.ActiveColumnSet.Columns; Dialogs.ChooseColumnsDialog ccd = new Dialogs.ChooseColumnsDialog( CalculatorFactory.GetAllCalulators().Except(shownRawColumns).Select(calc => CalculatorToTaggedObject(calc)), shownRawColumns.Select(calc => CalculatorToTaggedObject(calc)), _settings.ActiveColumnSet.Name); ccd.Translate(_translator); if (ccd.ShowDialog() == DialogResult.OK) { IList <IPlayerStatisticCalculator <IEnumerable <MatchAppearance> > > myList = GetCalculatorsListFromDialog(ccd); _settings.ActiveColumnSet.Name = ccd.MyName; _settings.ActiveColumnSet.Columns = myList; _settings.ColumnSets = _settings.ColumnSets; // TODO: force save another way _settings.ActiveColumnSet = _settings.ActiveColumnSet; // TODO: force save another way RefreshColumnSetComboBox(); SetColumns(_settings.ActiveColumnSet); } }); }
private void CB_LIST_OF_TEAMS_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (dialogInitialized) { if (CB_LIST_OF_TEAMS.SelectedItem is Team) { currentlySelectedTeam = (Team)CB_LIST_OF_TEAMS.SelectedItem; TeamLineup selectedTeamLineup = LineupPersistence.lookupTeamLineup(engine.StoredLineups, currentlySelectedTeam); System.Console.WriteLine(currentlySelectedTeam.Abrv + " contains " + selectedTeamLineup.Lineups.Count + " lineups."); List <Player> players = engine.TeamReportFile.getTeamBatters(currentlySelectedTeam); batterInfo.setPlayers(players); IUsageCalculator calculator = CalculatorFactory.getCalculator(USAGE_CALCULATOR, engine.TeamReportFile, currentlySelectedTeam); calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, engine.TeamLineupData.InDivisionGameCount); calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, engine.TeamLineupData.OutofDivisionGameCount); //TODO: Add UI element for Target At Bats calculator.setOptions(CalculatorOptions.OPTION_TARGET_AT_BAT, 615); engine.BalanceAtBats = balanceUsage.buildTable(calculator); updateWorkbook(currentlySelectedTeam, players); fillBoxesWithSavedDataData(); BTN_MANAGE_LINEUPS.IsEnabled = true; } } }
/// <summary> /// Static method which creates an instance of the class if not created /// </summary> /// <returns>CalculatorFactory</returns> public static CalculatorFactory GetInstance() { if (calculatorFactory == null){ calculatorFactory = new CalculatorFactory(); } return calculatorFactory; }
static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkRed; Console.WriteLine("Welcome to the calculating app"); Console.BackgroundColor = ConsoleColor.Black; NumberProvider numberProvider = new NumberProvider(); Tuple <int, int> numbers = numberProvider.GetNumbers(); Console.WriteLine("Thanks. These will be fun to do maths on."); Console.WriteLine("Initializing calculator..."); CalculationTypeProvider calculationTypeProvider = new CalculationTypeProvider(); CalculationType calculationType = calculationTypeProvider.GetCalculationType(); ICalculator calculator = CalculatorFactory.Get(calculationType); if (calculator != null) { Console.Beep(); decimal result = calculator.Calculate(numbers.Item1, numbers.Item2); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Yay... The result is {result}. Bye bye."); Console.ReadKey(); } }
public void VerifyConfigThrowException() { var ccf = CalculatorFactory.Build <TKey>(); if (ccf.Gt(PerLoadSize, TotalLoadSize)) { throw new ArgumentException("expect: PerLoadSize < TotalLoadSize"); } if (ccf.Gt(TotalLoadSize, TotalCacheSize)) { throw new ArgumentException("expect: TotalLoadSize < TotalCacheSize"); } if (ccf.Gt(TotalCacheSize, ccf.Subtract(EndPoint, StartPoint))) { throw new ArgumentException("expect: TotalCacheSize < (EndPoint - StartPoint)"); } if (ForwardAndBackwardScale < 0) { throw new ArgumentException("expect: ForwardAndBackwardScale > 0"); } if (LoadTriggerFrequency < 0 || LoadTriggerFrequency > 1) { throw new ArgumentException("expect: 0<= LoadTriggerFrequency <= 1"); } if (RemoveTriggerFrequency < 0 || RemoveTriggerFrequency > 1) { throw new ArgumentException("expect: 0<= RemoveTriggerFrequency <= 1"); } }
public EmployessService( CalculatorFactory factory, IDataManager data) { _factory = factory; _data = data; }
public void test_Balance_Calculation_Multiple_Divisions() { Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >(); setupTestTeams(pitcherDataByTeam); Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam); SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam); IUsageCalculator calculator = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_SCHEDULE, teamReportFile, buildTeam("TEST1", IN_DIVISION)); calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, 26); calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, 14); List <Dictionary <int, int> > results = calculator.calculate(); verifyBasicLineupStructure(results); // Test L-1R runLineupTest(results, createTestTeamLineup("L", "1R", "1R"), 11); // Test L 9L->9R runLineupTest(results, createTestTeamLineup("L", "9L", "9R"), 158); // Test R 9R->9R runLineupTest(results, createTestTeamLineup("R", "9L", "9R"), 483); // Test R E runLineupTest(results, createTestTeamLineup("R", "E", "E"), 62); // Test R 6R-9R runLineupTest(results, createTestTeamLineup("R", "6R", "9R"), 25); }
public void GetFactory_Calculate(double a, double b, CalculatorFactory.Shape shape, double expectedArea) { var calculator = CalculatorFactory.Get(shape); var actualArea = calculator(a, b); Assert.AreEqual(expectedArea, actualArea); }
public void Adding2To3Yields5_Shortened() { // Arrange var calculator = CalculatorFactory.CreateCalculator(); // Act/Assert calculator.Add(2, 3).Should().Be(5); }
public void Test_Factory() { Calculator operation = CalculatorFactory.CreatOperation("+"); var operType = (OperationType)Enum.Parse(typeof(OperationType), operation.Operation, true); var result = CalculatorFactory.CalculateAnswer(operType, 1, 2); Assert.AreEqual(result, 3); }
public C(A pA, B pB, CalculatorFactory pCalcFactory) { _pA = pA; _pB = pB; _pCalcFactory = pCalcFactory; var calculator = _pCalcFactory.Create(); }
public UnityOfWork(string operation) { logger = new Logger(); CalculatorFactory calculatorFactory = new CalculatorFactory(); calculateLogic = calculatorFactory.GetOperationType(operation); validate = new Validate(); }
public PlaygroundConfiguration(CompanyInfo company, List <QuotesModel> quotes, List <Indicator> indicators, CalculatorFactory calculatorFactory, int strategyId, List <IStrategyRuleView> rules) { Company = company; Quotes = quotes; Indicators = indicators; CalculatorFactory = calculatorFactory; StrategyId = strategyId; Rules = rules; }
public void CircleCalculator_GetArea_Exception_Test() { var radius = double.MaxValue; var circle = new Circle(Point2D.ZeroPoint, radius); var calculator = CalculatorFactory.ProduceCircleCalculator(); Assert.ThrowsException <CalculateAreaException>(() => calculator.GetArea(circle)); }
private void Operations(object sender, EventArgs e) { double first = Convert.ToDouble(textBox1.Text); double second = Convert.ToDouble(textBox2.Text); ICalculate Calc = CalculatorFactory.CreateCalcuator(((Button)sender).Name); double result = Calc.Calculate(first, second); textBox3.Text = result.ToString(); }
public void TestCalculatorMonth() { CalculatorFactory factory = new CalculatorFactory(); var calculator = factory.Build("MONTHLYSALARYEMPLOYEE"); var result = calculator.Calculate(new Employe { MonthlySalary = 30 }); Assert.AreEqual(360, result); }
public void Adding2To3Yields5() { // Arrange var calculator = CalculatorFactory.CreateCalculator(); // Act var sum = calculator.Add(2, 3); // Assert sum.Should().Be(5); }
public void TestCalculatorHour() { CalculatorFactory factory = new CalculatorFactory(); var calculator = factory.Build("HOURLYSALARYEMPLOYEE"); var result = calculator.Calculate(new Employe { HourlySalary = 30 }); Assert.AreEqual(43200, result); }
public GlobalIndicatorsProcessJob(ICompanyService companyService, IIndicatorService indicatorService, IGlobalIndicatorService globalIndicatorService, CalculatorFactory processorFactory) { _companyService = companyService; _indicatorService = indicatorService; _globalIndicatorService = globalIndicatorService; _processorFactory = processorFactory; }
public CostDetails CalculateCost(ParkTypeEnum parkType, double duration) { var costCalculator = CalculatorFactory.Get <ICostCalc>(parkType.ToString()); if (costCalculator == null) { return(null); } return(costCalculator.CalculateCost(duration)); }
public void CircleCalculator_GetArea_Test() { var radius = 10.5d; var circle = new Circle(Point2D.ZeroPoint, radius); var calculator = CalculatorFactory.ProduceCircleCalculator(); var circleArea = calculator.GetArea(circle); var s = Math.PI * radius * radius; Assert.AreEqual(s, circleArea, TestSettings.Delta); }
public void TriangleCalculator_Exception_Test() { var point1 = Point2D.ZeroPoint; var point2 = new Point2D(double.MaxValue, double.MaxValue); var point3 = new Point2D(double.MinValue, double.MaxValue); var triangle = new Triangle(point1, point2, point3); var calculator = CalculatorFactory.ProduceTriangleCalculator(); Assert.ThrowsException <CalculateAreaException>(() => calculator.IsRightTriangle(triangle)); }
private static void Run(bool useProxy) { ICalculate theCalculator = CalculatorFactory.Create(useProxy); for (int i = 0; i < 1000; i++) { int x = _generator.Next(0, Coordinate.XMax) + 1; int y = _generator.Next(0, Coordinate.YMax) + 1; Coordinate c = new Coordinate(x, y); Console.WriteLine($"Result of calculation #{i:000}, using ({x},{y}) : {theCalculator.Calculate(c)} {CacheReport(useProxy)}"); } }
public void TriangleCalculator_IsNotRight_Test() { var point1 = Point2D.ZeroPoint; var point2 = new Point2D(100, 100); var point3 = new Point2D(-100, -100); var triangle = new Triangle(point1, point2, point3); var calculator = CalculatorFactory.ProduceTriangleCalculator(); var isRight = calculator.IsRightTriangle(triangle); Assert.IsFalse(isRight); }
private Columns String2Columns(string columnString) { foreach (string column in columnString.Split(';')) { foreach (var v in CalculatorFactory.GetAllCalulators()) { if (column == v.Identifier) { yield return(v); } } } }
public GlobalIndicatorsProcessor( GlobalIndicatorsProcessorConfig config, IScheduledJobsService jobsService, ICompanyService companyService, IIndicatorService indicatorService, CalculatorFactory calculatorFactory, IGlobalIndicatorService globalIndicatorService, IProcessorLogger logger) : base(logger, jobsService, companyService, config) { _indicatorService = indicatorService; _calculatorFactory = calculatorFactory; _globalIndicatorService = globalIndicatorService; }
/// <summary> /// Acceptance of values and output of the result /// </summary> /// <param name="sender">Sending the name of the pressed button</param> /// <param name="e">Provides value for events that do not contain data</param> private void Calculete(object sender, EventArgs e) { try { double firstValue = Convert.ToDouble(textBox1.Text); double secondValue = Convert.ToDouble(textBox2.Text); ICalculator calculator = CalculatorFactory.CreateCalculator(((Button)sender).Name); var result = calculator.Calculate(firstValue, secondValue); textBox3.Text = result.ToString(); } catch (Exception exp) { textBox3.Text = exp.Message; } }
public CalculatorTest() { calculatorFactory = new CalculatorFactory(); }
public void Configurer_Test() { var configurer = new TestConfigurer(); ICalculator calculator = new CalculatorFactory(configurer).createInstance(); double result = calculator.Compute("~3.3"); Assert.AreEqual(3d, result); result = calculator.Compute("~3.3+2.8"); Assert.AreEqual(5.8d, result); result = calculator.Compute("3.3+2.8~"); Assert.AreEqual(4.1d, result); result = calculator.Compute("3.3+2.8~*2"); Assert.AreEqual(4.9d, result, 0.00001); }
public void WhenICalculateTheScore() { _result = new CalculatorFactory().GetCalculators().Single(f => f.Category == _type).GetScore(_roll); }