Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

func addNumbers(a int, b int) int {
return a + b
}

func addComplexNumbers(a complex128, b complex128) complex128 {
return a + b
}
26 changes: 26 additions & 0 deletions add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import "testing"

func TestAddComplexNumbers(t *testing.T) {
testCases := []struct {
name string
a, b complex128
expected complex128
}{
{"add zero", 0, 0, 0},
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another test scenario here, for large numbers (e.g. 9 digit imaginary component of the complex number).

Copy link
Copy Markdown
Author

@puresweep2 puresweep2 Bot Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Wrote Changes

Done.

{"add positive numbers", 1 + 2i, 3 + 4i, 4 + 6i},
{"add negative numbers", -1 - 2i, -3 - 4i, -4 - 6i},
{"add mixed numbers", -1 + 2i, 3 - 4i, 2 - 2i},
{"add large numbers", 1 + 123456789i, 2 + 987654321i, 3 + 1111111110i},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := addComplexNumbers(tc.a, tc.b)
if result != tc.expected {
t.Errorf("addComplexNumbers(%v, %v) = %v; want %v", tc.a, tc.b, result, tc.expected)
}
})
}
}