Example #1
0
// DisorderedSubset attempts to find all the given subsets in the list of actuals.
// Does not allow one actual to match more than one subset, be warray of the
// possibility of insufficiently specific subsets.
func DisorderedSubset(t Fataler, a, s interface{}, extra ...interface{}) {
	actuals := toInterfaceSlice(a)
	subsets := toInterfaceSlice(s)

	used := make([]bool, len(actuals))
	matches := 0
	for _, subset := range subsets {
		for i, actual := range actuals {
			if used[i] {
				continue
			}
			if subsetp.Check(subset, actual) {
				matches++
				used[i] = true
				break
			}
		}
	}
	if matches != len(subsets) {
		fatal(cond{
			Fataler:    t,
			Format:     "expected subsets not found:\nACTUAL:\n%s\nEXPECTED SUBSET\n%s",
			FormatArgs: []interface{}{spew.Sdump(actuals), tsdump(subsets)},
			Extra:      extra,
		})
	}
}
Example #2
0
// Subset ensures actual matches subset.
func Subset(t Fataler, actual, subset interface{}, a ...interface{}) {
	if !subsetp.Check(subset, actual) {
		fatal(cond{
			Fataler:    t,
			Format:     "expected subset not found:\nACTUAL:\n%s\nEXPECTED SUBSET\n%s",
			FormatArgs: []interface{}{spew.Sdump(actual), tsdump(subset)},
			Extra:      a,
		})
	}
}