Bug 355 - Improper return values when comparing ChainBase with different lengths
Summary: Improper return values when comparing ChainBase with different lengths
Status: RESOLVED FIXED
Alias: None
Product: Group 8 (2019)
Classification: Unclassified
Component: PokerHand (show other bugs)
Version: Version1.0
Hardware: PC Windows
: --- critical
Assignee: SYR
URL:
Depends on:
Blocks:
 
Reported: 2019-12-05 15:03 HKT by ZLQ
Modified: 2019-12-05 15:09 HKT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ZLQ 2019-12-05 15:03:26 HKT
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.
Comment 1 SYR 2019-12-05 15:09:01 HKT
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.