@Test public void compare() { List<TestCase> testCases = new ArrayList<>( List.of( new TestCase( "Same suit, desired, no trump - A > J", Suit.HEARTS, ValuedCard.fromCard(stringToCard("Ah"), false), ValuedCard.fromCard(stringToCard("Jh"), false), true), new TestCase( "Same suit, desired, no trump - J < A", Suit.HEARTS, ValuedCard.fromCard(stringToCard("Jh"), false), ValuedCard.fromCard(stringToCard("Ah"), false), false), new TestCase( "Same suit, non-desired, no trump - T > 9", Suit.SPADES, ValuedCard.fromCard(stringToCard("Tc"), false), ValuedCard.fromCard(stringToCard("9c"), false), true), new TestCase( "Same suit, non-desired, no trump - 9 < T", Suit.SPADES, ValuedCard.fromCard(stringToCard("9c"), false), ValuedCard.fromCard(stringToCard("Tc"), false), false), new TestCase( "Same suit, desired, trump - A < J", Suit.HEARTS, ValuedCard.fromCard(stringToCard("Ah"), true), ValuedCard.fromCard(stringToCard("Jh"), true), false), new TestCase( "Same suit, desired, trump - J > A", Suit.DIAMONDS, ValuedCard.fromCard(stringToCard("Ad"), true), ValuedCard.fromCard(stringToCard("Jd"), true), false), new TestCase( "Same suit, non-desired, trump - T < 9", Suit.CLUBS, ValuedCard.fromCard(stringToCard("Th"), true), ValuedCard.fromCard(stringToCard("9h"), true), false), new TestCase( "Same suit, non-desired, trump - 9 > T", Suit.CLUBS, ValuedCard.fromCard(stringToCard("9h"), true), ValuedCard.fromCard(stringToCard("Th"), true), true), new TestCase( "Desired H, Trump C, 7h > Qd", Suit.HEARTS, ValuedCard.fromCard(stringToCard("7h"), false), ValuedCard.fromCard(stringToCard("Qd"), false), true), new TestCase( "Desired S, Trump H, As < 8h", Suit.SPADES, ValuedCard.fromCard(stringToCard("As"), false), ValuedCard.fromCard(stringToCard("8h"), true), false), new TestCase( "Desired D, Trump D, Ad > Jc", Suit.DIAMONDS, ValuedCard.fromCard(stringToCard("Ad"), true), ValuedCard.fromCard(stringToCard("8h"), false), true), new TestCase( "Desired D, Trump D, Td > Ac", Suit.DIAMONDS, ValuedCard.fromCard(stringToCard("Td"), true), ValuedCard.fromCard(stringToCard("Ac"), false), true), new TestCase( "Desired S, Trump H, Ah < 9h", Suit.SPADES, ValuedCard.fromCard(stringToCard("Ah"), true), ValuedCard.fromCard(stringToCard("9h"), true), false), new TestCase( "Desired S, Trump H, Th > 8h", Suit.SPADES, ValuedCard.fromCard(stringToCard("Th"), true), ValuedCard.fromCard(stringToCard("8h"), true), true))); testCases.forEach(TestCase::run); }
@Override public int compare(ValuedCard o1, ValuedCard o2) { if (o1.getSuit().equals(o2.getSuit())) { return o1.getValue() - o2.getValue(); } if (o1.isTrump()) { return 1; } if (o2.isTrump()) { return -1; } if (o1.getSuit().equals(desiredSuit)) { return 1; } if (o2.getSuit().equals(desiredSuit)) { return -1; } return o1.getValue() - o2.getValue(); }
ValuedCardComparator implements Comparator<ValuedCard> { @Override public int compare(ValuedCard o1, ValuedCard o2) { if (o1.getSuit().equals(o2.getSuit())) { return o1.getValue() - o2.getValue(); } if (o1.isTrump()) { return 1; } if (o2.isTrump()) { return -1; } if (o1.getSuit().equals(desiredSuit)) { return 1; } if (o2.getSuit().equals(desiredSuit)) { return -1; } return o1.getValue() - o2.getValue(); } }
ValuedCardComparator implements Comparator<ValuedCard> { @Override public int compare(ValuedCard o1, ValuedCard o2) { if (o1.getSuit().equals(o2.getSuit())) { return o1.getValue() - o2.getValue(); } if (o1.isTrump()) { return 1; } if (o2.isTrump()) { return -1; } if (o1.getSuit().equals(desiredSuit)) { return 1; } if (o2.getSuit().equals(desiredSuit)) { return -1; } return o1.getValue() - o2.getValue(); } ValuedCardComparator(Suit desiredSuit); }
ValuedCardComparator implements Comparator<ValuedCard> { @Override public int compare(ValuedCard o1, ValuedCard o2) { if (o1.getSuit().equals(o2.getSuit())) { return o1.getValue() - o2.getValue(); } if (o1.isTrump()) { return 1; } if (o2.isTrump()) { return -1; } if (o1.getSuit().equals(desiredSuit)) { return 1; } if (o2.getSuit().equals(desiredSuit)) { return -1; } return o1.getValue() - o2.getValue(); } ValuedCardComparator(Suit desiredSuit); @Override int compare(ValuedCard o1, ValuedCard o2); }
ValuedCardComparator implements Comparator<ValuedCard> { @Override public int compare(ValuedCard o1, ValuedCard o2) { if (o1.getSuit().equals(o2.getSuit())) { return o1.getValue() - o2.getValue(); } if (o1.isTrump()) { return 1; } if (o2.isTrump()) { return -1; } if (o1.getSuit().equals(desiredSuit)) { return 1; } if (o2.getSuit().equals(desiredSuit)) { return -1; } return o1.getValue() - o2.getValue(); } ValuedCardComparator(Suit desiredSuit); @Override int compare(ValuedCard o1, ValuedCard o2);  }