Skip to content

Commit

Permalink
Merge pull request #268 from softwaremagico/209-tournament-brackets-n…
Browse files Browse the repository at this point in the history
…ot-correctly-drawn-with-5-groups

209 tournament brackets not correctly drawn with 5 groups
  • Loading branch information
softwaremagico authored Nov 17, 2023
2 parents 2ef6e96 + 11b2d02 commit 361885c
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 192 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager)
[![Time](https://img.shields.io/badge/development-519.5h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-521h-blueviolet.svg)]()

[![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]()
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public void adjustGroupsSize(Tournament tournament, int numberOfWinners) {
final Map<Integer, List<Group>> groupsByLevel = GroupUtils.orderByLevel(tournamentGroups);
int previousLevelSize = 0;
for (final Integer level : new HashSet<>(groupsByLevel.keySet())) {
if (groupsByLevel.get(level).size() < ((((previousLevelSize + 1) * (level == 1 ? numberOfWinners : 1))) / 2)) {
while (groupsByLevel.get(level).size()
< ((((previousLevelSize
// add +1 unless number of winners 2. This +1 will be rounded later but is needed if even teams pass from previous level.
+ (level == 1 && numberOfWinners == 2 ? 0 : 1))
//Check on level 1 the number of winners.
* (level == 1 ? numberOfWinners : 1))) / 2)) {
final Group levelGroup = new Group(tournament, level, groupsByLevel.get(level).size());
groupProvider.addGroup(tournament, levelGroup);
groupsByLevel.get(level).add(levelGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
Expand All @@ -37,15 +37,15 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import java.util.List;

@SpringBootTest
@Test(groups = {"numberOfWinners"})
public class NumberOfWinners extends AbstractTestNGSpringContextTests {
public class NumberOfWinnersTest extends AbstractTestNGSpringContextTests {

private static final String TOURNAMENT_NAME = "TournamentTest";
private static final String TOURNAMENT_TWO_WINNERS_NAME = "TournamentTest2";
private static final int MEMBERS = 3;

Expand Down Expand Up @@ -83,6 +83,13 @@ private void checkLink(GroupLink groupLink, int source, int destination, int win
Assert.assertEquals(groupLink.getWinner(), winner);
}

@AfterMethod
public void removeGroups() {
groupProvider.deleteAll();
tournamentExtraPropertyProvider.deleteAll();
tournamentProvider.deleteAll();
}

@Test
public void swapBetweenOneAndTwoWinners() {
Tournament tournamentChangingWinners = new Tournament(TOURNAMENT_TWO_WINNERS_NAME, 1, MEMBERS, TournamentType.TREE, null);
Expand Down Expand Up @@ -157,4 +164,21 @@ public void swapBetweenOneAndTwoWinners() {
checkLink(groupLinks.get(0), 0, 0, 0);
checkLink(groupLinks.get(1), 1, 0, 0);
}

@Test
public void addingAndRemovingGroupsWithTwoWinners() {
Tournament tournamentChangingWinners = new Tournament(TOURNAMENT_TWO_WINNERS_NAME, 1, MEMBERS, TournamentType.TREE, null);
tournamentChangingWinners = tournamentProvider.save(tournamentChangingWinners);
tournamentExtraPropertyProvider.save(new TournamentExtraProperty(tournamentChangingWinners, TournamentExtraPropertyKey.NUMBER_OF_WINNERS, "1"));


treeTournamentHandler.addGroup(tournamentChangingWinners, generateGroup(0, tournamentChangingWinners));
treeTournamentHandler.addGroup(tournamentChangingWinners, generateGroup(1, tournamentChangingWinners));
treeTournamentHandler.addGroup(tournamentChangingWinners, generateGroup(2, tournamentChangingWinners));
treeTournamentHandler.addGroup(tournamentChangingWinners, generateGroup(3, tournamentChangingWinners));

tournamentController.setNumberOfWinners(tournamentChangingWinners.getId(), 2, null);

Assert.assertEquals(groupProvider.getGroups(tournamentChangingWinners).size(), 11);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<class name="com.softwaremagico.kt.core.tests.achievements.TournamentTypeAchievementsTest"/>
<class name="com.softwaremagico.kt.core.tests.StatisticsTest"/>
<class name="com.softwaremagico.kt.core.tests.GroupTreeTest"/>
<class name="com.softwaremagico.kt.core.tests.NumberOfWinners"/>
<class name="com.softwaremagico.kt.core.tests.NumberOfWinnersTest"/>
</classes>
</test>
</suite>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

import java.awt.*;
import java.awt.Color;

public abstract class ParentList extends PdfDocument {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ spring.messages.basename=language/language
#Database Access
spring.jpa.open-in-view=false
spring.kendo.datasource.jpa.hibernate.ddl-auto=create-drop
spring.kendo.datasource.platform=mysql
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.kendo.datasource.jdbc-url=jdbc:mysql://localhost:3306/kendotournament?allowPublicKeyRetrieval=true&useSSL=false
spring.kendo.datasource.username=user
spring.kendo.datasource.password=asd123
spring.kendo.datasource.platform=h2
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.kendo.datasource.jdbc-url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false
spring.kendo.datasource.username=sa
spring.kendo.datasource.password=
spring.kendo.datasource.initialize=true
spring.kendo.datasource.test-while-idle=true

Expand Down
Loading

0 comments on commit 361885c

Please sign in to comment.