[General boards] [Winter 2019 courses] [Fall 2018 courses] [Summer 2018 courses] [Older or newer terms]

Testing


#1

one of my tests is like this in Fishtest class:

@Test
public void testBubbleCreated() {

    fish.setLocation(2, 10);

    fish.blowBubble();

    assertTrue(FishTank.getEntity(2, 10) instanceof Bubble);
}

it passes like expected because there is nothing at (2, 10) originally but

protected void blowBubble() {
Bubble b = new Bubble();
b.setLocation(x, y);
System.out.println(x + " " + y);

        if (FishTank.getEntity(x, y) == null || FishTank.getEntity(x, y) instanceof Bubble) {
            FishTank.addEntity(x, y, b);
        }

}

my blowbuuble is like that^. If I only reverse the coordinates in (b.setlocation) then it will still pass because of the other lines when its not supposed to. So when your testing can I assume you would reverse the coordinates on all lines or?


#2

I don’t really understand the question, could you elaborate on


#3

can I assume you would do:

Bubble b = new Bubble();
b.setLocation(y, x);
System.out.println(x + " " + y);

        if (FishTank.getEntity(y, x) == null || FishTank.getEntity(y, x) instanceof Bubble) {
            FishTank.addEntity(y, x, b);
        }

and not just flip the coordinates on b.setlocation(y, x)?


#4

Our tests will use (x, y) always – that’s the semantics of setLocation (its parameter names are x, y), similarly, addEntity’s parameter names are (x, y)


#5

yes but when you replace our code with a buggy implementation


#6

There are no guarantees about the buggy implementation, except for it will do “unreasonable” things that should obviously be bugs