Lab 04: A Debugging Mystery

Prerequisites to running the code.

Instructions: https://fa22.datastructur.es/materials/lab/lab04/

Solutions:

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()

Last updated