Commit ecaf2588 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Fixed bugs in IdentifyIntervalsFromMemberlist

parent ee06943b
......@@ -155,8 +155,9 @@ public class IdentifyIntervalsFromMemberlist {
* Calculates all subintervals from the given members that are located in the given global interval coordinates.
*
* @param <T>
* @param members
* @param interval
* @param members A list of member. Must not be null.
* @param interval An interval in the global coordinate system. If the interval is empty it is not only checked
* whether the interval is overlapping with an existing interval, but if it is adjacent.
* @return
*/
public static <T> List<MemberResult<T>> identifySubintervals(List<? extends Member<? extends T>> members, Interval<Integer> interval) {
......@@ -166,7 +167,7 @@ public class IdentifyIntervalsFromMemberlist {
for (Member<? extends T> member : members) {
final Interval<Integer> global = member.getGlobalInterval();
Interval<Integer> local = null;
if (interval.isEmpty() && operations.contains(global, interval)) {
if (interval.isEmpty() && (operations.contains(global, interval) || operations.adjacent(global, interval))) {
local = operations.shift(interval, -global.getStart());
MemberResult<T> result = new MemberResult<>(member.getId(), local);
list.add(result);
......
......@@ -71,6 +71,20 @@ public class IdentifyIntervalsFromMemberlistTest {
hasItems(new MemberResult<>("s3", createInterval(0, 0))));
}
@Test
public void testIdentifySubintervalsEmtpyIntervalAtEnd() {
assertThat(identifySubintervals(list, createInterval(9, 9)),
hasItems(new MemberResult<>("s4", createInterval(3, 3))));
}
@Test
public void testIdentifySubintervalsEmtpyIntervalAtBeginning() {
List<MemberResult<String>> identifySubintervals = identifySubintervals(list, createInterval(0, 0));
MemberResult<String> expected = new MemberResult<>("s1", createInterval(0, 0));
assertThat(identifySubintervals,
hasItems(expected));
}
@Test
public void testIdentifySubintervalsMultipleInternalIntervals() {
assertThat(identifySubintervals(list, createInterval(5, 8)),
......
/*
* Copyright (C) 2014 Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*
* 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/>.
*/
package de.cebitec.common.sequencetools.intervals;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import static de.cebitec.common.sequencetools.intervals.Intervals.*;
/**
*
* @author Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*/
public class SerializableIntervalTest {
@Test
public void testEqualsEmptyIntervals() {
assertThat(createInterval(0, 0), equalTo(createInterval(0, 0)));
}
@Test
public void testEqualsEmptyIntervals2() {
assertThat(createInterval(1, 1), equalTo(createInterval(1, 1)));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment