1 package jalview.renderer;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertNull;
6 import static org.testng.Assert.assertTrue;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.AlignViewport;
10 import jalview.io.DataSourceType;
11 import jalview.io.FileLoader;
12 import jalview.renderer.ScaleRenderer.ScaleMark;
14 import java.util.List;
16 import org.testng.annotations.Test;
18 public class ScaleRendererTest
20 @Test(groups = "Functional")
21 public void testCalculateMarks()
23 String data = ">Seq/20-45\nABCDEFGHIJKLMNOPQRSTUVWXYS\n";
24 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(data,
25 DataSourceType.PASTE);
26 AlignViewport av = af.getViewport();
29 * scale has minor ticks at 5, 15, 25, major at 10 and 20
30 * (these are base 1, ScaleMark holds base 0 values)
32 List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, 0, 25);
33 assertEquals(marks.size(), 5);
35 assertFalse(marks.get(0).major);
36 assertEquals(marks.get(0).column, 4);
37 assertNull(marks.get(0).text);
39 assertTrue(marks.get(1).major);
40 assertEquals(marks.get(1).column, 9);
41 assertEquals(marks.get(1).text, "10");
43 assertFalse(marks.get(2).major);
44 assertEquals(marks.get(2).column, 14);
45 assertNull(marks.get(2).text);
47 assertTrue(marks.get(3).major);
48 assertEquals(marks.get(3).column, 19);
49 assertEquals(marks.get(3).text, "20");
51 assertFalse(marks.get(4).major);
52 assertEquals(marks.get(4).column, 24);
53 assertNull(marks.get(4).text);
56 * now hide columns 9-11 and 18-20 (base 1)
57 * scale marks are now in the same columns as before, but
58 * with column numbering adjusted for hidden columns
60 av.hideColumns(8, 10);
61 av.hideColumns(17, 19);
62 marks = new ScaleRenderer().calculateMarks(av, 0, 25);
63 assertEquals(marks.size(), 5);
64 assertFalse(marks.get(0).major);
65 assertEquals(marks.get(0).column, 4);
66 assertNull(marks.get(0).text);
67 assertTrue(marks.get(1).major);
68 assertEquals(marks.get(1).column, 9);
69 assertEquals(marks.get(1).text, "13"); // +3 hidden columns
70 assertFalse(marks.get(2).major);
71 assertEquals(marks.get(2).column, 14);
72 assertNull(marks.get(2).text);
73 assertTrue(marks.get(3).major);
74 assertEquals(marks.get(3).column, 19);
75 assertEquals(marks.get(3).text, "26"); // +6 hidden columns
76 assertFalse(marks.get(4).major);
77 assertEquals(marks.get(4).column, 24);
78 assertNull(marks.get(4).text);