From e2826d30e4f68659254d911b219b4eb07fd4d007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 10 Jan 2022 13:12:13 +0100 Subject: [PATCH] Add sub --- internal/internal.go | 4 ++++ internal/internal_test.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/internal.go b/internal/internal.go index 0b04b79..1a804b6 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -3,3 +3,7 @@ package internal func Add(a, b int) int { return a + b } + +func Sub(a, b int) int { + return a - b +} diff --git a/internal/internal_test.go b/internal/internal_test.go index 8bdc2a8..16d576e 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -28,3 +28,24 @@ func TestAdd(t *testing.T) { }) } } +func TestSub(t *testing.T) { + var tc = []struct { + A int + B int + Expected int + }{ + {A: 1, B: 0, Expected: 1}, + {A: 1, B: 1, Expected: 0}, + {A: 0, B: -5, Expected: -5}, + } + + for _, test := range tc { + name := fmt.Sprintf("%d-%d", test.A, test.B) + t.Run(name, func(t *testing.T) { + result := internal.Sub(test.A, test.B) + if result != test.Expected { + t.Errorf("Got %d, expected %d", result, test.Expected) + } + }) + } +}