| Summary: | Improper return values when comparing ChainBase with different lengths | ||
|---|---|---|---|
| Product: | Group 8 (2019) | Reporter: | ZLQ <leqizheng2-c> |
| Component: | PokerHand | Assignee: | SYR <yuransun2-c> |
| Status: | RESOLVED FIXED | ||
| Severity: | critical | CC: | leqizheng2-c, yujiaxu4-c |
| Priority: | --- | ||
| Version: | Version1.0 | ||
| Hardware: | PC | ||
| OS: | Windows | ||
In the original implementation, we just check whether they are the same class instances and compare their first chainable. Therefore, the comparison between chains with different lengths will return 1/0/-1 in the previous version. We have added the length judge codes in ChainBase.java, and the bug has been resolved now. |
Steps to Reproduce: 1. Create a Chain instance as below: List<Card> cards1 = new ArrayList<Card>(); cards1.add(new Card(CardSuit.DIAMOND,CardRank.C4)); cards1.add(new Card(CardSuit.HEART,CardRank.C5)); cards1.add(new Card(CardSuit.SPADE,CardRank.C6)); cards1.add(new Card(CardSuit.CLUB,CardRank.C7)); cards1.add(new Card(CardSuit.CLUB,CardRank.C8)); cards1.add(new Card(CardSuit.SPADE,CardRank.C9)); cards1.add(new Card(CardSuit.CLUB,CardRank.C10)); Chain chain = new Chain(cards1); 2. Create another Chain instance as below: List<Card> cards2 = new ArrayList<Card>(); cards2.add(new Card(CardSuit.CLUB,CardRank.C3)); cards2.add(new Card(CardSuit.CLUB,CardRank.C4)); cards2.add(new Card(CardSuit.CLUB,CardRank.C5)); cards2.add(new Card(CardSuit.DIAMOND,CardRank.C6)); cards2.add(new Card(CardSuit.HEART,CardRank.C7)); Chain other = new Chain(cards2); 3. Invoke chain.compareTo(other); Expected Result: -2, they cannot do the comparison as they have different lengths. Actual Result: 1 More Information: Add length checking in the compareTo functions in ChainBase class.