Commit b3e0b852 authored by Jérôme Ortais's avatar Jérôme Ortais
Browse files

Modification d'un doctest pour mise en conformité avec les évolutions du

code dans la classe PolynomesCollege
parent e2576f97
......@@ -16,11 +16,9 @@ dist/
/.project
/.pydevproject
/.settings/
/src/.bank
/src/.project
/src/.pydevproject
/src/.settings/
#
# tests persos
/src/test.py
......
......@@ -526,7 +526,7 @@
<span class="sd"> &gt;&gt;&gt; Polynome(&#39;3x&#39;, details=1)*Polynome(&#39;2x+5&#39;, details=1)</span>
<span class="sd"> &#39;Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[2, 1]], &quot;x&quot;, 1)+Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[5, 0]], &quot;x&quot;, 1)&#39;</span>
<span class="sd"> &gt;&gt;&gt; Polynome(&#39;3x&#39;, details=3) * Polynome(&#39;2x&#39;, details=3)</span>
<span class="sd"> &quot;3*2*Polynome([[1, 1]], &#39;x&#39;, 3)*Polynome([[1, 1]], &#39;x&#39;, 3)&quot;</span>
<span class="sd"> &quot;Polynome([[3, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)*Polynome([[2, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)&quot;</span>
<span class="sd"> &gt;&gt;&gt; Polynome(&#39;3&#39;, details=3)*Polynome(&#39;x&#39;, details=3)</span>
<span class="sd"> Polynome([[3, 1]], &quot;x&quot;, 3)</span>
......@@ -562,7 +562,7 @@
<span class="c"># On commence par réduire la chaîne</span>
<span class="k">return</span> <span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">repr</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">nreduction</span><span class="p">())</span> <span class="k">for</span> <span class="n">other</span> <span class="ow">in</span> <span class="n">lother</span><span class="p">])</span>
<span class="n">lcoeff</span><span class="p">,</span> <span class="n">lexp</span><span class="p">,</span> <span class="n">reduire</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[],</span> <span class="bp">True</span>
<span class="n">lcoeff</span><span class="p">,</span> <span class="n">lexp</span><span class="p">,</span> <span class="n">reduire</span><span class="p">,</span> <span class="n">ordonne</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[],</span> <span class="bp">True</span><span class="p">,</span> <span class="bp">True</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">lother</span><span class="p">)):</span>
<span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_convert_other</span><span class="p">(</span><span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
......@@ -571,14 +571,29 @@
<span class="k">if</span> <span class="n">coeff</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span> <span class="n">lcoeff</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">coeff</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exp</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">lexp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="p">)</span>
<span class="k">if</span> <span class="n">coeff</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">exp</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">reduire</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">lexp</span> <span class="ow">and</span> <span class="n">exp</span> <span class="o">&lt;</span> <span class="n">lexp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span> <span class="n">ordonne</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">lother</span><span class="p">):</span>
<span class="c"># Ce n&#39;est pas un monôme, il va donc falloir utiliser la distributivité</span>
<span class="c"># ou alors la chaine est fini et on calcul</span>
<span class="c"># ou alors la chaine est fini et on calcule</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">lcoeff</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">lexp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="c"># on a multiplié au moins 2 monômes auparavant</span>
<span class="k">if</span> <span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">details</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">reduire</span><span class="p">:</span>
<span class="c"># TODO: cas où un coeff est une str</span>
<span class="c">#=======================================================</span>
<span class="c"># return &quot;*&quot;.join([repr(coeff) for coeff in lcoeff]) + &quot;*&quot; + \</span>
<span class="c"># &quot;*&quot;.join([&quot;Polynome([[1, %s]], &#39;%s&#39;, %s)&quot; % (exp, self.var, self.details) for exp in lexp]) + \</span>
<span class="c"># &quot;*&quot;.join([repr(other.nreduction()) for other in lother[i + 1:]])</span>
<span class="c">#=======================================================</span>
<span class="n">produit</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">lother</span><span class="p">:</span>
<span class="k">if</span> <span class="n">j</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">j</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">produit</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;Polynome([[</span><span class="si">%s</span><span class="s">, 0]], var = </span><span class="se">\&#39;</span><span class="si">%s</span><span class="se">\&#39;</span><span class="s">, details=</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">j</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">details</span><span class="p">),</span> \
<span class="s">&#39;Polynome([[1, </span><span class="si">%s</span><span class="s">]], var = </span><span class="se">\&#39;</span><span class="si">%s</span><span class="se">\&#39;</span><span class="s">, details=</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">j</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">j</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">details</span><span class="p">)]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">produit</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">j</span><span class="p">))</span>
<span class="k">return</span> <span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">produit</span><span class="p">)</span>
<span class="k">if</span> <span class="n">lother</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">details</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">ordonne</span><span class="p">:</span>
<span class="k">return</span> <span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">repr</span><span class="p">(</span><span class="n">coeff</span><span class="p">)</span> <span class="k">for</span> <span class="n">coeff</span> <span class="ow">in</span> <span class="n">lcoeff</span><span class="p">])</span> <span class="o">+</span> <span class="s">&quot;*&quot;</span> <span class="o">+</span> \
<span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&quot;Polynome([[1, </span><span class="si">%s</span><span class="s">]], &#39;</span><span class="si">%s</span><span class="s">&#39;, </span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">exp</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">details</span><span class="p">)</span> <span class="k">for</span> <span class="n">exp</span> <span class="ow">in</span> <span class="n">lexp</span><span class="p">])</span> <span class="o">+</span> \
<span class="s">&quot;*&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">repr</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">nreduction</span><span class="p">())</span> <span class="k">for</span> <span class="n">other</span> <span class="ow">in</span> <span class="n">lother</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">:]])</span>
......@@ -608,6 +623,22 @@
<span class="n">produit</span> <span class="o">=</span> <span class="n">id_rem</span><span class="p">(</span><span class="n">lother</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">lother</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">if</span> <span class="n">produit</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
<span class="c"># Distributivité</span>
<span class="c"># TODO: Convertir (a-b) en (a+(-b)) pour details=3</span>
<span class="c">#===================================================</span>
<span class="c"># if self.details == 3:</span>
<span class="c"># difference, produit = False, []</span>
<span class="c"># for poly in lother:</span>
<span class="c"># if len(poly) &gt; 1:</span>
<span class="c"># for j in range(1, len(poly)):</span>
<span class="c"># if poly[j][0] &lt; 0:</span>
<span class="c"># difference = True</span>
<span class="c"># produit.append(&quot;(&quot; + &quot;+&quot;.join([&#39;Polynome(%s, var = \&#39;%s\&#39;, details=%s)&#39; % (poly[i], poly.var, poly.details) for i in range(len(poly))]) + &quot;)&quot;)</span>
<span class="c"># break</span>
<span class="c"># if not difference: produit.append(repr(poly))</span>
<span class="c"># if difference:</span>
<span class="c"># return &quot;*&quot;.join(produit)</span>
<span class="c">#===================================================</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">details</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">produit</span> <span class="o">=</span> <span class="s">&quot;+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&quot;+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">repr</span><span class="p">(</span><span class="n">Polynome</span><span class="p">([</span><span class="n">premier</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">details</span><span class="p">))</span> <span class="o">+</span> \
<span class="s">&quot;*&quot;</span> <span class="o">+</span> <span class="nb">repr</span><span class="p">(</span><span class="n">Polynome</span><span class="p">([</span><span class="n">second</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">details</span><span class="p">))</span> \
......
......@@ -289,7 +289,7 @@ sinon les produits sont explicités.</p>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;2x+5&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">&#39;Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[2, 1]], &quot;x&quot;, 1)+Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[5, 0]], &quot;x&quot;, 1)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> <span class="o">*</span> <span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;2x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&quot;3*2*Polynome([[1, 1]], &#39;x&#39;, 3)*Polynome([[1, 1]], &#39;x&#39;, 3)&quot;</span>
<span class="go">&quot;Polynome([[3, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)*Polynome([[2, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="go">Polynome([[3, 1]], &quot;x&quot;, 3)</span>
</pre></div>
......@@ -913,7 +913,7 @@ sinon les produits sont explicités.</p>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;2x+5&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">&#39;Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[2, 1]], &quot;x&quot;, 1)+Polynome([[3, 1]], &quot;x&quot;, 1)*Polynome([[5, 0]], &quot;x&quot;, 1)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> <span class="o">*</span> <span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;2x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&quot;3*2*Polynome([[1, 1]], &#39;x&#39;, 3)*Polynome([[1, 1]], &#39;x&#39;, 3)&quot;</span>
<span class="go">&quot;Polynome([[3, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)*Polynome([[2, 0]], var = &#39;x&#39;, details=3)*Polynome([[1, 1]], var = &#39;x&#39;, details=3)&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;3&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="n">Polynome</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="go">Polynome([[3, 1]], &quot;x&quot;, 3)</span>
</pre></div>
......
......@@ -480,7 +480,7 @@ class Polynome():
>>> Polynome('3x', details=1)*Polynome('2x+5', details=1)
'Polynome([[3, 1]], "x", 1)*Polynome([[2, 1]], "x", 1)+Polynome([[3, 1]], "x", 1)*Polynome([[5, 0]], "x", 1)'
>>> Polynome('3x', details=3) * Polynome('2x', details=3)
"3*2*Polynome([[1, 1]], 'x', 3)*Polynome([[1, 1]], 'x', 3)"
"Polynome([[3, 0]], var = 'x', details=3)*Polynome([[1, 1]], var = 'x', details=3)*Polynome([[2, 0]], var = 'x', details=3)*Polynome([[1, 1]], var = 'x', details=3)"
>>> Polynome('3', details=3)*Polynome('x', details=3)
Polynome([[3, 1]], "x", 3)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment