Way to Reproduce: 1. Create two unequal PuzzleState PuzzleState A: ArrayList<String> TlandA = new ArrayList<String>(Arrays.asList("tiger", "grass")); ArrayList<String> TlandB = new ArrayList<String>(Arrays.asList("farmer", "sheep")); PuzzleState tps = new PuzzleState(TlandA,TlandB,1); PuzzleState B: ArrayList<String> ClandA = new ArrayList<String>(Arrays.asList("tiger", "grass","cow")); ArrayList<String> ClandB = new ArrayList<String>(Arrays.asList("farmer", "sheep")); PuzzleState cps = new PuzzleState(ClandA,ClandB,1); 2. Get the return value of function isIdentical() i.e. boolean result = tps.isIdentical(cps); Actual Result: True Expect Result: False
Bug is confirmed
The original code inside isIdentical() does not consider the size of two puzzleState. public boolean isIdentical(PuzzleState state) { if(!this.landA.containsAll(state.landA)) return false; if(!this.landB.containsAll(state.landB)) return false; return true; } Modification of code: public boolean isIdentical(PuzzleState state) { if(this.landA.size() != state.landA.size()) return false; if(this.landB.size() != state.landB.size()) return false; if(!this.landA.containsAll(state.landA)) return false; if(!this.landB.containsAll(state.landB)) return false; return true; }