@Test public void compareTo() { class TestCase extends GameEngineTestHelper.ComparisonTestCase<MoveBidding> { int expected; TestCase(String name, MoveBidding m1, MoveBidding m2, int expected) { super(name, m1, m2, true); this.expected = expected; } @Override protected void runAssertions() { if (expected > 0) { assertThat(o1).as("Check greater than").isGreaterThan(o2); return; } if (expected < 0) { assertThat(o1).as("Check less than").isLessThan(o2); return; } assertThat(o1).as("Check equals").isEqualByComparingTo(o2); } } List<TestCase> testCases = new ArrayList<>( List.of( new TestCase("pass - pass", MoveBidding.passMove(), MoveBidding.passMove(), 0), new TestCase( "coinche - coinche", MoveBidding.coincheMove(), MoveBidding.coincheMove(), 0), new TestCase( "surcoinche - surcoinche", MoveBidding.surcoincheMove(), MoveBidding.surcoincheMove(), 0), new TestCase( "pass - coinche", MoveBidding.passMove(), MoveBidding.coincheMove(), -1), new TestCase( "surcoinche - coinche", MoveBidding.surcoincheMove(), MoveBidding.coincheMove(), 1), new TestCase( "surcoinche - pass", MoveBidding.surcoincheMove(), MoveBidding.passMove(), 1), new TestCase( "pass - capot heart", MoveBidding.passMove(), MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), -1), new TestCase( "pass - 130 spades", MoveBidding.passMove(), MoveBidding.contractMove(ContractFactory.createContract(130, Suit.SPADES)), -1), new TestCase( "coinche - capot heart", MoveBidding.passMove(), MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), -1), new TestCase( "130 spades - pass", MoveBidding.contractMove(ContractFactory.createContract(130, Suit.SPADES)), MoveBidding.passMove(), 1), new TestCase( "130 spades - capot heart", MoveBidding.contractMove(ContractFactory.createContract(130, Suit.SPADES)), MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), -1), new TestCase( "130 heart - 130 spades", MoveBidding.contractMove(ContractFactory.createContract(130, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(130, Suit.SPADES)), 1), new TestCase( "capot heart - capot heart", MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), 0), new TestCase( "generale clubs - generale clubs", MoveBidding.contractMove(ContractFactory.createContract(500, Suit.CLUBS)), MoveBidding.contractMove(ContractFactory.createContract(500, Suit.CLUBS)), 0), new TestCase( "capot clubs - capot spades", MoveBidding.contractMove(ContractFactory.createContract(250, Suit.CLUBS)), MoveBidding.contractMove(ContractFactory.createContract(250, Suit.SPADES)), 1), new TestCase( "capot heart - generale spades", MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(500, Suit.SPADES)), -1), new TestCase( "generale heart - generale diamonds", MoveBidding.contractMove(ContractFactory.createContract(500, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(500, Suit.DIAMONDS)), -1), new TestCase( "90 heart - 90 heart", MoveBidding.contractMove(ContractFactory.createContract(90, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(90, Suit.HEARTS)), 0), new TestCase( "90 heart - 130 heart", MoveBidding.contractMove(ContractFactory.createContract(90, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(130, Suit.HEARTS)), -1), new TestCase( "110 diamonds - 110 spades", MoveBidding.contractMove(ContractFactory.createContract(110, Suit.DIAMONDS)), MoveBidding.contractMove(ContractFactory.createContract(110, Suit.SPADES)), 1), new TestCase( "capot heart - 100 heart", MoveBidding.contractMove(ContractFactory.createContract(250, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(100, Suit.HEARTS)), 1), new TestCase( "generale heart - 140 diamonds", MoveBidding.contractMove(ContractFactory.createContract(500, Suit.HEARTS)), MoveBidding.contractMove(ContractFactory.createContract(140, Suit.DIAMONDS)), 1))); testCases.forEach(TestCase::run); }
@Override public int compareTo(MoveBidding o) { if (this.specialMove != null && o.specialMove != null) { return this.specialMove.compareTo(o.specialMove); } if (this.specialMove != null) { return -1; } if (o.specialMove != null) { return 1; } if (o.contract.isHigherThan(this.contract)) { return -1; } if (this.contract.isHigherThan(o.contract)) { return 1; } return this.contract.getSuit().compareTo(o.contract.getSuit()); }
MoveBidding extends Move implements Comparable<MoveBidding> { @Override public int compareTo(MoveBidding o) { if (this.specialMove != null && o.specialMove != null) { return this.specialMove.compareTo(o.specialMove); } if (this.specialMove != null) { return -1; } if (o.specialMove != null) { return 1; } if (o.contract.isHigherThan(this.contract)) { return -1; } if (this.contract.isHigherThan(o.contract)) { return 1; } return this.contract.getSuit().compareTo(o.contract.getSuit()); } }
MoveBidding extends Move implements Comparable<MoveBidding> { @Override public int compareTo(MoveBidding o) { if (this.specialMove != null && o.specialMove != null) { return this.specialMove.compareTo(o.specialMove); } if (this.specialMove != null) { return -1; } if (o.specialMove != null) { return 1; } if (o.contract.isHigherThan(this.contract)) { return -1; } if (this.contract.isHigherThan(o.contract)) { return 1; } return this.contract.getSuit().compareTo(o.contract.getSuit()); } private  MoveBidding(Contract contract, Special specialMove); }
MoveBidding extends Move implements Comparable<MoveBidding> { @Override public int compareTo(MoveBidding o) { if (this.specialMove != null && o.specialMove != null) { return this.specialMove.compareTo(o.specialMove); } if (this.specialMove != null) { return -1; } if (o.specialMove != null) { return 1; } if (o.contract.isHigherThan(this.contract)) { return -1; } if (this.contract.isHigherThan(o.contract)) { return 1; } return this.contract.getSuit().compareTo(o.contract.getSuit()); } private  MoveBidding(Contract contract, Special specialMove); static MoveBidding contractMove(Contract contract); static MoveBidding passMove(); static MoveBidding coincheMove(); static MoveBidding surcoincheMove(); @Override int compareTo(MoveBidding o); Contract getContract(); boolean isPass(); boolean isCoinche(); boolean isSurcoinche(); @Override boolean equals(Object obj); @Override String getShortName(); @Override String toString(); }
MoveBidding extends Move implements Comparable<MoveBidding> { @Override public int compareTo(MoveBidding o) { if (this.specialMove != null && o.specialMove != null) { return this.specialMove.compareTo(o.specialMove); } if (this.specialMove != null) { return -1; } if (o.specialMove != null) { return 1; } if (o.contract.isHigherThan(this.contract)) { return -1; } if (this.contract.isHigherThan(o.contract)) { return 1; } return this.contract.getSuit().compareTo(o.contract.getSuit()); } private  MoveBidding(Contract contract, Special specialMove); static MoveBidding contractMove(Contract contract); static MoveBidding passMove(); static MoveBidding coincheMove(); static MoveBidding surcoincheMove(); @Override int compareTo(MoveBidding o); Contract getContract(); boolean isPass(); boolean isCoinche(); boolean isSurcoinche(); @Override boolean equals(Object obj); @Override String getShortName(); @Override String toString();  }