diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2017-10-14 13:51:01 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2017-10-30 22:18:37 -0400 |
| commit | 90ca86ec9c3db804ac32ef942fa04a0aa8c133e7 (patch) | |
| tree | 5295f93799d77f8fc0eb5ed3199fd41b858b0d6e /math | |
| parent | 4e626fdfc870c212c73e5b9494f63888e570f8ac (diff) | |
Adding math functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'math')
| -rw-r--r-- | math/math.go | 19 | ||||
| -rw-r--r-- | math/math_test.go | 12 |
2 files changed, 31 insertions, 0 deletions
diff --git a/math/math.go b/math/math.go new file mode 100644 index 00000000..9eaef051 --- /dev/null +++ b/math/math.go @@ -0,0 +1,19 @@ +package math + +// AddInt - +func AddInt(n ...int64) int64 { + x := int64(0) + for _, i := range n { + x += i + } + return x +} + +// MulInt - +func MulInt(n ...int64) int64 { + var x int64 = 1 + for _, i := range n { + x *= i + } + return x +} diff --git a/math/math_test.go b/math/math_test.go new file mode 100644 index 00000000..9c4da13a --- /dev/null +++ b/math/math_test.go @@ -0,0 +1,12 @@ +package math + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMath(t *testing.T) { + assert.Equal(t, int64(10), AddInt(1, 2, 3, 4)) + assert.Equal(t, int64(12), MulInt(3, 4, 1)) +} |
