<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Reading_8_Objectives" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Reading 8 Objectives</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc" data-has-score="False" data-runtime-version="1" data-block-type="video" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_814d0febedfc"
class="video closed"
data-metadata='{"ytTestTimeout": 1500, "autohideHtml5": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V004800_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V004800/MIT600512016-V004800.m3u8"], "end": 0.0, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/xmodule_handler/save_user_state", "speed": null, "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/transcript/available_translations", "completionEnabled": false, "transcriptLanguage": "en", "streams": "1.00:Q2BhnuUN6K4", "captionDataDir": null, "ytApiUrl": "https://www.youtube.com/iframe_api", "lmsRootURL": "https://openlearninglibrary.mit.edu", "showCaptions": "true", "ytMetadataEndpoint": "", "autoplay": false, "recordedYoutubeIsAvailable": true, "savedVideoPosition": 0.0, "transcriptLanguages": {"en": "English"}, "poster": null, "autoAdvance": false, "prioritizeHls": false, "start": 0.0, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/transcript/translation/__lang__", "completionPercentage": 0.95, "duration": 15.57, "saveStateEnabled": false, "publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/publish_completion"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_814d0febedfc"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_814d0febedfc">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_814d0febedfc">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_814d0febedfc/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_f5ca859f83b8">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_f5ca859f83b8" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h4>Software in 6.005</h4>
<table class="table table-striped no-markdown">
<tbody>
<tr>
<th width="33%">Safe from bugs</th>
<th>Easy to understand</th>
<th>Ready for change</th>
</tr>
<tr>
<td>
Correct today and correct in the unknown future
</td>
<td>
Communicating clearly with future programmers, including future you
</td>
<td>
Designed to accommodate change without rewriting
</td>
</tr>
</tbody>
</table>
<h4>Objectives for Today</h4>
<p>The topic of today's reading is systematic debugging.</p>
<p>After today’s reading, you should:</p>
<ul>
<li>Be able to reduce a bug report to a small, repeatable test case</li>
<li>Understand how to use the scientific method to localize and understand a bug</li>
</ul>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Systematic_Debugging" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Systematic Debugging</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc" data-has-score="False" data-runtime-version="1" data-block-type="video" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_cd892aac57cc"
class="video closed"
data-metadata='{"ytTestTimeout": 1500, "autohideHtml5": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V005100_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V005100/MIT600512016-V005100.m3u8"], "end": 0.0, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/xmodule_handler/save_user_state", "speed": null, "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/transcript/available_translations", "completionEnabled": false, "transcriptLanguage": "en", "streams": "1.00:2POD7hX6fHg", "captionDataDir": null, "ytApiUrl": "https://www.youtube.com/iframe_api", "lmsRootURL": "https://openlearninglibrary.mit.edu", "showCaptions": "true", "ytMetadataEndpoint": "", "autoplay": false, "recordedYoutubeIsAvailable": true, "savedVideoPosition": 0.0, "transcriptLanguages": {"en": "English"}, "poster": null, "autoAdvance": false, "prioritizeHls": false, "start": 0.0, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/transcript/translation/__lang__", "completionPercentage": 0.95, "duration": 263.73, "saveStateEnabled": false, "publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/publish_completion"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_cd892aac57cc"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_cd892aac57cc">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_cd892aac57cc">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cd892aac57cc/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_0315c1d14c3a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_0315c1d14c3a" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="systematic_debugging">Systematic Debugging</h2>
<p>Sometimes you have no choice but to debug — particularly when the bug is found only when you plug the whole system together, or when it is reported by a user after the system is deployed, in which case it may be hard to localize it to a particular module. For those situations, we can suggest a systematic strategy for more effective debugging.</p>
<h2 id="reproduce_the_bug">Reproduce the Bug</h2>
<div data-outline="reproduce_the_bug">
<p>Start by finding a small, repeatable test case that produces the failure. If the bug was found by regression testing, then you're in luck; you already have a failing test case in your test suite. If the bug was reported by a user, it may take some effort to reproduce the bug. For graphical user interfaces and multithreaded programs, a bug may be hard to reproduce consistently if it depends on timing of events or thread execution.</p>
<p>Nevertheless, any effort you put into making the test case small and repeatable will pay off, because you'll have to run it over and over while you search for the bug and develop a fix for it. Furthermore, after you've successfully fixed the bug, you'll want to add the test case to your regression test suite, so that the bug never crops up again. Once you have a test case for the bug, making this test work becomes your goal.</p>
<p>Here's an example. Suppose you have written this function:</p><pre><code class="language-java hljs"><span class="hljs-comment handout-javadoc-comment">/**
* Find the most common word in a string.
* <span class="hljs-doctag">@param</span> text string containing zero or more words, where a word
* is a string of alphanumeric characters bounded by nonalphanumerics.
* <span class="hljs-doctag">@return</span> a word that occurs maximally often in text, ignoring alphabetic case.
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">mostCommonWord</span><span class="hljs-params">(String text)</span> </span>{
...
}</code></pre>
<p>A user passes the whole text of Shakespeare's plays into your method, something like <code>mostCommonWord(allShakespearesPlaysConcatenated)</code>, and discovers that instead of returning a predictably common English word like <code>"the"</code> or <code>"a"</code>, the method returns something unexpected, perhaps <code>"e"</code>.</p>
<p>Shakespeare's plays have 100,000 lines containing over 800,000 words, so this input would be very painful to debug by normal methods, like print-debugging and breakpoint-debugging. Debugging will be easier if you first work on reducing the size of the buggy input to something manageable that still exhibits the same (or very similar) bug:</p>
<ul>
<li>does the first half of Shakespeare show the same bug? (Binary search! Always a good technique. More about this below.)</li>
<li>does a single play have the same bug?</li>
<li>does a single speech have the same bug?</li>
</ul>
<p>Once you've found a small test case, find and fix the bug using that smaller test case, and then go back to the original buggy input and confirm that you fixed the same bug.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_1bd300ed4677" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case" data-has-score="True" data-runtime-version="1" data-block-type="problem" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_08-reducing-bug-to-test-case" class="problems-wrapper" role="group"
aria-labelledby="08-reducing-bug-to-test-case-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="08-reducing-bug-to-test-case-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case-problem-progress" tabindex="-1">
reducing a bug to a test case
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-reducing-bug-to-test-case-problem-progress"></div>
<div class="problem">
<div>
<p>Suppose a user reports that <code>mostCommonWord("chicken chicken chicken beef")</code> returns <code>"beef"</code> instead of <code>"chicken"</code>.</p>
<p>To shorten and simplify this input before you start debugging, which of the following inputs are worth trying? Check all that apply. Give all answers that make sense, not just the simplest one (because the simplest one sometimes no longer exhibits the bug!)</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_08-reducing-bug-to-test-case_2_1">
<fieldset aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<div class="field">
<input type="checkbox" name="input_08-reducing-bug-to-test-case_2_1[]" id="input_08-reducing-bug-to-test-case_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="08-reducing-bug-to-test-case_2_1-choice_0-label" for="input_08-reducing-bug-to-test-case_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<code>mostCommonWord("chicken chicken beef")</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-reducing-bug-to-test-case_2_1[]" id="input_08-reducing-bug-to-test-case_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="08-reducing-bug-to-test-case_2_1-choice_1-label" for="input_08-reducing-bug-to-test-case_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<code>mostCommonWord("Chicken Chicken Chicken beef")</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-reducing-bug-to-test-case_2_1[]" id="input_08-reducing-bug-to-test-case_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="08-reducing-bug-to-test-case_2_1-choice_2-label" for="input_08-reducing-bug-to-test-case_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<code>mostCommonWord("chicken beef")</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-reducing-bug-to-test-case_2_1[]" id="input_08-reducing-bug-to-test-case_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="08-reducing-bug-to-test-case_2_1-choice_3-label" for="input_08-reducing-bug-to-test-case_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<code>mostCommonWord("a b c")</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-reducing-bug-to-test-case_2_1[]" id="input_08-reducing-bug-to-test-case_2_1_choice_4" class="field-input input-checkbox" value="choice_4"/><label id="08-reducing-bug-to-test-case_2_1-choice_4-label" for="input_08-reducing-bug-to-test-case_2_1_choice_4" class="response-label field-label label-inline" aria-describedby="status_08-reducing-bug-to-test-case_2_1">
<code>mostCommonWord("b b c")</code>
</label>
</div>
<span id="answer_08-reducing-bug-to-test-case_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_08-reducing-bug-to-test-case_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_08-reducing-bug-to-test-case_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="reducing a bug to a test case" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_08-reducing-bug-to-test-case" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_08-reducing-bug-to-test-case">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-reducing-bug-to-test-case-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-reducing-bug-to-test-case-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-reducing-bug-to-test-case-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
<div class="vert vert-2" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing" data-has-score="True" data-runtime-version="1" data-block-type="problem" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_08-regression-testing" class="problems-wrapper" role="group"
aria-labelledby="08-regression-testing-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="08-regression-testing-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing-problem-progress" tabindex="-1">
regression testing
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-regression-testing-problem-progress"></div>
<div class="problem">
<div>
<p>Suppose you reduce the <code>"chicken chicken chicken beef"</code> input down to "c c b", which also has a problem. You find a bug, fix it, and observe that both <code>"c c b"</code> and <code>"chicken chicken chicken beef"</code> are now returning the right answer.</p>
<p>Which test cases should you now add to your test suite? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_08-regression-testing_2_1">
<fieldset aria-describedby="status_08-regression-testing_2_1">
<div class="field">
<input type="checkbox" name="input_08-regression-testing_2_1[]" id="input_08-regression-testing_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="08-regression-testing_2_1-choice_0-label" for="input_08-regression-testing_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_08-regression-testing_2_1">
<code>assertEquals("chicken", mostCommonWord("chicken chicken chicken beef"))</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-regression-testing_2_1[]" id="input_08-regression-testing_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="08-regression-testing_2_1-choice_1-label" for="input_08-regression-testing_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_08-regression-testing_2_1">
<code>assertEquals("c", mostCommonWord("c c b"))</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-regression-testing_2_1[]" id="input_08-regression-testing_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="08-regression-testing_2_1-choice_2-label" for="input_08-regression-testing_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_08-regression-testing_2_1">
<code>assertEquals("c", mostCommonWord("c b"))</code>
</label>
</div>
<div class="field">
<input type="checkbox" name="input_08-regression-testing_2_1[]" id="input_08-regression-testing_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="08-regression-testing_2_1-choice_3-label" for="input_08-regression-testing_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_08-regression-testing_2_1"> you shouldn&#8217;t change the test suite, because you haven&#8217;t changed the spec
</label>
</div>
<span id="answer_08-regression-testing_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_08-regression-testing_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_08-regression-testing_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="regression testing" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_08-regression-testing" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_08-regression-testing">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-regression-testing-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-regression-testing-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-regression-testing-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Understand_the_Location_and_Cause_of_the_Bug" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Understand the Location and Cause of the Bug</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1" data-has-score="False" data-runtime-version="1" data-block-type="video" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_cf095c108cf1"
class="video closed"
data-metadata='{"ytTestTimeout": 1500, "autohideHtml5": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V004500_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V004500/MIT600512016-V004500.m3u8"], "end": 0.0, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/xmodule_handler/save_user_state", "speed": null, "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/transcript/available_translations", "completionEnabled": false, "transcriptLanguage": "en", "streams": "1.00:x3-BCzIcWAk", "captionDataDir": null, "ytApiUrl": "https://www.youtube.com/iframe_api", "lmsRootURL": "https://openlearninglibrary.mit.edu", "showCaptions": "true", "ytMetadataEndpoint": "", "autoplay": false, "recordedYoutubeIsAvailable": true, "savedVideoPosition": 0.0, "transcriptLanguages": {"en": "English"}, "poster": null, "autoAdvance": false, "prioritizeHls": false, "start": 0.0, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/transcript/translation/__lang__", "completionPercentage": 0.95, "duration": 693.6, "saveStateEnabled": false, "publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/publish_completion"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_cf095c108cf1"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_cf095c108cf1">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_cf095c108cf1">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_cf095c108cf1/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_c9742d591a5a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_c9742d591a5a" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="understand_the_location_and_cause_of_the_bug">Understand the Location and Cause of the Bug</h2>
<div data-outline="understand_the_location_and_cause_of_the_bug">
<p>To localize the bug and its cause, you can use the scientific method:</p>
<ol>
<li>
<p><strong>Study the data.</strong> Look at the test input that causes the bug and the incorrect results, failed assertions, and stack traces that result from it.</p>
</li>
<li>
<p><strong>Hypothesize.</strong> Propose a hypothesis, consistent with all the data, about where the bug might be or where it <em>cannot</em> be. It's good to make this hypothesis general at first.</p>
</li>
<li>
<p><strong>Experiment.</strong> Devise an experiment that tests your hypothesis. It's good to make the experiment an <em>observation</em> at first — a probe that collects information but disturbs the system as little as possible.</p>
</li>
<li>
<p><strong>Repeat.</strong> Add the data you collected from your experiment to what you knew before and make a fresh hypothesis. Hopefully you have ruled out some possibilities and narrowed the set of possible locations and reasons for the bug.</p>
</li>
</ol>
<p>Let's look at these steps in the context of the <code>mostCommonWord()</code> example, fleshed out a little more with three helper methods:</p><pre><code class="language-java hljs"><span class="hljs-comment handout-javadoc-comment">/**
* Find the most common word in a string.
* <span class="hljs-doctag">@param</span> text string containing zero or more words,
* where a word is a string of alphanumeric
* characters bounded by nonalphanumerics.
* <span class="hljs-doctag">@return</span> a word that occurs maximally often in text,
* ignoring alphabetic case.
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">mostCommonWord</span><span class="hljs-params">(String text)</span> </span>{
... words = splitIntoWords(text); ...
... frequencies = countOccurrences(words); ...
... winner = findMostCommon(frequencies); ...
... <span class="hljs-keyword">return</span> winner;
}
<span class="hljs-comment handout-javadoc-comment">/** Split a string into words ... */</span>
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> List<String> <span class="hljs-title">splitIntoWords</span><span class="hljs-params">(String text)</span> </span>{
...
}
<span class="hljs-comment handout-javadoc-comment">/** Count how many times each word appears ... */</span>
<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Map<String,Integer> countOccurrences(List<String> words) {
...
}
<span class="hljs-comment handout-javadoc-comment">/** Find the word with the highest frequency count ... */</span>
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">findMostCommon</span><span class="hljs-params">(Map<String,Integer> frequencies)</span> </span>{
...
}</code></pre>
<h3 id="1_study_the_data">1. Study the Data</h3>
<div data-outline="1_study_the_data">
<p>One important form of data is the stack trace from an exception. Practice reading the stack traces that you get because they will give you enormous amounts of information about where and what the bug might be.</p>
<p>The process of isolating a small test case may also give you data that you didn't have before. You may even have two related test cases that <em>bracket</em> the bug in the sense that one succeeds and one fails. For example, maybe <code>mostCommonWords("c c, b")</code> is broken, but <code>mostCommonWords("c c b")</code> is fine.</p>
</div>
<h3 id="2_hypothesize">2. Hypothesize</h3>
<div data-outline="2_hypothesize">
<div class="panel panel-figure pull-right pull-margin"><img src="/assets/courseware/v1/71e385fdcd5bc3939e4c5ab862e727c2/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/08-dataflow.png" alt="data flowing through the modules of the program" width="400"></div>
<p>It helps to think about your program as modules, or steps in an algorithm, and try to rule out whole sections of the program at once.</p>
<p>The flow of data in <code>mostCommonWord()</code> is shown at right. If the symptom of the bug is an exception in <code>countOccurrences()</code>, then you can rule out everything downstream, specifically <code>findMostFrequent()</code>.</p>
<p>Then you would choose a hypothesis that tries to localize the bug even further. You might hypothesize that the bug is in <code>splitIntoWords()</code>, corrupting its results, which then cause the exception in <code>countOccurrences()</code>. You would then use an experiment to test that hypothesis. If the hypothesis is true, then you would have ruled out <code>countOccurrences()</code> as the source of the problem. If it's false, then you would rule out <code>splitIntoWords()</code>.</p>
</div>
<h3 id="3_experiment">3. Experiment</h3>
<div data-outline="3_experiment">
<p>A good experiment is a gentle observation of the system without disturbing it much. It might be:</p>
<ul>
<li>
<p>Run a <strong>different test case.</strong> The test case reduction process discussed above used test cases as experiments.</p>
</li>
<li>
<p>Insert a <strong>print statement</strong> or <strong>assertion</strong> in the running program to check something about its internal state.</p>
</li>
<li>
<p>Set a <strong>breakpoint</strong> using a debugger and then single-step through the code and look at variable and object values.</p>
</li>
</ul>
<p>It's tempting to try to insert <em>fixes</em> to the hypothesized bug, instead of mere probes. This is almost always the wrong thing to do. First, it leads to a kind of ad-hoc guess-and-test programming, which produces awful, complex, hard-to-understand code. Second, your fixes may just mask the true bug without actually removing it.</p>
<p>For example, if you're getting an <code>ArrayOutOfBoundsException</code>, try to understand what's going on first. Don't just add code that avoids or catches the exception without fixing the real problem.</p>
</div>
<h3 id="other_tips">Other tips</h3>
<div data-outline="other_tips">
<p><strong>Bug localization by binary search</strong>. Debugging is a search process, and you can sometimes use binary search to speed up the process. For example, in <code>mostCommonWords</code>, the data flows through three helper methods. To do a binary search, you would divide this workflow in half, perhaps guessing that the bug is found somewhere between the first helper method call and the second and you would insert probes (like breakpoints, print statements, or assertions) there to check the results. From the answer to that experiment, you would further divide in half.</p>
<p><strong>Prioritize your hypotheses</strong>. When making your hypothesis, you may want to keep in mind that different parts of the system have different likelihoods of failure. For example, old, well-tested code is probably more trustworthy than recently-added code. Java library code is probably more trustworthy than yours. The Java compiler and runtime, operating system platform, and hardware are increasingly more trustworthy because they are more tried and tested. You should trust these lower levels until you've found good reason not to.</p>
<p><strong>Swap components</strong>. If you have another implementation of a module that satisfies the same interface, and you suspect the module, then one experiment you can do is to try swapping in the alternative. For example, if you suspect your binarySearch() implementation, then substitute a simpler linearSearch() instead. If you suspect java.util.ArrayList, you could swap in java.util.LinkedList instead. If you suspect the Java runtime, run with a different version of Java. If you suspect the operating system, run your program on a different OS. If you suspect the hardware, run on a different machine. You can waste a lot of time swapping unfailing components, however, so don't do this unless you have good reason to suspect a component.</p>
<p><strong>Make sure your source code and object code are up to date.</strong> Pull the latest version from the repository, and delete all your binary files and recompile everything (in Eclipse, this is done by Project → Clean).</p>
<p><strong>Get help.</strong> It often helps to explain your problem to someone else even if the person you're talking to has no idea what you're talking about. Lab assistants and fellow 6.005 students usually do know what you're talking about, so they're even better.</p>
<p><strong>Sleep on it.</strong> If you're too tired, you won't be an effective debugger. Trade latency for efficiency.</p>
</div>
</div>
<h2 id="fix_the_bug">Fix the Bug</h2>
<div data-outline="fix_the_bug">
<p>Once you've found the bug and understand its cause, the third step is to devise a fix for it. Avoid the temptation to slap a patch on it and move on. Ask yourself whether the bug was a coding error, like a misspelled variable or interchanged method parameters, or a design error, like an underspecified or insufficient interface. Design errors may suggest that you step back and revisit your design, or at the very least consider all the other clients of the failing interface to see if they suffer from the bug too.</p>
<p>Think also whether the bug has any relatives. If I just found a divide-by-zero error here, did I do that anywhere else in the code? Try to make the code safe from future bugs like this. Also consider what effects your fix will have. Will it break any other code?</p>
<p>Finally, after you have applied your fix, add the bug's test case to your regression test suite and run all the tests to assure yourself that (a) the bug is fixed, and (b) no new bugs have been introduced.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_e0066f82326e" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48" data-has-score="True" data-runtime-version="1" data-block-type="problem" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_08-debugging-strategy-48" class="problems-wrapper" role="group"
aria-labelledby="08-debugging-strategy-48-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="5"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="08-debugging-strategy-48-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48-problem-progress" tabindex="-1">
debugging strategy
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@08-debugging-strategy-48-problem-progress"></div>
<div class="problem">
<div>
<p>Suppose you are debugging the quadraticRoots function, which appears to be producing wrong answers sometimes.</p>
<pre class="code">
/**
* Solves quadratic equation ax^2 + bx + c = 0.
*
* @param a quadratic coefficient, requires a != 0
* @param b linear coefficient
* @param c constant term
* @return a list of the real roots of the equation
*/
public static List&lt;Double&gt; quadraticRoots(int a, int b, int c) { ... }
</pre>
<p>Put the following items in the order that you should try them: 1, 2, 3, ... Say "wat" for items that are nonsense statements.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="inputtype option-input ">
<label class="problem-group-label" for="input_08-debugging-strategy-48_2_1" id="label_08-debugging-strategy-48_2_1">Change your code from using ArrayList to using LinkedList.</label>
<select name="input_08-debugging-strategy-48_2_1" id="input_08-debugging-strategy-48_2_1" aria-describedby="status_08-debugging-strategy-48_2_1">
<option value="option_08-debugging-strategy-48_2_1_dummy_default">Select an option</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="wat"> wat</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_08-debugging-strategy-48_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_08-debugging-strategy-48_2_1"/>
</div></div>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 2" role="group"><div class="inputtype option-input ">
<label class="problem-group-label" for="input_08-debugging-strategy-48_3_1" id="label_08-debugging-strategy-48_3_1">Put println() statements throughout your method to display the intermediate values of the calculation.</label>
<select name="input_08-debugging-strategy-48_3_1" id="input_08-debugging-strategy-48_3_1" aria-describedby="status_08-debugging-strategy-48_3_1">
<option value="option_08-debugging-strategy-48_3_1_dummy_default">Select an option</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="wat"> wat</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_08-debugging-strategy-48_3_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_08-debugging-strategy-48_3_1"/>
</div></div>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 3" role="group"><div class="inputtype option-input ">
<label class="problem-group-label" for="input_08-debugging-strategy-48_4_1" id="label_08-debugging-strategy-48_4_1">Write a test case that causes the bug to happen.</label>
<select name="input_08-debugging-strategy-48_4_1" id="input_08-debugging-strategy-48_4_1" aria-describedby="status_08-debugging-strategy-48_4_1">
<option value="option_08-debugging-strategy-48_4_1_dummy_default">Select an option</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="wat"> wat</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_08-debugging-strategy-48_4_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_08-debugging-strategy-48_4_1"/>
</div></div>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 4" role="group"><div class="inputtype option-input ">
<label class="problem-group-label" for="input_08-debugging-strategy-48_5_1" id="label_08-debugging-strategy-48_5_1">Run a code coverage tool to see if there are lines that your tests aren't reaching.</label>
<select name="input_08-debugging-strategy-48_5_1" id="input_08-debugging-strategy-48_5_1" aria-describedby="status_08-debugging-strategy-48_5_1">
<option value="option_08-debugging-strategy-48_5_1_dummy_default">Select an option</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="wat"> wat</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_08-debugging-strategy-48_5_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_08-debugging-strategy-48_5_1"/>
</div></div>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 5" role="group"><div class="inputtype option-input ">
<label class="problem-group-label" for="input_08-debugging-strategy-48_6_1" id="label_08-debugging-strategy-48_6_1">Switch from Java 8 back to Java 7.</label>
<select name="input_08-debugging-strategy-48_6_1" id="input_08-debugging-strategy-48_6_1" aria-describedby="status_08-debugging-strategy-48_6_1">
<option value="option_08-debugging-strategy-48_6_1_dummy_default">Select an option</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="wat"> wat</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_08-debugging-strategy-48_6_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_08-debugging-strategy-48_6_1"/>
</div></div>
<div class="solution-span">
<span id="solution_08-debugging-strategy-48_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="debugging strategy" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_08-debugging-strategy-48" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_08-debugging-strategy-48">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-debugging-strategy-48-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-debugging-strategy-48-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="08-debugging-strategy-48-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Reading_8_Summary" data-has-score="False" data-runtime-version="1" data-block-type="vertical" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<h2 class="hd hd-2 unit-title">Reading 8 Summary</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_8352a9b95119">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_8352a9b95119" data-has-score="False" data-runtime-version="1" data-block-type="html" data-request-token="0edb03a4ed0e11eeb41c1299a322540b" data-graded="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h3 id="summary">Summary</h3>
<div data-outline="summary">
<p>In this reading, we looked at how to debug systematically:</p>
<ul>
<li>reproduce the bug as a test case and put it in your regression suite</li>
<li>find the bug using the scientific method</li>
<li>fix the bug thoughtfully, not slapdash</li>
</ul>
<p>Thinking about our three main measures of code quality, systematic debugging is essentially about <b>safety from bugs</b>: we're trying to get rid of a bug, while using regression testing to keep it from coming back.<p>
</div>
<div class="license">This reading was collaboratively authored with contributions from: Saman Amarasinghe, Adam Chlipala, Srini Devadas, Michael Ernst, Max Goldman, John Guttag, Daniel Jackson, Rob Miller, Martin Rinard, and Armando Solar-Lezama. This work is licensed under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.</div>
</div>
</div>
</div>
</div>