public void AddTest()
 {
     calculator = new ComplexNumbers.Calculator();
     Complex<double> actual = calculator.Add(new Complex<double>(4, 5), new Complex<double>(6, 7));
     Complex<double> expected = new Complex<double>(4 + 6, 5 + 7);
     Assert.True(actual.Equals(expected));
 }
 public void MultiplyTest()
 {
     calculator = new ComplexNumbers.Calculator();
     Complex<double> actual = calculator.Multiply(new Complex<double>(4, 5), new Complex<double>(6, 7));
     Complex<double> expected = new Complex<double>(4 * 6 - 5 * 7, 5 * 6 + 4 * 7);
     Assert.True(actual.Equals(expected));
 }
Example #3
0
        static void DoCalculations(ICalculator client)
        {
            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);
            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
        }
Example #4
0
 public Prompt(IConsole console, ICalculator calculator, IValidator validator, ILogger logger)
 {
     _console = console;
     _calculator = calculator;
     _validator = validator;
     _logger = logger;
 }
 public void SubtrachtTest()
 {
     calculator = new ComplexNumbers.Calculator();
     Complex<double> actual = calculator.Subtracht(new Complex<double>(4, 5), new Complex<double>(6, 7));
     Complex<double> expected = new Complex<double>(4 - 6, 5 - 7);
     Assert.True(actual.Equals(expected));
 }
 public CalculatorReplLoop(ICalculator calculator, IInputService inputService, IOutputService outputService, IInputParserService parsingService)
 {
     this.calculator = calculator;
     this.inputService = inputService;
     this.outputService = outputService;
     this.parsingService = parsingService;
 }
 public AdapterPatternDemo(TextWriter output, TextReader input)
 {
     _output = output;
     _input = input;
     _legacy = new Adaptee();
     _adapter = new Adapter();
 }
Example #8
0
        static void CalculateFromFile(ICalculator calc, IUtility utility)
        {
            var read = File.OpenText(@"c:\Calculate_Log.txt");

            string txt;
            var counter = 0;

            while ((txt = read.ReadLine()) != null)
            {
                if (counter == 0)
                    calc.Process = txt;

                if (counter == 1)
                {
                    if (utility.IsNUmeric(txt))
                        calc.FirstNumber = Convert.ToDouble(txt);
                }
                if (counter == 2)
                {
                    if (utility.IsNUmeric(txt))
                        calc.SecondNumber = Convert.ToDouble(txt);
                }
                counter++;
            }

            read.Close();

            calc.Calculate();
        }
 public void DivideTest()
 {
     calculator = new ComplexNumbers.Calculator();
     Complex<double> actual = calculator.Divide(new Complex<double>(4, 5), new Complex<double>(6, 7));
     Complex<double> expected = new Complex<double>((4.0 * 6.0 + 5.0 * 7.0) / (6.0 * 6.0 + 7.0 * 7.0), (5.0 * 6.0 - 4.0 * 7.0) / (6.0 * 6.0 + 7.0 * 7.0));
     Assert.True(actual.Equals(expected));
 }
 public void SetUp()
 {
     calc = new Calculator();
     basicList = new List<long> { 1, 2, 3, 4, 5 };
     evenList = new List<long> { 2, 4, 6, 8, 10 };
     singleItemEvenList = new List<long> { 4 };
     singleItemOddList = new List<long> { 7 };
 }
Example #11
0
        protected override void Given()
        {
            _schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>());

            _calculator = A.Fake<ICalculator>();

            _runtime = new GraspRuntime(_schema, _calculator, Enumerable.Empty<VariableBinding>());
        }
Example #12
0
        public void DoCalculation(ICalculator ic)
        {
            Console.WriteLine(ic.Addition(10, 20));
            Console.WriteLine(ic.Substraction(10, 20));

            //Downcasting
            Console.WriteLine(((Provider)ic).Mod(10, 2));
        }
Example #13
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes the biomass-cohorts module.
        /// </summary>
        /// <param name="successionTimeStep">
        /// The time step for the succession extension.  Unit: years
        /// </param>
        /// <param name="deathMethod">
        /// The method to call when a cohort dies.
        /// </param>
        /// <param name="biomassCalculator">
        /// The calculator for computing the change in a cohort's biomass due
        /// to growth and mortality.
        /// </param>
	    public static void Initialize(int               successionTimeStep,
                                      CohortDeathMethod deathMethod,
                                      ICalculator       biomassCalculator)
	    {
	        Cohorts.successionTimeStep = successionTimeStep;
	        Cohorts.deathMethod        = deathMethod;
	        Cohorts.biomassCalculator  = biomassCalculator;
	    }
Example #14
0
        /// <summary>
        /// Initializes an executable with the specified schema and calculator
        /// </summary>
        /// <param name="schema">The schema which generated this executable</param>
        /// <param name="calculator">The calculator which applies the schema's calculations to runtimes generated by this executable</param>
        public GraspExecutable(GraspSchema schema, ICalculator calculator)
        {
            Contract.Requires(schema != null);
            Contract.Requires(calculator != null);

            Schema = schema;
            Calculator = calculator;
        }
Example #15
0
        public void Initialize()
        {
            Debug.WriteLine(">>>Initialize MainModule");

            _container.RegisterType<ICalculator, Calculator>();
            _calculator = _serviceLocator.GetInstance<ICalculator>();

            _calculator.Run();
        }
Example #16
0
 public HomeController(ICalculator calc, 
     IScoped scoped1,
     IScoped scoped2,
     ITransient transient1,
     ITransient transient2)
 {
     _Calculator = calc;
     _ScopedEqual = scoped1 == scoped2;
     _TransientsEqual = transient1 == transient2;
 }
Example #17
0
        static bool DoCalculate(ICalculateStrategy Strategy, ICalculator Calc)
        {
            if (!Strategy.StartCalculating())
                return false;

            while (Strategy.ReadAndExecuteNextAction())
            {
                Console.WriteLine("\nТекущее значение: {0}\n", Calc.CurrentValue);
            }

            return true;
        }
Example #18
0
 static void Invoke(Action<ICalculator> action, ICalculator proxy, string operation)
 {
     try
     {
         action(proxy);
         Console.WriteLine("服务操作\"{0}\"调用成功...", operation);
     }
     catch (Exception ex)
     {
         Console.WriteLine("服务操作\"{0}\"调用失败...", operation);
     }
 }
        public CalculatingActor(ICalculator calculator)
        {
            if (calculator == null)
            {
                throw new ArgumentNullException("calculator");
            }

            _calculator = calculator;
            Receive<ScanMessage>(message => HandleScanMessage(message));
            Receive<SetPricingMessage>(message => HandlePricingMessage(message));
            Receive<CalculateMessage>(message => HandleCalculateMessage(message));
        }
Example #20
0
 public Executor(ICalculationMonitor monitor)
 {
     this._calculator = null;
     this._lstCalculator = new List<ICalculator>();
     this._tasks = new List<object>();
     this._lstMonitor = new List<ICalculationMonitor>();
     if (monitor != null)
     {
         this._lstMonitor.Add(monitor);
     }
     _bgwMain = new BackgroundWorker();
 }
Example #21
0
 static void Invoke(ICalculator calculator)
 {
     try
     {
         calculator.Add(1, 2);
         Console.WriteLine("服务调用成功...");
     }
     catch
     {
         Console.WriteLine("服务调用失败...");
     }
 }
Example #22
0
 static void Invoke(Action<ICalculator> action, ICalculator calculator)
 {
     try
     {
         action(calculator);
         Console.WriteLine("服务调用成功!");
     }
     catch (Exception ex)
     {
         Console.WriteLine("抛出异常: {0}", ex.Message);
     }
 }
Example #23
0
        /// <summary>
        /// Initializes a runtime with the specified schema, calculator, and bindings
        /// </summary>
        /// <param name="schema">The schema which defines the variables and calculations in effect for this runtime</param>
        /// <param name="calculator">The calculator which applies the specified schema's calculations to this runtime</param>
        /// <param name="bindings">The initial states of the variables in this runtime</param>
        public GraspRuntime(GraspSchema schema, ICalculator calculator, IEnumerable<VariableBinding> bindings)
        {
            Contract.Requires(schema != null);
            Contract.Requires(calculator != null);
            Contract.Requires(bindings != null);

            // TODO: Ensure that all bound variables exist in schema

            Schema = schema;
            Calculator = calculator;

            _bindingsByVariable = bindings.ToDictionary(binding => binding.Variable);
        }
 public SubExpressionUpdate(ICalculator calculator, IFunction callFunction, string val, int propIndex, IVariable relative)
 {
     if (propIndex == -1 && callFunction is IVariableReferencePropertyUsage)
     {
         if (val != relative.Name)
         {
             // Compute dependicy properties before returning the variable
             // in order to receive correct values.
             object var = calculator.ComputeVariable(val, null);
             string[] props = ((IVariableReferencePropertyUsage)callFunction).GetDependices(var.GetType());
             if (props != null)
             {
                 foreach (string prop in props)
                 {
                     Expression exp = calculator.GetExpressionObject(val + "." + prop);
                     if (exp != null)
                         m_expressionList.Add(exp);
                 }
             }
         }
     }
     else if (propIndex > 0)
     {
         // Compute property dependices before this.
         string name = val.Substring(0, propIndex);
         if (name != relative.Name)
         {
             object var = calculator.ComputeVariable(name, null);
             if (var is IOptimizable)
             {
                 IOptimizable opt = (IOptimizable)var;
                 PropertyDependicy[] deps = opt.PropertyDependices;
                 string prop = val.Substring(propIndex + 1);
                 if (deps != null)
                 {
                     Expression[] exps = new Expression[1];
                     foreach (PropertyDependicy dep in deps)
                     {
                         if (dep.ParentProperty == prop)
                         {
                             Expression exp = calculator.GetExpressionObject(name + "." + dep.ChildProperty);
                             if (exp != null)
                                 m_expressionList.Add(exp);
                         }
                     }
                 }
             }
         }
     }
 }
Example #25
0
        protected override void Given()
        {
            _variables = new[] { new Variable("Grasp", "Test", typeof(int)), new Variable("Grasp", "Test2", typeof(int)) };

            _calculations = new[]
            {
                new Calculation(new Variable("Grasp", "TestOutput", typeof(int)), Expression.Constant(0)),
                new Calculation(new Variable("Grasp", "Test2Output", typeof(int)), Expression.Constant(1))
            };

            _schema = new GraspSchema(_variables, _calculations);

            _calculator = A.Fake<ICalculator>();
        }
Example #26
0
        static void CalculateFromConsole(ICalculator calc, IUtility utility)
        {
            var firstNumber = Console.ReadLine();
            if (utility.IsNUmeric(firstNumber))
                calc.FirstNumber = Convert.ToDouble(firstNumber);

            calc.Process = Console.ReadLine();

            var secondNumber = Console.ReadLine();

            if (utility.IsNUmeric(secondNumber))
                calc.SecondNumber = Convert.ToDouble(secondNumber);

            calc.Calculate();
        }
Example #27
0
        private static void RunCalculator(ICalculator calc)
        {

            if (calc == null)
            {
                //No calculators were found; read a line and exit.
                Console.ReadLine();
            }
            Console.WriteLine("Available operations: +, -, *, /");
            Console.WriteLine("Request a calculation , such as: 2 + 2");
            Console.WriteLine("Type \"exit\" to exit");
            String line = Console.ReadLine();
            while (!line.Equals("exit"))
            {
                // The Parser class parses the user's input. 
                try
                {
                    Parser c = new Parser(line);
                    switch (c.Action)
                    {
                        case "+":
                            Console.WriteLine(calc.Add(c.A, c.B));
                            break;
                        case "-":
                            Console.WriteLine(calc.Subtract(c.A, c.B));
                            break;
                        case "*":
                            Console.WriteLine(calc.Multiply(c.A, c.B));
                            break;
                        case "/":
                            Console.WriteLine(calc.Divide(c.A, c.B));
                            break;
                        default:
                            Console.WriteLine("{0} is an invalid command. Valid commands are +,-,*,/", c.Action);
                            break;
                    }
                }
                catch
                {
                    Console.WriteLine("Invalid command: {0}. Commands must be formated: [number] [operation] [number]", line);
                }

                line = Console.ReadLine();
            }
        }
Example #28
0
        static void DoCalculations(ICalculator proxy)
        {
            MyChannelExtension extension = ((IContextChannel)proxy).Extensions.Find<MyChannelExtension>();
            if (extension != null)
            {
                if (extension.Binding != null)
                {
                    Console.WriteLine("Sending requests over {0}", extension.Binding.Scheme);
                }

                if (extension.IntroduceErrors)
                {
                    Console.WriteLine("Errors will be introduced in the request");
                }
            }

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = proxy.Add(value1, value2);
            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = proxy.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = proxy.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = proxy.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            Console.WriteLine();
        }
Example #29
0
        private MandelType c_type; // Mandel vagy Julia mod

        #endregion Fields

        #region Constructors

        public Mandel()
        {
            c_cent = 0;
              c_radius = 2;
              c_saveCent = 0;
              c_saveRadius = 2;
              c_type = MandelType.MANDEL_TYPE_MANDEL;
              c_julia = 0;
              c_timeused = 0;
              c_LayerData = new List<ProcessLayer>();
              c_fractaltype = FractalType.FRACTAL_TYPE_MANDEL;
              c_param = 0;
              c_lineprocess = true;
              c_processnum = 1;
              c_function = "";
              c_haschanged = true;
              c_calc = null;
              c_LayerDataHash = 0;
              c_factory = null;
        }
        private static void ParseLine(string line, ICalculator calculatorModule)
        {
            var strings = line.Split(' ');

            if(strings.Length == 0) { return;}

            switch (strings[0])
            {
                case "1":
                    Console.WriteLine("1 + 2 = {0}",calculatorModule.Add(1, 2));
                    break;
                case "2":
                    Console.WriteLine("1 + 2 = {0}", calculatorModule.Subtract(2, 1));
                    break;
                case "3":
                    Console.WriteLine("1 + 2 = {0}", calculatorModule.Multiply(2, 3));
                    break;
                case "4":
                    Console.WriteLine("1 + 2 = {0}", calculatorModule.Divide(4, 2));
                    break;

            }
        }
 public TemplateController(ITemplateManager templateManager, ICalculator calculator, ILogger logger)
 {
     _calculator      = calculator;
     _templateManager = templateManager;
     _logger          = logger;
 }
Example #32
0
 public Buyer(ICalculator calculator)
 {
     _calculator = calculator;
 }
Example #33
0
 public ApplicationSettingViewModel(ApplicationSetting setting, ICalculator <string, object> hashCalculator)
 {
     _hashCalculator = hashCalculator;
     _setting        = setting;
     _initialHash    = _hashCalculator.Calculate(this);
 }
 public CalculatorController(ICalculator calculator)
 {
     _calculator = calculator;
 }
Example #35
0
 public IndexModel(ILogger <IndexModel> logger, ICalculator calculator)
 {
     _logger     = logger;
     _calculator = calculator;
 }
Example #36
0
 public Presenter(IView view, ICalculator calculator, IUsageLogger usageLogger)
 {
     _view        = view;
     _calculator  = calculator;
     _usageLogger = usageLogger;
 }
Example #37
0
 public UsersController(ICalculator calculator, IEmailService emailService)
 {
     this.Calculator   = calculator;
     this.EmailService = emailService;
 }
Example #38
0
        public void CreateModTest()
        {
            ICalculator calc = Factory.CreateCalculator("button10");

            Assert.IsInstanceOf(typeof(Mod), calc);
        }
Example #39
0
 public ProfilingCalculator(ICalculator calculator, Stopwatch stopwatch)
 {
     _calculator = calculator;
     _stopwatch  = stopwatch;
 }
Example #40
0
 public LendersManager(IFileReader fileReader, ICalculator calculator, string fileName)
 {
     _fileReader = fileReader;
     _lenders    = Load(fileName);
     _calculator = calculator;
 }
Example #41
0
        public void CreateDelenTest()
        {
            ICalculator calc = Factory.CreateCalculator("button4");

            Assert.IsInstanceOf(typeof(Delen), calc);
        }
Example #42
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.AddIn.Pipeline.ContractBase" /> class.
 /// </summary>
 public CalculatorViewToContractAddInSideAdapter(ICalculator view)
 {
     _view = view;
 }
Example #43
0
 public PayslipGenerator(ICalculator calculator)
 {
     Calculator = calculator;
 }
Example #44
0
 public EmployeeController(ICalculator calculator)
 {
     _calculator = calculator;
 }
Example #45
0
 public ApplicationLogic(ICalculator <double> calc)
 {
     this._calc = calc;
 }
Example #46
0
 public CalculateController(ICalculator calculator)
 {
     this.calculator = calculator;
 }
Example #47
0
        public void SimpleTest(string name, Type type)
        {
            ICalculator calculator = Factory.CreateCalculator(name);

            Assert.IsInstanceOf(type, calculator);
        }
Example #48
0
 public void SetUp()
 {
     _sut = new Calculator();
 }
Example #49
0
 public TimerDecorator(ICalculator calculator) : base(calculator)
 {
     _watch = new Stopwatch();
 }
Example #50
0
 public void Initialize_Test()
 {
     //Create a new instance of the calculator class for each test.
     _Calculator = new Calculator();
 }
Example #51
0
 public Order(int id, ICalculator calculator)
 {
     Id         = id;
     Calculator = calculator;
 }
Example #52
0
 protected CalculatorViewModelBase(ICalculator calculator)
 {
     this.calculator = calculator;
 }
 public PostHandler(ICalculator calculator)
 {
     _calculator = calculator;
 }
 public CalcServiceController(ICalculator calculator)
 {
     _calculator = calculator;
 }
Example #55
0
        public void CreateUmnogTest()
        {
            ICalculator calc = Factory.CreateCalculator("button2");

            Assert.IsInstanceOf(typeof(Umnog), calc);
        }
Example #56
0
 public GoogleCalculatorValidationSteps(ICalculator calculator)
 {
     this.calculator = calculator;
 }
Example #57
0
        public void CreateRaznostTest()
        {
            ICalculator calc = Factory.CreateCalculator("button3");

            Assert.IsInstanceOf(typeof(Raznost), calc);
        }
Example #58
0
 public void Setup()
 {
     _calc = new Calculator();
 }
Example #59
0
 public Problem2PageModel(ILogger <Problem2PageModel> logger, ICalculator calculator)
     : base(logger)
 {
     _calculator = calculator;
 }
Example #60
0
 public void Setup()
 {
     squareCalulator = (ICalculator) new Calculator();
 }