| 8 | ) |
| 9 | |
| 10 | func TestBin2(t *testing.T) { |
| 11 | td := []struct { |
| 12 | n, k, expected int |
| 13 | }{ |
| 14 | {0, 0, 1}, |
| 15 | {1, 1, 1}, |
| 16 | {2, 0, 1}, {2, 1, 2}, {2, 2, 1}, |
| 17 | {3, 0, 1}, {3, 1, 3}, {3, 2, 3}, {3, 3, 1}, |
| 18 | {4, 0, 1}, {4, 1, 4}, {4, 2, 6}, {4, 3, 4}, {4, 4, 1}, |
| 19 | {5, 0, 1}, {5, 1, 5}, {5, 2, 10}, {5, 3, 10}, {5, 4, 5}, {5, 5, 1}, |
| 20 | {10, 2, 45}, |
| 21 | {15, 10, 3003}, |
| 22 | } |
| 23 | for _, tc := range td { |
| 24 | name := fmt.Sprintf("binomial coefficient of (%d, %d)", tc.n, tc.k) |
| 25 | t.Run(name, func(t *testing.T) { |
| 26 | actual := dynamic.Bin2(tc.n, tc.k) |
| 27 | if actual != tc.expected { |
| 28 | t.Errorf("expecting binomial coefficient of (%d, %d) to be %d but got %d", tc.n, tc.k, tc.expected, actual) |
| 29 | } |
| 30 | }) |
| 31 | } |
| 32 | } |