Colin Cross | 9a642dc | 2019-05-30 11:17:23 -0700 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func Test_shardTests(t *testing.T) { |
| 23 | type args struct { |
| 24 | paths []string |
| 25 | shards int |
| 26 | } |
| 27 | tests := []struct { |
| 28 | name string |
| 29 | args args |
| 30 | want [][]string |
| 31 | }{ |
| 32 | { |
| 33 | name: "empty", |
| 34 | args: args{ |
| 35 | paths: nil, |
| 36 | shards: 1, |
| 37 | }, |
| 38 | want: [][]string(nil), |
| 39 | }, |
| 40 | { |
| 41 | name: "too many shards", |
| 42 | args: args{ |
| 43 | paths: []string{"a", "b"}, |
| 44 | shards: 3, |
| 45 | }, |
| 46 | want: [][]string{{"a"}, {"b"}}, |
| 47 | }, |
| 48 | { |
| 49 | name: "single shard", |
| 50 | args: args{ |
| 51 | paths: []string{"a", "b"}, |
| 52 | shards: 1, |
| 53 | }, |
| 54 | want: [][]string{{"a", "b"}}, |
| 55 | }, |
| 56 | { |
| 57 | name: "shard per input", |
| 58 | args: args{ |
| 59 | paths: []string{"a", "b", "c"}, |
| 60 | shards: 3, |
| 61 | }, |
| 62 | want: [][]string{{"a"}, {"b"}, {"c"}}, |
| 63 | }, |
| 64 | { |
| 65 | name: "balanced shards", |
| 66 | args: args{ |
| 67 | paths: []string{"a", "b", "c", "d"}, |
| 68 | shards: 2, |
| 69 | }, |
| 70 | want: [][]string{{"a", "b"}, {"c", "d"}}, |
| 71 | }, |
| 72 | { |
| 73 | name: "unbalanced shards", |
| 74 | args: args{ |
| 75 | paths: []string{"a", "b", "c"}, |
| 76 | shards: 2, |
| 77 | }, |
| 78 | want: [][]string{{"a", "b"}, {"c"}}, |
| 79 | }, |
| 80 | } |
| 81 | for _, tt := range tests { |
| 82 | t.Run(tt.name, func(t *testing.T) { |
| 83 | if got := shardTests(tt.args.paths, tt.args.shards); !reflect.DeepEqual(got, tt.want) { |
| 84 | t.Errorf("shardTests() = %v, want %v", got, tt.want) |
| 85 | } |
| 86 | }) |
| 87 | } |
| 88 | } |