MCPcopy
hub / github.com/expr-lang/expr / NotSubset

Function NotSubset

internal/testify/assert/assertions.go:1029–1079  ·  view source on GitHub ↗

NotSubset asserts that the specified list(array, slice...) or map does NOT contain all elements given in the specified subset list(array, slice...) or map. assert.NotSubset(t, [1, 3, 4], [1, 2]) assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})

(t TestingT, list, subset interface{}, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1027// assert.NotSubset(t, [1, 3, 4], [1, 2])
1028// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
1029func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
1030 if h, ok := t.(tHelper); ok {
1031 h.Helper()
1032 }
1033 if subset == nil {
1034 return Fail(t, "nil is the empty set which is a subset of every set", msgAndArgs...)
1035 }
1036
1037 listKind := reflect.TypeOf(list).Kind()
1038 if listKind != reflect.Array && listKind != reflect.Slice && listKind != reflect.Map {
1039 return Fail(t, fmt.Sprintf("%q has an unsupported type %s", list, listKind), msgAndArgs...)
1040 }
1041
1042 subsetKind := reflect.TypeOf(subset).Kind()
1043 if subsetKind != reflect.Array && subsetKind != reflect.Slice && listKind != reflect.Map {
1044 return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...)
1045 }
1046
1047 if subsetKind == reflect.Map && listKind == reflect.Map {
1048 subsetMap := reflect.ValueOf(subset)
1049 actualMap := reflect.ValueOf(list)
1050
1051 for _, k := range subsetMap.MapKeys() {
1052 ev := subsetMap.MapIndex(k)
1053 av := actualMap.MapIndex(k)
1054
1055 if !av.IsValid() {
1056 return true
1057 }
1058 if !ObjectsAreEqual(ev.Interface(), av.Interface()) {
1059 return true
1060 }
1061 }
1062
1063 return Fail(t, fmt.Sprintf("%q is a subset of %q", subset, list), msgAndArgs...)
1064 }
1065
1066 subsetList := reflect.ValueOf(subset)
1067 for i := 0; i < subsetList.Len(); i++ {
1068 element := subsetList.Index(i).Interface()
1069 ok, found := containsElement(list, element)
1070 if !ok {
1071 return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
1072 }
1073 if !found {
1074 return true
1075 }
1076 }
1077
1078 return Fail(t, fmt.Sprintf("%q is a subset of %q", subset, list), msgAndArgs...)
1079}
1080
1081// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
1082// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,

Callers 5

NotSubsetFunction · 0.92
NotSubsetfFunction · 0.70
TestSubsetNotSubsetFunction · 0.70
TestNotSubsetNilFunction · 0.70
NotSubsetMethod · 0.70

Calls 6

ObjectsAreEqualFunction · 0.85
containsElementFunction · 0.85
SprintfMethod · 0.80
FailFunction · 0.70
HelperMethod · 0.45
LenMethod · 0.45

Tested by 2

TestSubsetNotSubsetFunction · 0.56
TestNotSubsetNilFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…