Skip to content

Commit 5654ce9

Browse files
mbalayilsiriak
andauthored
Add test file for lcm (#302)
Co-authored-by: Andrii Siriak <[email protected]>
1 parent 066d15e commit 5654ce9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

math/lcm/lcm_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package lcm
2+
3+
import "testing"
4+
5+
func TestLcm(t *testing.T) {
6+
testCases := []struct {
7+
name string
8+
a int64
9+
b int64
10+
output int64
11+
}{
12+
{
13+
name: "LCM of 1 & 5",
14+
a: 1,
15+
b: 5,
16+
output: 5,
17+
}, {
18+
name: "LCM of 2 & 5",
19+
a: 2,
20+
b: 5,
21+
output: 10,
22+
}, {
23+
name: "LCM of 5 & 10",
24+
a: 10,
25+
b: 5,
26+
output: 10,
27+
}, {
28+
name: "LCM of 5 & 5",
29+
a: 5,
30+
b: 5,
31+
output: 5,
32+
},
33+
}
34+
35+
for _, tc := range testCases {
36+
t.Run(tc.name, func(t *testing.T) {
37+
actual_output := Lcm(tc.a, tc.b)
38+
if actual_output != tc.output {
39+
t.Errorf("Expected LCM of %d and %d is %d, but got %d", tc.a, tc.b, tc.output,
40+
actual_output)
41+
}
42+
})
43+
}
44+
}

0 commit comments

Comments
 (0)