News for hackers. Stuff that matters.
Re:Hypothesis: Property-Based Testing for Python by lgas on Wednesday November 05, 2025 @05:39AM (#45821481)
Always returning the empty list meets your spec.
Re:Hypothesis: Property-Based Testing for Python by wongarsu on Wednesday November 05, 2025 @05:50AM (#45821530)
Good point. I suppose we should add "number of input elements equals number of output elements" and "every input element is present in the output". Translated in a straightforward test that still allows my_sort([1,1,2]) to return [1,2,2], but we have to draw the line somewhere
Re:Hypothesis: Property-Based Testing for Python by masklinn on Wednesday November 05, 2025 @11:44AM (#45824990)
> we have to draw the line somewhere

Do we? You can pop-count the two lists and checks that those are equal.

Re:Hypothesis: Property-Based Testing for Python by travisjungroth on Wednesday November 05, 2025 @01:42PM (#45826305)
Just use Counter and if the objects aren’t hashable, use the count of IDs. Grab this before calling the function, in case the function is destructive. Check it against the output.

Add in checking each item is less than or equal to its successor and you have the fundamental sort properties. You might have more, like stability.