|
|
@ -26,13 +26,11 @@ import org.junit.rules.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.lang.Math.*;
|
|
|
|
import static junit.framework.TestCase.assertFalse;
|
|
|
|
import static junit.framework.TestCase.assertFalse;
|
|
|
|
import static junit.framework.TestCase.fail;
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.*;
|
|
|
|
import static org.hamcrest.CoreMatchers.*;
|
|
|
|
import static org.hamcrest.MatcherAssert.*;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static org.isoron.uhabits.core.models.HabitList.Order.BY_COLOR;
|
|
|
|
import static org.isoron.uhabits.core.models.HabitList.Order.*;
|
|
|
|
import static org.isoron.uhabits.core.models.HabitList.Order.BY_NAME;
|
|
|
|
|
|
|
|
import static org.isoron.uhabits.core.models.HabitList.Order.BY_POSITION;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
|
|
|
|
|
|
@ -173,36 +171,35 @@ public class HabitListTest extends BaseUnitTest
|
|
|
|
public void testReorder()
|
|
|
|
public void testReorder()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int operations[][] = {
|
|
|
|
int operations[][] = {
|
|
|
|
{ 5, 2 }, { 3, 7 }, { 4, 4 }, { 3, 2 }
|
|
|
|
{ 5, 2 }, { 3, 7 }, { 4, 4 }, { 8, 3 }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int expectedPosition[][] = {
|
|
|
|
int expectedSequence[][] = {
|
|
|
|
{ 0, 1, 3, 4, 5, 2, 6, 7, 8, 9 },
|
|
|
|
{ 0, 1, 5, 2, 3, 4, 6, 7, 8, 9 },
|
|
|
|
{ 0, 1, 7, 3, 4, 2, 5, 6, 8, 9 },
|
|
|
|
{ 0, 1, 5, 2, 4, 6, 7, 3, 8, 9 },
|
|
|
|
{ 0, 1, 7, 3, 4, 2, 5, 6, 8, 9 },
|
|
|
|
{ 0, 1, 5, 2, 4, 6, 7, 3, 8, 9 },
|
|
|
|
{ 0, 1, 7, 2, 4, 3, 5, 6, 8, 9 },
|
|
|
|
{ 0, 1, 5, 2, 4, 6, 7, 8, 3, 9 },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < operations.length; i++)
|
|
|
|
for (int i = 0; i < operations.length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int from = operations[i][0];
|
|
|
|
Habit fromHabit = habitsArray.get(operations[i][0]);
|
|
|
|
int to = operations[i][1];
|
|
|
|
Habit toHabit = habitsArray.get(operations[i][1]);
|
|
|
|
|
|
|
|
|
|
|
|
Habit fromHabit = habitList.getByPosition(from);
|
|
|
|
|
|
|
|
Habit toHabit = habitList.getByPosition(to);
|
|
|
|
|
|
|
|
habitList.reorder(fromHabit, toHabit);
|
|
|
|
habitList.reorder(fromHabit, toHabit);
|
|
|
|
|
|
|
|
|
|
|
|
int actualPositions[] = new int[10];
|
|
|
|
int actualSequence[] = new int[10];
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 10; j++)
|
|
|
|
for (int j = 0; j < 10; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Habit h = habitList.getById(j);
|
|
|
|
Habit h = habitList.getByPosition(j);
|
|
|
|
if (h == null) fail();
|
|
|
|
assertThat(h.getPosition(), equalTo(j));
|
|
|
|
actualPositions[j] = habitList.indexOf(h);
|
|
|
|
actualSequence[j] = toIntExact(h.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(actualPositions, equalTo(expectedPosition[i]));
|
|
|
|
assertThat(actualSequence, equalTo(expectedSequence[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(activeHabits.indexOf(habitsArray.get(5)), equalTo(0));
|
|
|
|
|
|
|
|
assertThat(activeHabits.indexOf(habitsArray.get(2)), equalTo(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -281,4 +278,14 @@ public class HabitListTest extends BaseUnitTest
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
|
|
activeHabits.reorder(h1, h2);
|
|
|
|
activeHabits.reorder(h1, h2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testReorder_onSortedList() throws Exception
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
habitList.setOrder(BY_SCORE);
|
|
|
|
|
|
|
|
Habit h1 = habitsArray.get(1);
|
|
|
|
|
|
|
|
Habit h2 = habitsArray.get(2);
|
|
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
|
|
|
|
|
|
habitList.reorder(h1, h2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|