Skip to content

Add test file for lcm #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2021
Merged
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
44 changes: 44 additions & 0 deletions math/lcm/lcm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package lcm

import "testing"

func TestLcm(t *testing.T) {
testCases := []struct {
name string
a int64
b int64
output int64
}{
{
name: "LCM of 1 & 5",
a: 1,
b: 5,
output: 5,
}, {
name: "LCM of 2 & 5",
a: 2,
b: 5,
output: 10,
}, {
name: "LCM of 5 & 10",
a: 10,
b: 5,
output: 10,
}, {
name: "LCM of 5 & 5",
a: 5,
b: 5,
output: 5,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual_output := Lcm(tc.a, tc.b)
if actual_output != tc.output {
t.Errorf("Expected LCM of %d and %d is %d, but got %d", tc.a, tc.b, tc.output,
actual_output)
}
})
}
}