(t *testing.T, f testExtendedFunction)
| 5 | type testExtendedFunction func(int64, int64) (int64, int64, int64) |
| 6 | |
| 7 | func TemplateTestExtendedGCD(t *testing.T, f testExtendedFunction) { |
| 8 | var testCasesExtended = []struct { |
| 9 | name string |
| 10 | a int64 |
| 11 | b int64 |
| 12 | gcd int64 |
| 13 | x int64 |
| 14 | y int64 |
| 15 | }{ |
| 16 | {"gcd of 10 and 0", 10, 0, 10, 1, 0}, |
| 17 | {"gcd of 98 and 56", 98, 56, 14, -1, 2}, |
| 18 | {"gcd of 0 and 10", 0, 10, 10, 0, 1}, |
| 19 | } |
| 20 | for _, tc := range testCasesExtended { |
| 21 | t.Run(tc.name, func(t *testing.T) { |
| 22 | actualGcd, actualX, actualY := f(tc.a, tc.b) |
| 23 | if actualGcd != tc.gcd { |
| 24 | t.Errorf("Expected GCD of %d and %d to be: %v, but got: %d", tc.a, tc.b, tc.gcd, actualGcd) |
| 25 | } |
| 26 | if actualX != tc.x { |
| 27 | t.Errorf("Expected x satisfying %d * x + %d * y = gcd to be: %v, but got: %d", tc.a, tc.b, tc.x, actualX) |
| 28 | } |
| 29 | if actualY != tc.y { |
| 30 | t.Errorf("Expected y satisfying %d * x + %d * y = gcd to be: %v, but got: %d", tc.a, tc.b, tc.y, actualY) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestExtendedGCDRecursive(t *testing.T) { |
| 37 | TemplateTestExtendedGCD(t, ExtendedRecursive) |
no outgoing calls
no test coverage detected