[swift-dev] Should we remove _customContainsEquatableElement from stdlib?

Dmitri Gribenko gribozavr at gmail.com
Thu Dec 31 15:49:06 CST 2015


On Thu, Dec 31, 2015 at 10:06 PM, Ling Wang <an00na at gmail.com> wrote:
> Do you mean something like this in validation-test/stdlib/SequenceType.swift.gyb:
>
> SequenceTypeTests.test("Range<Element>.contains/WhereElementIsComparable/dispatch") {
>   MinimalComparableValue.timesLessWasCalled = 0
>   let start = 0
>   let end = 10
>   let range = Range(start: MinimalComparableValue(start), end: MinimalComparableValue(end))
>   let count = 20
>   for test in 0...count {
>     expectEqual(
>       test >= start && test < end,
>       range.contains(MinimalComparableValue(test)))
>   }
>   expectEqual(
>     count * 2, MinimalComparableValue.timesLessWasCalled)
> }

Yes, this would be good.

> There is one issue. MinimalComparableValue doesn’t conform to ForwardIndexType. I’m not sure it is proper for me to add this conformance in an extension because the definition of MinimalComparableValue is “A type that conforms only to `Equatable` and `Comparable`”.
>
> What’s your suggestion?

I think it would be appropriate to define a special type like
MinimalComparableValue just for this test since the requirements are
quite specific (Comparable + ForwardIndexType).

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-dev mailing list