|
| 1 | +// Copyright 2014 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package common |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | +) |
| 24 | + |
| 25 | +func TestContainsAll_whenTypical(t *testing.T) { |
| 26 | + source := []string{"1", "2"} |
| 27 | + target := []string{"1", "2"} |
| 28 | + |
| 29 | + assert.True(t, ContainsAll(source, target)) |
| 30 | +} |
| 31 | + |
| 32 | +func TestContainsAll_whenNot(t *testing.T) { |
| 33 | + source := []string{"1", "2"} |
| 34 | + target := []string{"3", "4"} |
| 35 | + |
| 36 | + assert.False(t, ContainsAll(source, target)) |
| 37 | +} |
| 38 | + |
| 39 | +func TestContainsAll_whenTargetIsSubset(t *testing.T) { |
| 40 | + source := []string{"1", "2"} |
| 41 | + target := []string{"1"} |
| 42 | + |
| 43 | + assert.True(t, ContainsAll(source, target)) |
| 44 | +} |
| 45 | + |
| 46 | +func TestContainsAll_whenTargetIsSuperSet(t *testing.T) { |
| 47 | + source := []string{"2"} |
| 48 | + target := []string{"1", "2"} |
| 49 | + |
| 50 | + assert.False(t, ContainsAll(source, target)) |
| 51 | +} |
| 52 | + |
| 53 | +func TestContainsAll_whenSourceIsEmpty(t *testing.T) { |
| 54 | + var source []string |
| 55 | + target := []string{"1", "2"} |
| 56 | + |
| 57 | + assert.False(t, ContainsAll(source, target)) |
| 58 | +} |
| 59 | + |
| 60 | +func TestContainsAll_whenSourceIsNil(t *testing.T) { |
| 61 | + target := []string{"1", "2"} |
| 62 | + |
| 63 | + assert.False(t, ContainsAll(nil, target)) |
| 64 | +} |
| 65 | + |
| 66 | +func TestContainsAll_whenTargetIsEmpty(t *testing.T) { |
| 67 | + source := []string{"1", "2"} |
| 68 | + |
| 69 | + assert.True(t, ContainsAll(source, []string{})) |
| 70 | +} |
| 71 | + |
| 72 | +func TestContainsAll_whenTargetIsNil(t *testing.T) { |
| 73 | + source := []string{"1", "2"} |
| 74 | + |
| 75 | + assert.True(t, ContainsAll(source, nil)) |
| 76 | +} |
| 77 | + |
| 78 | +func TestAppendSkipDuplicates_whenTypical(t *testing.T) { |
| 79 | + source := []string{"1", "2"} |
| 80 | + additional := []string{"1", "3"} |
| 81 | + |
| 82 | + assert.Equal(t, []string{"1", "2", "3"}, AppendSkipDuplicates(source, additional...)) |
| 83 | +} |
| 84 | + |
| 85 | +func TestAppendSkipDuplicates_whenSourceIsNil(t *testing.T) { |
| 86 | + additional := []string{"1", "3"} |
| 87 | + |
| 88 | + assert.Equal(t, []string{"1", "3"}, AppendSkipDuplicates(nil, additional...)) |
| 89 | +} |
| 90 | + |
| 91 | +func TestAppendSkipDuplicates_whenElementIsNil(t *testing.T) { |
| 92 | + assert.Equal(t, []string{"1", "3"}, AppendSkipDuplicates([]string{"1", "3"}, nil...)) |
| 93 | +} |
0 commit comments