21: amicable numbers

This commit is contained in:
VicRen
2020-10-20 15:07:14 +08:00
parent e2c5f95122
commit 64d25a8714
2 changed files with 90 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package main
import (
"testing"
)
func Test_sumOfDivisors(t *testing.T) {
tt := []struct {
name string
input int
want int
}{
{
"220",
220,
284,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := sumOfDivisors(tc.input)
if got != tc.want {
t.Errorf("sumOfDivisors() = %d, want %d", got, tc.want)
}
})
}
}
func Test_isAmicableNumber(t *testing.T) {
tt := []struct {
name string
input int
want bool
}{
{
"220",
220,
true,
},
{
"221",
221,
false,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := isAmicableNumber(tc.input)
if got != tc.want {
t.Errorf("isAmicableNumber() = %v, want %v", got, tc.want)
}
})
}
}