slice_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. package common
  17. import (
  18. "testing"
  19. "github.com/stretchr/testify/assert"
  20. )
  21. func TestContainsAll_whenTypical(t *testing.T) {
  22. source := []string{"1", "2"}
  23. target1 := []string{"3"}
  24. target2 := []string{"1", "2"}
  25. assert.True(t, ContainsAll(source, target1, target2))
  26. }
  27. func TestContainsAll_whenNot(t *testing.T) {
  28. source := []string{"1", "2"}
  29. target := []string{"3", "4"}
  30. assert.False(t, ContainsAll(source, target))
  31. }
  32. func TestContainsAll_whenTargetIsSubset(t *testing.T) {
  33. source := []string{"1", "2"}
  34. target := []string{"1"}
  35. assert.True(t, ContainsAll(source, target))
  36. }
  37. func TestContainsAll_whenTargetIsSuperSet(t *testing.T) {
  38. source := []string{"2"}
  39. target := []string{"1", "2"}
  40. assert.False(t, ContainsAll(source, target))
  41. }
  42. func TestContainsAll_whenSourceIsEmpty(t *testing.T) {
  43. var source []string
  44. target := []string{"1", "2"}
  45. assert.False(t, ContainsAll(source, target))
  46. }
  47. func TestContainsAll_whenSourceIsNil(t *testing.T) {
  48. target := []string{"1", "2"}
  49. assert.False(t, ContainsAll(nil, target))
  50. }
  51. func TestContainsAll_whenTargetIsEmpty(t *testing.T) {
  52. source := []string{"1", "2"}
  53. assert.True(t, ContainsAll(source, []string{}))
  54. }
  55. func TestContainsAll_whenTargetIsNil(t *testing.T) {
  56. source := []string{"1", "2"}
  57. assert.True(t, ContainsAll(source, nil))
  58. }
  59. func TestAppendSkipDuplicates_whenTypical(t *testing.T) {
  60. source := []string{"1", "2"}
  61. additional := []string{"1", "3"}
  62. assert.Equal(t, []string{"1", "2", "3"}, AppendSkipDuplicates(source, additional...))
  63. }
  64. func TestAppendSkipDuplicates_whenSourceIsNil(t *testing.T) {
  65. additional := []string{"1", "3"}
  66. assert.Equal(t, []string{"1", "3"}, AppendSkipDuplicates(nil, additional...))
  67. }
  68. func TestAppendSkipDuplicates_whenElementIsNil(t *testing.T) {
  69. assert.Equal(t, []string{"1", "3"}, AppendSkipDuplicates([]string{"1", "3"}, nil...))
  70. }