|
| 1 | +package apis |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/godbus/dbus/v5" |
| 7 | +) |
| 8 | + |
| 9 | +func isNegative(v int) bool { |
| 10 | + return v < 0 |
| 11 | +} |
| 12 | + |
| 13 | +func TestAnyOfIsNegativeTrue(t *testing.T) { |
| 14 | + testValues := []int{5, 7, -4, 6, 8} |
| 15 | + expected := true |
| 16 | + result := anyOf[int](testValues, isNegative) |
| 17 | + if expected != result { |
| 18 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +func TestAnyOfIsNegativeFalse(t *testing.T) { |
| 23 | + testValues := []int{5, 7, 4, 6, 8} |
| 24 | + expected := false |
| 25 | + result := anyOf[int](testValues, isNegative) |
| 26 | + if expected != result { |
| 27 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestAnyOfIsNegativeEmpty(t *testing.T) { |
| 32 | + testValues := []int{} |
| 33 | + expected := false |
| 34 | + result := anyOf[int](testValues, isNegative) |
| 35 | + if expected != result { |
| 36 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TestAnyOfIsNegativeFirst(t *testing.T) { |
| 41 | + testValues := []int{-5, 7, 4, 6, 8} |
| 42 | + expected := true |
| 43 | + result := anyOf[int](testValues, isNegative) |
| 44 | + if expected != result { |
| 45 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +func TestAnyOfIsNegativeLast(t *testing.T) { |
| 50 | + testValues := []int{5, 7, 4, 6, -8} |
| 51 | + expected := true |
| 52 | + result := anyOf[int](testValues, isNegative) |
| 53 | + if expected != result { |
| 54 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +func TestIsFDTrue(t *testing.T) { |
| 59 | + var tested dbus.UnixFD |
| 60 | + expected := true |
| 61 | + result := isFileDescriptor(tested) |
| 62 | + |
| 63 | + if expected != result { |
| 64 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +func TestIsFDInt(t *testing.T) { |
| 69 | + var tested int |
| 70 | + expected := false |
| 71 | + result := isFileDescriptor(tested) |
| 72 | + |
| 73 | + if expected != result { |
| 74 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func TestIsFDInterface(t *testing.T) { |
| 79 | + var tested interface{} |
| 80 | + expected := false |
| 81 | + result := isFileDescriptor(tested) |
| 82 | + |
| 83 | + if expected != result { |
| 84 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +func TestAnyOfIsFDTrue(t *testing.T) { |
| 89 | + var fd dbus.UnixFD |
| 90 | + var i interface{} |
| 91 | + |
| 92 | + testValues := []any{5, fd, i} |
| 93 | + expected := true |
| 94 | + result := anyOf[any](testValues, isFileDescriptor) |
| 95 | + if expected != result { |
| 96 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +func TestAnyOfIsFDFalse(t *testing.T) { |
| 101 | + var i interface{} |
| 102 | + |
| 103 | + testValues := []any{5, -7, i} |
| 104 | + expected := false |
| 105 | + result := anyOf[any](testValues, isFileDescriptor) |
| 106 | + if expected != result { |
| 107 | + t.Errorf("Expecting %v, got %v", expected, result) |
| 108 | + } |
| 109 | +} |
0 commit comments