Skip to content

Commit

Permalink
solve complex numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Nov 28, 2023
1 parent f5eff66 commit f4a15c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion go/complex-numbers/complex_numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ func (n Number) Abs() float64 {
}

func (n Number) Exp() Number {
panic("Please implement the Exp method")
return Number{
a: math.Pow(math.E, n.a) * math.Cos(n.b),
b: math.Pow(math.E, n.a) * math.Sin(n.b),
}
}
20 changes: 10 additions & 10 deletions go/complex-numbers/complex_numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func TestNumber_Conjugate(t *testing.T) {
}
}

// func TestNumber_Exp(t *testing.T) {
// for _, tt := range expTestCases {
// t.Run(tt.description, func(t *testing.T) {
// n := Number{tt.in.a, tt.in.b}
// if got := n.Exp(); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
// t.Errorf("Number%+v.Exp()\n got: %+v\nwant: %+v", tt.in, got, tt.want)
// }
// })
// }
// }
func TestNumber_Exp(t *testing.T) {
for _, tt := range expTestCases {
t.Run(tt.description, func(t *testing.T) {
n := Number{tt.in.a, tt.in.b}
if got := n.Exp(); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
t.Errorf("Number%+v.Exp()\n got: %+v\nwant: %+v", tt.in, got, tt.want)
}
})
}
}

0 comments on commit f4a15c1

Please sign in to comment.