You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Different functions will have different edge cases. Often, you need not test for cases that are outside the valid range, unless you want to test that the function fails. In the <code>fib()</code> function negative and noninteger values are not valid inputs. You do not need to have tests for these classes of numbers, unless you want to make sure that the function fails as expected, which is actually quite a good idea. Edge cases are not where the story ends, though, as we will see next.</p>
83
+
<p>Different functions will have different edge cases. Often, you need not test for cases that are outside the valid range, unless you want to test that the function fails. In the <code>fib()</code> function negative and noninteger values are not valid inputs. Tests for these classes of numbers serve you well if you want to make sure that the function fails as expected. Indeed, we learned in the assertions section that this is actually quite a good idea.</p>
84
+
<sectionclass="challenge panel panel-success">
85
+
<divclass="panel-heading">
86
+
<h2><spanclass="glyphicon glyphicon-pencil"></span>Test for Graceful Failure</h2>
87
+
</div>
88
+
<divclass="panel-body">
89
+
<p>The <code>fib()</code> function should probably return the Python built-in <code>NotImplemented</code> value for negative and noninteger values.</p>
90
+
<olstyle="list-style-type: decimal">
91
+
<li>Create a file called <code>test_fib.py</code></li>
92
+
<li>Copy the three tests above into that file.</li>
93
+
<li>Write <strong>two new</strong> tests that check for the expected return value (NotImplemented) in each case (for negative input and noninteger input respectively).</li>
94
+
</ol>
95
+
</div>
96
+
</section>
97
+
<p>Edge cases are not where the story ends, though, as we will see next.</p>
84
98
<h2id="corner-cases">Corner Cases</h2>
85
99
<p>When two or more edge cases are combined, it is called a <em>corner case</em>. If a function is parametrized by two linear and independent variables, a test that is at the extreme of both variables is in a corner. As a demonstration, consider the case of the function <code>(sin(x) / x) * (sin(y) / y)</code>, presented here:</p>
0 commit comments