go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/common/i64_test.go (about) 1 // Copyright 2021 The LUCI Authors. 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 common 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 ) 22 23 func TestI64s(t *testing.T) { 24 t.Parallel() 25 26 Convey("UniqueSorted", t, func() { 27 v := []int64{7, 6, 3, 1, 3, 4, 9, 2, 1, 5, 8, 8, 8, 4, 9} 28 v1 := UniqueSorted(v) 29 So(v1, ShouldResemble, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9}) 30 So(v[:len(v1)], ShouldResemble, v1) // re-uses space 31 32 v = []int64{1, 2, 2, 3, 4, 5, 5} 33 v1 = UniqueSorted(v) 34 So(v1, ShouldResemble, []int64{1, 2, 3, 4, 5}) 35 So(v[:len(v1)], ShouldResemble, v1) // re-uses space 36 }) 37 38 Convey("DifferenceSorted", t, func() { 39 all := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} 40 odd := []int64{1, 3, 5, 7, 9, 11} 41 div3 := []int64{3, 6, 9} 42 43 So(DifferenceSorted(odd, all), ShouldBeEmpty) 44 So(DifferenceSorted(div3, all), ShouldBeEmpty) 45 46 So(DifferenceSorted(all, odd), ShouldResemble, []int64{2, 4, 6, 8, 10}) 47 So(DifferenceSorted(all, div3), ShouldResemble, []int64{1, 2, 4, 5, 7, 8, 10, 11}) 48 49 So(DifferenceSorted(odd, div3), ShouldResemble, []int64{1, 5, 7, 11}) 50 So(DifferenceSorted(div3, odd), ShouldResemble, []int64{6}) 51 }) 52 53 Convey("UnionSorted", t, func() { 54 all := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9} 55 odd := []int64{1, 3, 5, 7, 9} 56 div3 := []int64{3, 6, 9} 57 58 So(UnionSorted(odd, all), ShouldResemble, all) 59 So(UnionSorted(all, div3), ShouldResemble, all) 60 So(UnionSorted(all, all), ShouldResemble, all) 61 So(UnionSorted(all, nil), ShouldResemble, all) 62 So(UnionSorted(nil, all), ShouldResemble, all) 63 64 So(UnionSorted(odd, div3), ShouldResemble, []int64{1, 3, 5, 6, 7, 9}) 65 So(UnionSorted(div3, odd), ShouldResemble, []int64{1, 3, 5, 6, 7, 9}) 66 }) 67 }