From 9317de4ce997ec39dee25ec507c12807c5067d7d Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 21 Nov 2017 09:57:29 +0000 Subject: [PATCH] JAL-2759 BoundedStartRegionIterator test --- .../datamodel/BoundedStartRegionIteratorTest.java | 214 ++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 test/jalview/datamodel/BoundedStartRegionIteratorTest.java diff --git a/test/jalview/datamodel/BoundedStartRegionIteratorTest.java b/test/jalview/datamodel/BoundedStartRegionIteratorTest.java new file mode 100644 index 0000000..77b4fd2 --- /dev/null +++ b/test/jalview/datamodel/BoundedStartRegionIteratorTest.java @@ -0,0 +1,214 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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. + * + * Jalview 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 Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.datamodel; + +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.testng.annotations.Test; + +public class BoundedStartRegionIteratorTest +{ + /** + * Test the start region iterator + */ + @Test(groups = { "Functional" }) + public void testBasicBoundsIterator() + { + List hiddenColumns = null; + + // null hidden columns + Iterator it = new BoundedStartRegionIterator(3, 10, + hiddenColumns); + assertFalse(it.hasNext()); + + hiddenColumns = new ArrayList<>(); + + // no hidden columns + it = new BoundedStartRegionIterator(3, 10, hiddenColumns); + assertFalse(it.hasNext()); + + // add some hidden columns + hiddenColumns.add(new int[] { 5, 10 }); + hiddenColumns.add(new int[] { 25, 40 }); + + it = new BoundedStartRegionIterator(3, 10, hiddenColumns); + assertTrue(it.hasNext()); + Integer result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(3, 15, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(3, 18, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(3, 19, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertFalse(it.hasNext()); + + hiddenColumns.add(new int[] { 47, 50 }); + + it = new BoundedStartRegionIterator(15, 60, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(25, (int) result); + assertFalse(it.hasNext()); + } + + /** + * Test the start region iterator with null cursor + */ + @Test(groups = { "Functional" }) + public void testBoundsIteratorUsingNullCursor() + { + List hiddenColumns = null; + HiddenCursorPosition pos = null; + + // null hidden columns + Iterator it = new BoundedStartRegionIterator(pos, 3, 10, + hiddenColumns); + assertFalse(it.hasNext()); + + hiddenColumns = new ArrayList<>(); + + // no hidden columns + it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns); + assertFalse(it.hasNext()); + + // add some hidden columns + hiddenColumns.add(new int[] { 5, 10 }); + hiddenColumns.add(new int[] { 25, 40 }); + + it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns); + assertTrue(it.hasNext()); + Integer result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertFalse(it.hasNext()); + + hiddenColumns.add(new int[] { 47, 50 }); + + it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(25, (int) result); + assertFalse(it.hasNext()); + } + + /** + * Test the start region iterator with nonnull cursor + */ + @Test(groups = { "Functional" }) + public void testBoundsIteratorUsingCursor() + { + List hiddenColumns = new ArrayList<>(); + + // add some hidden columns + hiddenColumns.add(new int[] { 5, 10 }); + hiddenColumns.add(new int[] { 25, 40 }); + + HiddenCursorPosition pos = new HiddenCursorPosition(0, 0); + + Iterator it = new BoundedStartRegionIterator(pos, 3, 10, + hiddenColumns); + assertTrue(it.hasNext()); + Integer result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertFalse(it.hasNext()); + + it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(5, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertFalse(it.hasNext()); + + pos = new HiddenCursorPosition(1, 6); + hiddenColumns.add(new int[] { 47, 50 }); + + it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(19, (int) result); + assertTrue(it.hasNext()); + result = it.next(); + assertEquals(25, (int) result); + assertFalse(it.hasNext()); + } +} -- 1.7.10.2