1 | import static org.junit.Assert.assertEquals;
|
---|
2 | import static org.junit.Assert.assertTrue;
|
---|
3 |
|
---|
4 | import java.io.IOException;
|
---|
5 |
|
---|
6 | import org.junit.Test;
|
---|
7 |
|
---|
8 | import tudelft.mentalhealth.perfectfit.Characteristics;
|
---|
9 | import tudelft.mentalhealth.perfectfit.GoalLine;
|
---|
10 | import tudelft.mentalhealth.perfectfit.SortedGoals;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * NOTE!! The ID value in the table is NOT equal to the row number It skips a
|
---|
14 | * number of values for some reason. Eg there are no id 10 and 11.
|
---|
15 | */
|
---|
16 | public class SortedGoalsTest {
|
---|
17 | @Test
|
---|
18 | public void test1() throws IOException {
|
---|
19 | // copy of characteristics of example id=6 from the file
|
---|
20 | Characteristics c6 = new Characteristics(1, 0.698430493273543,
|
---|
21 | 0.604904632152589, 0.363636363636364, 0.75, 0.6,
|
---|
22 | 0.285714285714286, 0.537037037037037, 0.25, 0.333333333333333);
|
---|
23 | SortedGoals sorted = new SortedGoals(c6);
|
---|
24 |
|
---|
25 | checkSortedProperly(sorted, c6);
|
---|
26 | // The firxt one will be one that is actually higher than c31
|
---|
27 | assertEquals(6, sorted.get(1).getId());
|
---|
28 |
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void test31() throws IOException {
|
---|
33 | // copy of characteristics of example 5 from the file
|
---|
34 | Characteristics c31 = new Characteristics(1, 0.724215246636771,
|
---|
35 | 0.272479564032698, 0.636363636363636, 0.25, 0.2,
|
---|
36 | 0.357142857142857, 0.592592592592593, 0.333333333333333, 0.5);
|
---|
37 | SortedGoals sorted = new SortedGoals(c31);
|
---|
38 |
|
---|
39 | checkSortedProperly(sorted, c31);
|
---|
40 | // The firxt one will be one that is actually higher than c31
|
---|
41 | assertEquals(31, sorted.get(1).getId());
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Test
|
---|
45 | public void test43() throws IOException {
|
---|
46 | // copy of characteristics of example 5 from the file
|
---|
47 | Characteristics c43 = new Characteristics(1, 0.896860986547085,
|
---|
48 | 0.574931880108992, 0.363636363636364, 0.75, 0.4, 0.5,
|
---|
49 | 0.055555555555556, 0.25, 0.333333333333333);
|
---|
50 | SortedGoals sorted = new SortedGoals(c43);
|
---|
51 |
|
---|
52 | checkSortedProperly(sorted, c43);
|
---|
53 | // The firxt AND second one will be one that is actually higher than c31
|
---|
54 | assertEquals(43, sorted.get(2).getId());
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | private void checkSortedProperly(SortedGoals sorted, Characteristics c) {
|
---|
59 | GoalLine ex0 = sorted.get(0);
|
---|
60 | double sim0 = ex0.characteristics().similarity(c);
|
---|
61 |
|
---|
62 | // check that the first one is indeed the best match
|
---|
63 | for (GoalLine ex : sorted.getList()) {
|
---|
64 | assertTrue(
|
---|
65 | "Example " + ex
|
---|
66 | + " is more similar to c31 than the top pick",
|
---|
67 | ex.characteristics().similarity(c) <= sim0);
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|
71 | }
|
---|