Sage: Ticket #16244: Simplify TestSuite's some_elements role and logic (no random sampling)
https://trac.sagemath.org/ticket/16244
<p>
Since <a class="closed ticket" href="https://trac.sagemath.org/ticket/14284" title="enhancement: Sampling in unit tests (closed: fixed)">#14284</a>, <code>TestSuite</code> (more precisely <code>InstanceTester.some_elements</code>) tries to be fancy by choosing "some elements" using a random sample. The random sample is built using Python's <code>random.sample</code>, which requires its input to be a Sequence (i.e. the i-th element can be fetched with o[i]), or some dict-like object. This can get brittle with inputs where <code>__getitem__</code> is used for other purposes, or where unranking is just computationally expensive. The <code>some_elements</code> method also assumes <code>__len__</code> to be implemented and cheap enough.
</p>
<p>
Example:
</p>
<pre class="wiki">sage: FF = IntegerModRing(29) # needs to be >21 otherwise random.sample uses a different strategy
sage: tester = FF._tester(elements=FF, max_runs=5)
sage: list(tester.some_elements())
...
ValueError: first letter of variable name must be a letter
</pre><p>
This ticket reduces the role of <code>InstanceTester.some_elements</code> to just do some argument parsing and ensure that at most "max_run" elements are returned. It only requires the input to be iterable.
</p>
<p>
If we want to have fancy random samples, we should define a specific protocol (typically P.sample()) for it, or just let parents decide on the strategy by defining some_elements appropriately.
</p>
<p>
This was originaly analyzed in <a class="closed ticket" href="https://trac.sagemath.org/ticket/15919" title="defect: unrank via R[i] conflicts with notation for constructing polynomial ... (closed: fixed)">#15919</a>.
</p>
<p>
TODO: decide whether <a class="missing wiki">InstanceTester?</a>.some_elements should return a list or an iterator. A list would be more user friendly (though that's not critical since this is pretty low level) and maybe less error-prone (if a _test_method attempt to reuse the result twice). On the other hand, in case of failure of a _test_method, using an iterator would waste a bit less time before the failure occurs (no need to build all the elements).
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/16244
Trac 1.1.6nthierySat, 26 Apr 2014 21:15:59 GMTbranch set
https://trac.sagemath.org/ticket/16244#comment:1
https://trac.sagemath.org/ticket/16244#comment:1
<ul>
<li><strong>branch</strong>
set to <em>u/nthiery/simplify_testsuite_s_some_elements_role_and_logic__no_random_sampling_</em>
</li>
</ul>
TicketnthierySat, 26 Apr 2014 21:32:41 GMTstatus changed; commit set
https://trac.sagemath.org/ticket/16244#comment:2
https://trac.sagemath.org/ticket/16244#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>2486f804d260370ee1d9a7a9b3a7962a36ea0e65</em>
</li>
</ul>
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="http://git.sagemath.org/sage.git/commit/?id=2486f804d260370ee1d9a7a9b3a7962a36ea0e65"><span class="icon"></span>2486f80</a></td><td><code>#16244: Simplify the role and logic of TestSuite's some_elements (no random sampling)</code>
</td></tr></table>
TicketnthierySat, 26 Apr 2014 21:39:09 GMTcc, description changed
https://trac.sagemath.org/ticket/16244#comment:3
https://trac.sagemath.org/ticket/16244#comment:3
<ul>
<li><strong>cc</strong>
<em>roed</em> <em>saraedum</em> added
</li>
<li><strong>description</strong>
modified (<a href="/ticket/16244?action=diff&version=3">diff</a>)
</li>
</ul>
TicketnthierySat, 26 Apr 2014 21:44:05 GMTdescription changed
https://trac.sagemath.org/ticket/16244#comment:4
https://trac.sagemath.org/ticket/16244#comment:4
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/16244?action=diff&version=4">diff</a>)
</li>
</ul>
TickettscrimMon, 28 Apr 2014 14:55:02 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/16244#comment:5
https://trac.sagemath.org/ticket/16244#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Travis Scrimshaw</em>
</li>
</ul>
<p>
LGTM (also with <a class="closed ticket" href="https://trac.sagemath.org/ticket/15919" title="defect: unrank via R[i] conflicts with notation for constructing polynomial ... (closed: fixed)">#15919</a>).
</p>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/16244#comment:6
https://trac.sagemath.org/ticket/16244#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
TicketvbraunMon, 12 May 2014 19:32:52 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/16244#comment:7
https://trac.sagemath.org/ticket/16244#comment:7
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>u/nthiery/simplify_testsuite_s_some_elements_role_and_logic__no_random_sampling_</em> to <em>2486f804d260370ee1d9a7a9b3a7962a36ea0e65</em>
</li>
</ul>
TicketroedSat, 26 Aug 2017 04:13:21 GMTcommit deleted
https://trac.sagemath.org/ticket/16244#comment:8
https://trac.sagemath.org/ticket/16244#comment:8
<ul>
<li><strong>commit</strong>
<em>2486f804d260370ee1d9a7a9b3a7962a36ea0e65</em> deleted
</li>
</ul>
<p>
See <a class="closed ticket" href="https://trac.sagemath.org/ticket/23724" title="enhancement: Allow random sampling for unit testing (closed: fixed)">#23724</a> for adding this back in (but optionally)
</p>
Ticket