### Question:
ArrayListOfDoublesWritable extends ArrayListOfDoubles implements
    WritableComparable<ArrayListOfDoublesWritable> { @Override public int compareTo(ArrayListOfDoublesWritable obj) { ArrayListOfDoublesWritable other = (ArrayListOfDoublesWritable) obj; if (isEmpty()) { if (other.isEmpty()) { return 0; } else { return -1; } } for (int i = 0; i < size(); i++) { if (other.size() <= i) { return 1; } if (get(i) < other.get(i)) { return -1; } else if (get(i) > other.get(i)) { return 1; } } if (other.size() > size()) { return -1; } else { return 0; } } ArrayListOfDoublesWritable();  ArrayListOfDoublesWritable(int initialCapacity);  ArrayListOfDoublesWritable(ArrayListOfDoublesWritable other);  ArrayListOfDoublesWritable(double[] arr); void readFields(DataInput in); void write(DataOutput out); @Override String toString(); static ArrayListOfDoublesWritable fromArrayListOfDoubles(ArrayListOfDoubles arr); @Override int compareTo(ArrayListOfDoublesWritable obj);  }### Answer:
@Test public void testCompare() { ArrayListOfDoublesWritable a = new ArrayListOfDoublesWritable(); a.add(one).add(three).add(five); ArrayListOfDoublesWritable b = new ArrayListOfDoublesWritable(); b.add(one).add(three).add(five).add(seven); assertTrue(b.compareTo(a) > 0); b.remove(3); assertTrue(b.compareTo(a) == 0); b.remove(2); assertTrue(b.compareTo(a) < 0); ArrayListOfDoublesWritable c = new ArrayListOfDoublesWritable(); assertTrue(b.compareTo(c) > 0); assertTrue(c.compareTo(a) < 0); assertTrue(a.compareTo(c) > 0); assertTrue(c.compareTo(b) < 0); }
@Test public void testCompare2() { ArrayListOfDoublesWritable a = new ArrayListOfDoublesWritable(); a.add(one).add(three).add(six); ArrayListOfDoublesWritable b = new ArrayListOfDoublesWritable(); b.add(one).add(three).add(four); assertTrue(a.compareTo(b) > 0); ArrayListOfDoublesWritable c = new ArrayListOfDoublesWritable(); c.add(one).add(three).add(four).add(nine); assertTrue(c.compareTo(a) < 0); assertTrue(b.compareTo(c) < 0); ArrayListOfDoublesWritable d = new ArrayListOfDoublesWritable(); d.add(two).add(four); ArrayListOfDoublesWritable e = new ArrayListOfDoublesWritable(); e.add(zero).add(two); assertTrue(d.compareTo(a) > 0); assertTrue(d.compareTo(b) > 0); assertTrue(d.compareTo(c) > 0); assertTrue(e.compareTo(a) < 0); assertTrue(e.compareTo(b) < 0); assertTrue(e.compareTo(c) < 0); assertTrue(e.compareTo(d) < 0); }