From d66775feacb4a7cc43c5296e8ef33811e5e75e79 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 15 May 2015 14:25:56 +0100 Subject: [PATCH] JAL-1270 main method converted 'as seen' to JUnit --- src/jalview/datamodel/Mapping.java | 22 ++-------------- test/jalview/datamodel/MappingTest.java | 43 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 test/jalview/datamodel/MappingTest.java diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 559ae4c..d7b7eb9 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -20,12 +20,12 @@ */ package jalview.datamodel; -import jalview.util.MapList; - import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Vector; +import jalview.util.MapList; + public class Mapping { /** @@ -663,24 +663,6 @@ public class Mapping return copy; } - public static void main(String[] args) - { - /** - * trite test of the intersectVisContigs method for a simple DNA -> Protein - * exon map and a range of visContigs - */ - MapList fk = new MapList(new int[] - { 1, 6, 8, 13, 15, 23 }, new int[] - { 1, 7 }, 3, 1); - Mapping m = new Mapping(fk); - Mapping m_1 = m.intersectVisContigs(new int[] - { fk.getFromLowest(), fk.getFromHighest() }); - Mapping m_2 = m.intersectVisContigs(new int[] - { 1, 7, 11, 20 }); - System.out.println("" + m_1.map.getFromRanges()); - - } - /** * get the sequence being mapped to - if any * diff --git a/test/jalview/datamodel/MappingTest.java b/test/jalview/datamodel/MappingTest.java new file mode 100644 index 0000000..fe2ff59 --- /dev/null +++ b/test/jalview/datamodel/MappingTest.java @@ -0,0 +1,43 @@ +package jalview.datamodel; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; + +import jalview.util.MapList; + +/** + * Test class refactored from main method + */ +public class MappingTest +{ + /** + * trite test of the intersectVisContigs method for a simple DNA -> Protein + * exon map and a range of visContigs + */ + @Test + public void testIntersectVisContigs() + { + MapList fk = new MapList(new int[] + { 1, 6, 8, 13, 15, 23 }, new int[] + { 1, 7 }, 3, 1); + Mapping m = new Mapping(fk); + Mapping m_1 = m.intersectVisContigs(new int[] + { fk.getFromLowest(), fk.getFromHighest() }); + Mapping m_2 = m.intersectVisContigs(new int[] + { 1, 7, 11, 20 }); + + // assertions from output values 'as is', not checked for correctness + String result = Arrays.deepToString(m_1.map.getFromRanges() + .toArray()); + System.out.println(result); + assertEquals("[[1, 6], [8, 13], [15, 23]]", result); + + result = Arrays.deepToString(m_2.map.getFromRanges().toArray()); + System.out.println(result); + assertEquals("[[1, 6], [11, 13], [15, 20]]", result); + } + +} -- 1.7.10.2