đź’ż
CS61B Fall 2022
  • CS61B Fall 2022
  • Prerequisites to running the assignments.
  • Lab 01: Setting up your computer
  • Lab 02: JUnit Tests and Debugging
  • Project 0: 2048
  • Lab 03: Timing Tests and Randomized Comparison Tests
  • Lab 04: A Debugging Mystery
  • Project 1: Deques
  • HW 2: Percolation
  • Lab 07: BSTMap
  • Project 2a: NGordNet (NGrams)
  • Lab 08: HashMap
  • Project 2b: NGordNet (WordNet)
  • Lab 11: BYOW Introduction
  • Project 3 BYOW
    • Phase 1: World Generation
Powered by GitBook
On this page
  • GIT exercise
  • A Debugging Mystery

Lab 04: A Debugging Mystery

PreviousLab 03: Timing Tests and Randomized Comparison TestsNextProject 1: Deques

Last updated 2 years ago

to running the code.

Instructions:

Solutions:

  • GIT exercise:

  • A Debug Mystery:

This lab is fairly straightforward, aims at practicing GIT & Debugging.

GIT exercise

  1. In the first part, we pulled a buggy version of lab01/Collatz.

  2. Commited the buggy version.

  3. Checked out the file from the commit in lab01, to revert its state to its pre-buggy version.

A Debugging Mystery

Your company, Flik Enterprises, has released a fine software library called Flik.java that is able to determine whether two Integers are the same or not.

You receive an email from someone named “Horrible Steve” who describes a problem they’re having with your library:

"Dear Flik Enterprises,

Your library is very bad. See the attached code. It should print out 500
but actually it's printing out 128.

(attachment: HorribleSteve.java)"

Figure out whether the bug is in Horrible Steve’s code or in Flik enterprise’s library.

Solution:

After writing and running some tests, I found out that unfortunately, the bug was indeed in Flik enterprise's library. :))

Original:

public static boolean isSameNumber(Integer a, Integer b) {
    return a == b;
}

Test Suite:

public class FlikTest {
    @Test
    public void testIsSameNumber() {
        assertTrue(Flik.isSameNumber(4, 4));
        assertTrue(Flik.isSameNumber(128, 128));

        assertFalse(Flik.isSameNumber(5, 4));
    }
}

Solution:

public static boolean isSameNumber(Integer a, Integer b) {
    return a.equals(b);
}

Reasoning - to check object equality, you need to use equals()

Prerequisites
https://fa22.datastructur.es/materials/lab/lab04/
https://github.com/tomthestrom/cs61b/blob/master/lab01/Collatz.java
https://github.com/tomthestrom/cs61b/blob/master/lab04/flik/Flik.java