From 90ca86ec9c3db804ac32ef942fa04a0aa8c133e7 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 14 Oct 2017 13:51:01 -0400 Subject: Adding math functions Signed-off-by: Dave Henderson --- math/math.go | 19 +++++++++++++++++++ math/math_test.go | 12 ++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 math/math.go create mode 100644 math/math_test.go (limited to 'math') 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)) +} -- cgit v1.2.3