public static void IndexOfAny_LastIndexOfAny_AlgComplexity_RefType() { // Similar to RunIndexOfAnyAlgComplexityTest (see comments there), but we can't use // BoundedMemory because we're dealing with ref types. Instead, we'll trap the call to // Equals and use that to fail the test. Span <CustomEquatableType <int> > haystack = new CustomEquatableType <int> [8192]; haystack[1024] = new CustomEquatableType <int>(default, isPoison: true); // fail the test if we iterate this far
public bool Equals(CustomEquatableType <T> other) { if (_isPoison) { throw new InvalidOperationException("This object is poisoned and its Equals method should not be called."); } if (other is null) { return(false); } if (other._isPoison) { throw new InvalidOperationException("The 'other' object is poisoned and should not be passed to Equals."); } return(_value.Equals(other._value)); }