File size: 1,984 Bytes
2311079
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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<Puzzle>();
        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<Puzzle>();
        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());
    }
}