From 3e6ab0cb043dd49393bf8a9cb6d79098d5a6b6a5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 27 Jan 2017 15:30:49 +0000 Subject: [PATCH] JAL-2099 belated unit test --- test/jalview/renderer/ScaleRendererTest.java | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/jalview/renderer/ScaleRendererTest.java diff --git a/test/jalview/renderer/ScaleRendererTest.java b/test/jalview/renderer/ScaleRendererTest.java new file mode 100644 index 0000000..5588ad1 --- /dev/null +++ b/test/jalview/renderer/ScaleRendererTest.java @@ -0,0 +1,73 @@ +package jalview.renderer; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; +import jalview.io.DataSourceType; +import jalview.io.FileLoader; +import jalview.renderer.ScaleRenderer.ScaleMark; + +import java.util.List; + +import org.testng.annotations.Test; + +public class ScaleRendererTest +{ + @Test + public void testCalculateMarks() + { + String data = ">Seq/20-45\nABCDEFGHIJKLMNOPQRSTUVWXYS\n"; + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(data, + DataSourceType.PASTE); + AlignViewport av = af.getViewport(); + + /* + * scale has minor ticks at 5 and 15, major at 10 and 20 + * (these are base 1, ScaleMark holds base 0 values) + */ + List marks = new ScaleRenderer().calculateMarks(av, 0, 25); + assertEquals(marks.size(), 4); + + assertFalse(marks.get(0).major); + assertEquals(marks.get(0).column, 4); + assertNull(marks.get(0).text); + + assertTrue(marks.get(1).major); + assertEquals(marks.get(1).column, 9); + assertEquals(marks.get(1).text, "10"); + + assertFalse(marks.get(2).major); + assertEquals(marks.get(2).column, 14); + assertNull(marks.get(2).text); + + assertTrue(marks.get(3).major); + assertEquals(marks.get(3).column, 19); + assertEquals(marks.get(3).text, "20"); + + /* + * now hide columns 9-11 and 18-20 (base 1) + * scale marks are now in the same columns as before, but + * with column numbering adjusted for hidden columns + */ + av.hideColumns(8, 10); + av.hideColumns(17, 19); + marks = new ScaleRenderer().calculateMarks(av, 0, 25); + assertEquals(marks.size(), 4); + assertFalse(marks.get(0).major); + assertEquals(marks.get(0).column, 4); + assertNull(marks.get(0).text); + assertTrue(marks.get(1).major); + assertEquals(marks.get(1).column, 9); + assertEquals(marks.get(1).text, "13"); // +3 hidden columns + assertFalse(marks.get(2).major); + assertEquals(marks.get(2).column, 14); + assertNull(marks.get(2).text); + assertTrue(marks.get(3).major); + assertEquals(marks.get(3).column, 19); + assertEquals(marks.get(3).text, "26"); // +6 hidden columns + } +} -- 1.7.10.2