本文整理汇总了C#中Calculator.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Calculator.Add方法的具体用法?C# Calculator.Add怎么用?C# Calculator.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add_OneNumber_ReturnNumber
public void Add_OneNumber_ReturnNumber()
{
var numberString = "1";
var calculator = new Calculator();
int result = calculator.Add(numberString);
Assert.AreEqual(1, result);
}
示例2: AddNegative4andnegative10
public void AddNegative4andnegative10()
{
Calculator calc = new Calculator(); //ARRANGE
int result = calc.Add(-4, -10); //ACT
Assert.AreEqual(-14, result); //assert
}
示例3: Add_NumbersAndHandleValidNewLine_ReturnSum
public void Add_NumbersAndHandleValidNewLine_ReturnSum()
{
var numberString = "1\n2";
var calculator = new Calculator();
int result = calculator.Add(numberString);
Assert.AreEqual(3, result);
}
示例4: Add5and8
public void Add5and8()
{
Calculator calc = new Calculator();
int result = calc.Add(5, 3);
Assert.AreEqual(8, result);
}
示例5: Add4and10
public void Add4and10()
{
Calculator calc = new Calculator();
int result = calc.Add(4, 10);
Assert.AreEqual(14, result);
}
示例6: OnePlusOneIsTwo
public void OnePlusOneIsTwo()
{
var calc = new Calculator();
var two = calc.Add(1, 1);
Assert.AreEqual(2, two);
}
示例7: CalculateButton_Click
protected void CalculateButton_Click(object sender, EventArgs e)
{
if (ValueBox1.Text.Length > 0 && ValueBox2.Text.Length > 0)
{
double result = 0;
double value1 = Convert.ToDouble(ValueBox1.Text);
double value2 = Convert.ToDouble(ValueBox2.Text);
Calculator myCalculator = new Calculator();
Trace.Write(string.Format("Performing the calculation with the {0} operator", OperatorList.SelectedValue));
switch (OperatorList.SelectedValue)
{
case "+":
result = myCalculator.Add(value1, value2);
break;
case "-":
result = myCalculator.Subtract(value1, value2);
break;
case "*":
result = myCalculator.Multiply(value1, value2);
break;
case "/":
result = myCalculator.Divide(value1, value2);
break;
}
ResultLabel.Text = result.ToString();
}
else
{
ResultLabel.Text = string.Empty;
Trace.Warn("Custom Category", "TextBox controls are empty; time to add Validation controls?");
}
}
示例8: Calculate
private static void Calculate(string s)
{
var calculator = new Calculator(UI);
calculator.Add(s);
CalculateNextValue(calculator);
}
示例9: AddNegative4and10
public void AddNegative4and10()
{
Calculator calc = new Calculator();
int result = calc.Add(-4, 10);
Assert.AreEqual(6, result);
}
示例10: Calculate
public string Calculate(double number, char operator)
{
Calculator calculator = new Calculator();
if(!storedNum)
{
storedNum = number;
}
if(storedOperator!='')
{
switch(storedOperator)
{
case '+':
storedNum = calculator.Add(storedNum, number);
break;
default:
//Suitable error for case not found
break;
}
storedOperator
}
else
{
storedOperator = operator;
}
}
示例11: Add_NumbersAndHandleInvalidNewLine_ThrowsInvalidException
public void Add_NumbersAndHandleInvalidNewLine_ThrowsInvalidException()
{
var numberString = "1,\n";
var calculator = new Calculator();
calculator.Add(numberString);
Assert.Fail();
}
示例12: CalculateButton_Click
protected void CalculateButton_Click(object sender, EventArgs e)
{
if (ValueBox1.Text.Length > 0 && ValueBox2.Text.Length > 0)
{
double result = 0;
double value1 = Convert.ToDouble(ValueBox1.Text);
double value2 = Convert.ToDouble(ValueBox2.Text);
Calculator myCalculator = new Calculator();
switch (OperatorList.SelectedValue)
{
case "+":
result = myCalculator.Add(value1, value2);
break;
case "-":
result = myCalculator.Subtract(value1, value2);
break;
case "*":
result = myCalculator.Multiply(value1, value2);
break;
case "/":
result = myCalculator.Divide(value1, value2);
break;
}
ResultLabel.Text = result.ToString();
}
else
{
ResultLabel.Text = string.Empty;
}
}
示例13: Add_ChangeDelimeterandAddNumbers_ReturnSum
public void Add_ChangeDelimeterandAddNumbers_ReturnSum()
{
var numberString = "//;\n1;2";
var calculator = new Calculator();
int result = calculator.Add(numberString);
Assert.AreEqual(3, result);
}
示例14: Add_EmptyString_ReturnZero
public void Add_EmptyString_ReturnZero()
{
var numberString = "";
var calculator = new Calculator();
int result = calculator.Add(numberString);
Assert.AreEqual(0, result);
}
示例15: Calculator_should_add_1_and_2
public void Calculator_should_add_1_and_2()
{
var sut = new Calculator();
var result = sut.Add(1, 2);
result.Should().Be(3);
}