@Test
public void testEncloses() throws Exception {

  RingRange r0To20 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(20L));
  RingRange r5To15 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(15L));
  assertTrue(r0To20.encloses(r5To15));
  RingRange r5To25 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(25L));
  assertFalse(r0To20.encloses(r5To25));
  RingRange r190To25 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(25L));
  assertFalse(r0To20.encloses(r190To25));
  RingRange r0To15 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(15L));
  assertTrue(r0To20.encloses(r0To15));
  RingRange r190To15 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(15L));
  assertFalse(r0To20.encloses(r190To15));
  RingRange r190To0 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(0L));
  assertFalse(r0To20.encloses(r190To0));
  RingRange r15To20 = new RingRange(BigInteger.valueOf(15L), BigInteger.valueOf(20L));
  assertTrue(r0To20.encloses(r15To20));
  assertTrue(r0To20.encloses(r0To20));
  RingRange r20To25 = new RingRange(BigInteger.valueOf(20L), BigInteger.valueOf(25L));
  assertFalse(r0To20.encloses(r20To25));
  RingRange r190To20 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(20L));
  assertFalse(r190To20.encloses(r5To25));
  RingRange r200To10 = new RingRange(BigInteger.valueOf(200L), BigInteger.valueOf(10L));
  assertTrue(r190To20.encloses(r200To10));
  RingRange r0To2 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(2L));
  RingRange r5To190 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(190L));
  assertFalse(r0To2.encloses(r5To190));
  // 0_0 should enclose almost everything, but is not enclosed by anything
  RingRange r15To5 = new RingRange(BigInteger.valueOf(15L), BigInteger.valueOf(5L));
  RingRange r0To0 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(0L));
  assertTrue(r0To0.encloses(r0To20));
  assertTrue(r0To0.encloses(r15To20));
  // the exception is that 0_0 does not enclose 15_5
  // this is because 0_0 range means one node in the cluster, and that node can't become
  // a repair coordinator for segment 15_5. This is not a biggie though, because we
  // generate the segments carefully, and prevent situation like this
  assertFalse(r0To0.encloses(r15To5));
  assertTrue(r0To0.encloses(r190To0));
  assertFalse(r0To20.encloses(r0To0));
  assertFalse(r15To20.encloses(r0To0));
  assertFalse(r5To15.encloses(r0To0));
  assertFalse(r190To0.encloses(r0To0));
}