Kotlin - Complex Numbers Complex
This commit is contained in:
parent
0c837c9284
commit
28b0a6a05a
2 changed files with 30 additions and 32 deletions
|
@ -43,11 +43,9 @@ data class ComplexNumber(val real: Double = 0.0, val imag: Double = 0.0){
|
|||
}
|
||||
}
|
||||
|
||||
// This implementation is silly, there is no documentation for it
|
||||
fun exponential(num: ComplexNumber): ComplexNumber{
|
||||
val x = num.real
|
||||
val y = num.imag
|
||||
|
||||
|
||||
return ComplexNumber(real = Math.pow(Math.E, x), imag = 1.0) * ComplexNumber(real = 1.0, imag = Math.pow(Math.E, y))
|
||||
return ComplexNumber(real = Math.pow(Math.E, x), imag = 0.0) * ComplexNumber(real = Math.cos(y), imag = Math.sin(y))
|
||||
}
|
|
@ -31,7 +31,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAdditionWithPurelyRealNumbers() {
|
||||
val expected = ComplexNumber(real = 3.0)
|
||||
|
@ -39,7 +39,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAdditionWithPurelyImaginaryNumbers() {
|
||||
val expected = ComplexNumber(imag = 3.0)
|
||||
|
@ -47,7 +47,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAdditionWithRealAndImaginaryParts() {
|
||||
val expected = ComplexNumber(real = 4.0, imag = 6.0)
|
||||
|
@ -55,7 +55,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testSubtractionWithPurelyRealNumbers() {
|
||||
val expected = ComplexNumber(real = -1.0, imag = 0.0)
|
||||
|
@ -63,7 +63,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testSubtractionWithPurelyImaginaryNumbers() {
|
||||
val expected = ComplexNumber(imag = -1.0)
|
||||
|
@ -71,7 +71,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testSubtractionWithRealAndImaginaryParts() {
|
||||
val expected = ComplexNumber(real = -2.0, imag = -2.0)
|
||||
|
@ -79,7 +79,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testMultiplicationWithPurelyRealNumbers() {
|
||||
val expected = ComplexNumber(real = 2.0)
|
||||
|
@ -87,7 +87,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testMultiplicationWithPurelyImaginaryNumbers() {
|
||||
val expected = ComplexNumber(real = -2.0)
|
||||
|
@ -95,7 +95,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testMultiplicationWithRealAndImaginaryParts() {
|
||||
val expected = ComplexNumber(real = -5.0, imag = 10.0)
|
||||
|
@ -103,7 +103,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testDivisionWithPurelyRealNumbers() {
|
||||
val expected = ComplexNumber(real = 0.5)
|
||||
|
@ -111,7 +111,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testDivisionWithPurelyImaginaryNumbers() {
|
||||
val expected = ComplexNumber(real = 0.5)
|
||||
|
@ -119,7 +119,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testDivisionWithRealAndImaginaryParts() {
|
||||
val expected = ComplexNumber(real = 0.44, imag = 0.08)
|
||||
|
@ -127,7 +127,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAbsoluteValueOfPositivePurelyRealNumber() {
|
||||
val expected = 5.0
|
||||
|
@ -135,7 +135,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAbsoluteValueOfNegativePurelyRealNumber() {
|
||||
val expected = 5.0
|
||||
|
@ -143,7 +143,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAbsoluteValueOfPurelyImaginaryNumberWithPositiveImaginaryPart() {
|
||||
val expected = 5.0
|
||||
|
@ -151,7 +151,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAbsoluteValueOfPurelyImaginaryNumberWithNegativeImaginaryPart() {
|
||||
val expected = 5.0
|
||||
|
@ -159,7 +159,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testAbsoluteValueOfNumberWithRealAndImaginaryParts() {
|
||||
val expected = 5.0
|
||||
|
@ -167,7 +167,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testConjugationOfPurelyRealNumber() {
|
||||
val expected = ComplexNumber(real = 5.0)
|
||||
|
@ -175,7 +175,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testConjugationOfPurelyImaginaryNumber() {
|
||||
val expected = ComplexNumber(imag = -5.0)
|
||||
|
@ -183,7 +183,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testConjugationOfNumberWithRealAndImaginaryParts() {
|
||||
val expected = ComplexNumber(real = 1.0, imag = -1.0)
|
||||
|
@ -191,7 +191,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testRealPartOfPurelyRealNumber() {
|
||||
val expected = 1.0
|
||||
|
@ -199,7 +199,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testRealPartOfPurelyImaginaryNumber() {
|
||||
val expected = 0.0
|
||||
|
@ -207,7 +207,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testRealPartOfNumberWithRealAndImaginaryParts() {
|
||||
val expected = 1.0
|
||||
|
@ -215,7 +215,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testImaginaryPartOfPurelyRealNumber() {
|
||||
val expected = 0.0
|
||||
|
@ -223,7 +223,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testImaginaryPartOfPurelyImaginaryNumber() {
|
||||
val expected = 1.0
|
||||
|
@ -231,7 +231,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testImaginaryPartOfNumberWithRealAndImaginaryParts() {
|
||||
val expected = 2.0
|
||||
|
@ -239,7 +239,7 @@ class ComplexNumberTest {
|
|||
assertDoublesEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testExponentialOfPurelyImaginaryNumber() {
|
||||
val expected = ComplexNumber(real = -1.0)
|
||||
|
@ -247,7 +247,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testExponentialOfZero() {
|
||||
val expected = ComplexNumber(real = 1.0)
|
||||
|
@ -255,7 +255,7 @@ class ComplexNumberTest {
|
|||
assertComplexNumbersEqual(expected, actual)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
fun testExponentialOfPurelyRealNumber() {
|
||||
val expected = ComplexNumber(real = Math.E)
|
||||
|
|
Loading…
Add table
Reference in a new issue