| 1 |
/* |
| 2 |
Copyright The containerd Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
/* |
| 18 |
Copyright 2019 The Go Authors. All rights reserved. |
| 19 |
Use of this source code is governed by a BSD-style |
| 20 |
license that can be found in the NOTICE.md file. |
| 21 |
*/ |
| 22 |
|
| 23 |
package remote |
| 24 |
|
| 25 |
import ( |
| 26 |
"reflect" |
| 27 |
"testing" |
| 28 |
) |
| 29 |
|
| 30 |
func TestRegionSet(t *testing.T) { |
| 31 |
tests := []struct { |
| 32 |
input []region |
| 33 |
expected []region |
| 34 |
}{ |
| 35 |
{ |
| 36 |
input: []region{{1, 3}, {2, 4}}, |
| 37 |
expected: []region{{1, 4}}, |
| 38 |
}, |
| 39 |
{ |
| 40 |
input: []region{{1, 5}, {2, 4}}, |
| 41 |
expected: []region{{1, 5}}, |
| 42 |
}, |
| 43 |
{ |
| 44 |
input: []region{{2, 4}, {1, 5}}, |
| 45 |
expected: []region{{1, 5}}, |
| 46 |
}, |
| 47 |
{ |
| 48 |
input: []region{{2, 4}, {6, 8}, {1, 5}}, |
| 49 |
expected: []region{{1, 8}}, |
| 50 |
}, |
| 51 |
{ |
| 52 |
input: []region{{1, 2}, {1, 2}}, |
| 53 |
expected: []region{{1, 2}}, |
| 54 |
}, |
| 55 |
{ |
| 56 |
input: []region{{1, 3}, {1, 2}}, |
| 57 |
expected: []region{{1, 3}}, |
| 58 |
}, |
| 59 |
{ |
| 60 |
input: []region{{1, 3}, {2, 3}}, |
| 61 |
expected: []region{{1, 3}}, |
| 62 |
}, |
| 63 |
{ |
| 64 |
input: []region{{1, 3}, {3, 6}}, |
| 65 |
expected: []region{{1, 6}}, |
| 66 |
}, |
| 67 |
{ |
| 68 |
input: []region{{1, 3}, {4, 6}}, // region.e is inclusive |
| 69 |
expected: []region{{1, 6}}, |
| 70 |
}, |
| 71 |
{ |
| 72 |
input: []region{{4, 6}, {1, 3}}, // region.e is inclusive |
| 73 |
expected: []region{{1, 6}}, |
| 74 |
}, |
| 75 |
{ |
| 76 |
input: []region{{4, 6}, {1, 3}, {7, 9}, {2, 8}}, |
| 77 |
expected: []region{{1, 9}}, |
| 78 |
}, |
| 79 |
{ |
| 80 |
input: []region{{4, 6}, {1, 5}, {7, 9}, {4, 8}}, |
| 81 |
expected: []region{{1, 9}}, |
| 82 |
}, |
| 83 |
{ |
| 84 |
input: []region{{7, 8}, {1, 2}, {5, 6}}, |
| 85 |
expected: []region{{1, 2}, {5, 8}}, |
| 86 |
}, |
| 87 |
} |
| 88 |
for i, tt := range tests { |
| 89 |
var rs regionSet |
| 90 |
for _, f := range tt.input { |
| 91 |
rs.add(f) |
| 92 |
} |
| 93 |
if !reflect.DeepEqual(tt.expected, rs.rs) { |
| 94 |
t.Errorf("#%d: expected %v, got %v", i, tt.expected, rs.rs) |
| 95 |
} |
| 96 |
} |
| 97 |
} |