Position implements Comparable<Position> { @Override public int compareTo(Position p) { if (p == null) { return Integer.MIN_VALUE; } if (m_line < p.m_line) { return -1; } if (m_line > p.m_line) { return 1; } return m_column - p.m_column; } Position(int line, int column); int getLine(); int getColumn(); @Override String toString(); @Override int compareTo(Position p); @Override int hashCode(); @Override boolean equals(Object o); Position moveBy(int offset); static final Position ZERO; static final Nowhere NOWHERE; }
@Test public void test1() { Position p1 = new Position(0, 0); Position p2 = new Position(0, 0); assertTrue(p1.compareTo(p2) == 0); }
@Test public void test2() { Position p1 = new Position(0, 0); Position p2 = new Position(0, 1); assertTrue(p1.compareTo(p2) < 0); }
@Test public void test3() { Position p1 = new Position(0, 1); Position p2 = new Position(0, 0); assertTrue(p1.compareTo(p2) > 0); }
@Test public void test4() { Position p1 = new Position(0, 0); Position p2 = new Position(1, 0); assertTrue(p1.compareTo(p2) < 0); }
@Test public void test5() { Position p1 = new Position(1, 0); Position p2 = new Position(0, 0); assertTrue(p1.compareTo(p2) > 0); }