| Summary: | Function - isIdentical() return true even though puzzleState is not identical | ||
|---|---|---|---|
| Product: | River-Crossing-Puzzle-Solver | Reporter: | tsunychau2-c |
| Component: | Logic | Assignee: | tsunychau2-c |
| Status: | RESOLVED FIXED | ||
| Severity: | enhancement | ||
| Priority: | --- | ||
| Version: | v0.9.5 | ||
| Hardware: | PC | ||
| OS: | Mac OS | ||
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;
}
|
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