forked from fiji/SNT
-
Notifications
You must be signed in to change notification settings - Fork 17
/
TreeStatisticsBTest.java
77 lines (67 loc) · 2.59 KB
/
TreeStatisticsBTest.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*-
* #%L
* Fiji distribution of ImageJ for the life sciences.
* %%
* Copyright (C) 2010 - 2024 Fiji developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package sc.fiji.snt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import sc.fiji.snt.analysis.TreeStatistics;
import sc.fiji.snt.annotation.AllenUtils;
import sc.fiji.snt.annotation.BrainAnnotation;
/**
* Tests for {@link TreeStatistics}
*/
public class TreeStatisticsBTest {
private final double precision = 0.0001;
private Tree tree;
private TreeStatistics tStats;
@Before
public void setUp() throws Exception {
tree = new SNTService().demoTrees().get(1);
tStats = new TreeStatistics(tree);
assumeNotNull(tree);
}
@Test
public void testAnnotatedLength() {
final double cableLength = tStats.getCableLength();
final int maxOntologyDepth = AllenUtils.getHighestOntologyDepth();
for (int level = 0; level < maxOntologyDepth; level++) {
final Map<BrainAnnotation, Double> lengthMap = tStats.getAnnotatedLength(level);
lengthMap.forEach((k, v) -> {
assertEquals("Length in lengthMap entry", tStats.getCableLength(k, true), v, precision);
});
final double mapLength = lengthMap.values().stream().mapToDouble(d -> d).sum();
assertEquals("Sum of annotated lengths", cableLength, mapLength, precision);
final double unaccountedLength = (lengthMap.get(null) == null) ? 0 : lengthMap.get(null);
assertTrue("Length not entirely in null compartment", mapLength - unaccountedLength > 0);
// Check for duplicate keys
Set<String> uniqueKeys = new HashSet<String>();
lengthMap.keySet().stream().filter(e -> !uniqueKeys.add(e.acronym())).collect(Collectors.toSet());
assertEquals("No duplicate keys", uniqueKeys.size(), lengthMap.keySet().size());
}
}
}