package com.tacticmaster.puzzle; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; import java.util.TreeSet; public class PuzzleTest { @Test public void testCompareTo() { Puzzle puzzle1 = new Puzzle("1", "fen1", "moves1", 1500, 100, 10, 1000, "themes1", "url1", "opening1"); Puzzle puzzle2 = new Puzzle("2", "fen2", "moves2", 1600, 100, 10, 1000, "themes2", "url2", "opening2"); Puzzle puzzle3 = new Puzzle("3", "fen3", "moves3", 1400, 100, 10, 1000, "themes3", "url3", "opening3"); assertTrue(puzzle1.compareTo(puzzle2) < 0); assertTrue(puzzle2.compareTo(puzzle3) > 0); assertTrue(puzzle1.compareTo(puzzle3) > 0); assertEquals(0, puzzle1.compareTo(new Puzzle("1", "fen1", "moves1", 1500, 100, 10, 1000, "themes1", "url1", "opening1"))); } @Test public void treeSet() { var puzzleSet = new java.util.TreeSet(); puzzleSet.add(new Puzzle("1", "fen1", "moves1", 1500, 100, 10, 1000, "themes1", "url1", "opening1")); puzzleSet.add(new Puzzle("2", "fen2", "moves2", 1600, 100, 10, 1000, "themes2", "url2", "opening2")); puzzleSet.add(new Puzzle("3", "fen3", "moves3", 1400, 100, 10, 1000, "themes3", "url3", "opening3")); assertEquals(1400, puzzleSet.first().rating()); assertEquals(1600, puzzleSet.last().rating()); puzzleSet.pollLast(); assertEquals(1400, puzzleSet.first().rating()); assertEquals(1500, puzzleSet.last().rating()); } @Test public void testSameRatingDifferentId() { var puzzleSet = new TreeSet(); puzzleSet.add(new Puzzle("1", "fen1", "moves1", 1500, 100, 10, 1000, "themes1", "url1", "opening1")); puzzleSet.add(new Puzzle("2", "fen2", "moves2", 1500, 100, 10, 1000, "themes2", "url2", "opening2")); assertEquals(2, puzzleSet.size()); } }