(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestSplitInt(t *testing.T) { |
| 30 | testCases := []struct { |
| 31 | name string |
| 32 | x int |
| 33 | n int |
| 34 | expectedResult []int |
| 35 | expectedError bool |
| 36 | }{ |
| 37 | {"multiple", 10, 5, []int{2, 2, 2, 2, 2}, false}, |
| 38 | {"n=1", 10, 1, []int{10}, false}, |
| 39 | {"x=10, n=3", 10, 3, []int{4, 3, 3}, false}, |
| 40 | {"x=10, n=7", 10, 7, []int{2, 2, 2, 1, 1, 1, 1}, false}, |
| 41 | {"n>x", 10, 11, nil, true}, |
| 42 | } |
| 43 | for _, testCase := range testCases { |
| 44 | t.Run(testCase.name, func(t *testing.T) { |
| 45 | res, err := splitInt(testCase.x, testCase.n) |
| 46 | for i := 0; i < len(testCase.expectedResult); i++ { |
| 47 | if res[i] != testCase.expectedResult[i] { |
| 48 | t.Fatalf("unexpected result at index %d: %d - expected %d", i, res[i], testCase.expectedResult[i]) |
| 49 | } |
| 50 | } |
| 51 | if testCase.expectedError { |
| 52 | if err == nil { |
| 53 | t.Fatal("expected an error, got nil") |
| 54 | } |
| 55 | } else { |
| 56 | if err != nil { |
| 57 | t.Fatalf("unexpected error - %s", err) |
| 58 | } |
| 59 | } |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestMonteCarloPi2(t *testing.T) { |
| 65 | res, err := MonteCarloPiConcurrent(100000000) |
nothing calls this directly
no test coverage detected