本文整理汇总了C#中ComplexNumber类的典型用法代码示例。如果您正苦于以下问题:C# ComplexNumber类的具体用法?C# ComplexNumber怎么用?C# ComplexNumber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ComplexNumber类属于命名空间,在下文中一共展示了ComplexNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simple
public void Simple()
{
var complexNumber1 = new ComplexNumber(1, 2);
var complexNumber2 = new ComplexNumber(3, 4);
var multiplyComplexNumber = complexNumber1.Multiply(complexNumber2);
Assert.AreEqual(1 * 3 - 2 * 4, multiplyComplexNumber.Real);
Assert.AreEqual(2 * 3 + 1 * 4, multiplyComplexNumber.Imaginary);
multiplyComplexNumber = complexNumber1.Multiply(5);
Assert.AreEqual(5 * 1, multiplyComplexNumber.Real);
Assert.AreEqual(5 * 2, multiplyComplexNumber.Imaginary);
multiplyComplexNumber = 6 * complexNumber1;
Assert.AreEqual(6 * 1, multiplyComplexNumber.Real);
Assert.AreEqual(6 * 2, multiplyComplexNumber.Imaginary);
multiplyComplexNumber = complexNumber1 * 7;
Assert.AreEqual(7 * 1, multiplyComplexNumber.Real);
Assert.AreEqual(7 * 2, multiplyComplexNumber.Imaginary);
complexNumber1 *= 1;
Assert.AreEqual(1, complexNumber1.Real);
Assert.AreEqual(2, complexNumber1.Imaginary);
complexNumber1 *= 5;
Assert.AreEqual(5, complexNumber1.Real);
Assert.AreEqual(10, complexNumber1.Imaginary);
complexNumber1 *= complexNumber2;
Assert.AreEqual(5 * 3 - 10 * 4, complexNumber1.Real);
Assert.AreEqual(10 * 3 + 5 * 4, complexNumber1.Imaginary);
}
示例2: Simple2
public void Simple2()
{
var complexNumber1 = new ComplexNumber(4, 3);
var complexNumber2 = new ComplexNumber(6, 2);
var complexNumber3 = new ComplexNumber(-2, -4);
var complexNumber4 = new ComplexNumber(3, -8);
var complexNumber5 = new ComplexNumber(8, 3);
var resultComplexNumber = complexNumber1 + complexNumber2;
Assert.AreEqual(10, resultComplexNumber.Real);
Assert.AreEqual(5, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber1 + complexNumber3;
Assert.AreEqual(2, resultComplexNumber.Real);
Assert.AreEqual(-1, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber1 + complexNumber4;
Assert.AreEqual(7, resultComplexNumber.Real);
Assert.AreEqual(-5, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber1 + complexNumber5;
Assert.AreEqual(12, resultComplexNumber.Real);
Assert.AreEqual(6, resultComplexNumber.Imaginary);
}
示例3: ExecuteWithParamsTest
public void ExecuteWithParamsTest()
{
var complex = new Complex(5, 2);
var exp = new ComplexNumber(complex);
Assert.Equal(complex, exp.Execute(null));
}
示例4: Simple1
public void Simple1()
{
var complexNumber1 = new ComplexNumber(4, 3);
var complexNumber2 = new ComplexNumber(6, 2);
var complexNumber3 = new ComplexNumber(-2, -4);
var complexNumber4 = new ComplexNumber(3, -8);
var complexNumber5 = new ComplexNumber(8, 3);
var resultComplexNumber = complexNumber1.Subtract(complexNumber2);
Assert.AreEqual(1, resultComplexNumber.Imaginary);
Assert.AreEqual(-2, resultComplexNumber.Real);
resultComplexNumber = complexNumber1.Subtract(complexNumber3);
Assert.AreEqual(7, resultComplexNumber.Imaginary);
Assert.AreEqual(6, resultComplexNumber.Real);
resultComplexNumber = complexNumber1.Subtract(complexNumber4);
Assert.AreEqual(11, resultComplexNumber.Imaginary);
Assert.AreEqual(1, resultComplexNumber.Real);
resultComplexNumber = complexNumber1.Subtract(complexNumber5);
Assert.AreEqual(0, resultComplexNumber.Imaginary);
Assert.AreEqual(-4, resultComplexNumber.Real);
}
示例5: EqualsTest
public void EqualsTest()
{
var exp1 = new ComplexNumber(new Complex(5, 2));
var exp2 = new ComplexNumber(new Complex(5, 2));
Assert.True(exp1.Equals(exp2));
}
示例6: ExecuteTest
public void ExecuteTest()
{
var complex = new Complex(5, 2);
var exp = new ComplexNumber(complex);
Assert.Equal(complex, exp.Execute());
}
示例7: Simple
public void Simple()
{
var complexNumber = new ComplexNumber(5, 6);
var copy = (ComplexNumber) complexNumber.Clone();
Assert.AreEqual(copy.Real, complexNumber.Real);
Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);
complexNumber = new ComplexNumber(-2, 3);
copy = (ComplexNumber) complexNumber.Clone();
Assert.AreEqual(copy.Real, complexNumber.Real);
Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);
complexNumber = new ComplexNumber(5, -3);
copy = (ComplexNumber) complexNumber.Clone();
Assert.AreEqual(copy.Real, complexNumber.Real);
Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);
complexNumber = new ComplexNumber(-9, -4);
copy = (ComplexNumber) complexNumber.Clone();
Assert.AreEqual(copy.Real, complexNumber.Real);
Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);
}
示例8: Simple
public void Simple()
{
var complexNumber1 = new ComplexNumber(4, 5);
var complexNumber2 = new ComplexNumber(-2, 4);
var complexNumber3 = new ComplexNumber(1, -3);
var complexNumber4 = new ComplexNumber(-6, -12);
var resultComplexNumber = complexNumber1.Reciprocal;
Assert.AreEqual(4d / 41d, resultComplexNumber.Real);
Assert.AreEqual(-5d / 41d, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber2.Reciprocal;
Assert.AreEqual(-2d / 20d, resultComplexNumber.Real);
Assert.AreEqual(-4d / 20d, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber3.Reciprocal;
Assert.AreEqual(1d / 10d, resultComplexNumber.Real);
Assert.AreEqual(3d / 10d, resultComplexNumber.Imaginary);
resultComplexNumber = complexNumber4.Reciprocal;
Assert.AreEqual(-6d / 180d, resultComplexNumber.Real);
Assert.AreEqual(12d / 180d, resultComplexNumber.Imaginary);
}
示例9: CanAdd
public ComplexNumber CanAdd(ComplexNumber x, ComplexNumber y)
{
ComplexNumber result = x + y;
Assert.AreEqual(x.Real + y.Real, result.Real);
Assert.AreEqual(x.Imaginary + y.Imaginary, result.Imaginary);
return result;
}
示例10: Main
public static void Main( string[] args )
{
// declare two variables to store complex numbers
// to be entered by user
ComplexNumber x, y;
// prompt the user to enter the first complex number
Console.Write( "Enter the real part of complex number x: " );
double realPart = Convert.ToDouble( Console.ReadLine() );
Console.Write(
"Enter the imaginary part of complex number x: " );
double imaginaryPart = Convert.ToDouble( Console.ReadLine() );
x = new ComplexNumber( realPart, imaginaryPart );
// prompt the user to enter the second complex number
Console.Write( "\nEnter the real part of complex number y: " );
realPart = Convert.ToDouble( Console.ReadLine() );
Console.Write(
"Enter the imaginary part of complex number y: " );
imaginaryPart = Convert.ToDouble( Console.ReadLine() );
y = new ComplexNumber( realPart, imaginaryPart );
// display the results of calculations with x and y
Console.WriteLine();
Console.WriteLine( "{0} + {1} = {2}", x, y, x + y );
Console.WriteLine( "{0} - {1} = {2}", x, y, x - y );
Console.WriteLine( "{0} * {1} = {2}", x, y, x * y );
}
示例11: SumNumbers
public void SumNumbers()
{
ComplexNumber n1 = new ComplexNumber(1,1);
ComplexNumber n2 = new ComplexNumber(1,1);
ComplexNumber result = n1 + n2;
Assert.AreEqual(2, result.Real);
Assert.AreEqual(2, result.Imaginary);
}
示例12: MulNumbers
public void MulNumbers()
{
ComplexNumber n1 = new ComplexNumber(3, 5);
ComplexNumber n2 = new ComplexNumber(2, 3);
ComplexNumber result = n1 * n2;
Assert.AreEqual(6, result.Real);
Assert.AreEqual(15, result.Imaginary);
}
示例13: DivNumbers
public void DivNumbers()
{
ComplexNumber n1 = new ComplexNumber(3, 15);
ComplexNumber n2 = new ComplexNumber(2, 3);
ComplexNumber result = n1 / n2;
Assert.AreEqual(1.5, result.Real);
Assert.AreEqual(5, result.Imaginary);
}
示例14: DiffNumbers
public void DiffNumbers()
{
ComplexNumber n1 = new ComplexNumber(1, 1);
ComplexNumber n2 = new ComplexNumber(1, 1);
ComplexNumber result = n1 - n2;
Assert.AreEqual(0, result.Real);
Assert.AreEqual(0, result.Imaginary);
}
示例15: CalculateMandelbrotIterations
private static int CalculateMandelbrotIterations(ComplexNumber current, ComplexNumber start, int iterations,int maxiterations)
{
if (iterations >= maxiterations)
return maxiterations;
if (current.LengthSquared() > 4f)
return iterations;
return CalculateMandelbrotIterations(current * current + start, start, ++iterations,maxiterations);
}