Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c6daca4

Browse files
author
openset
committed
Add: Add Digits
1 parent a273546 commit c6daca4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

‎problems/add-digits/add_digits.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
package add_digits
2+
3+
func addDigits(num int) int {
4+
return (num-1)%9 + 1
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
package add_digits
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected int
8+
}
9+
10+
func TestAddDigits(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 38,
14+
expected: 2,
15+
},
16+
}
17+
for _, tc := range tests {
18+
output := addDigits(tc.input)
19+
if output != tc.expected {
20+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
21+
}
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /