### Question:
MultiTableRRRangePartitioner extends MultiTableRangePartitioner { @Override protected int calculateIndex(int index, int numPartitions, String tableName, int cutPointArrayLength) { if (SPLIT_TO_REDUCER_MAP.containsKey(tableName) && SPLIT_TO_REDUCER_MAP.get(tableName).containsKey(index)) { return SPLIT_TO_REDUCER_MAP.get(tableName).get(index); } else { int i = cutPointArrayLength; int reducer = numPartitions - 1; Map<Integer,Integer> tempSplitReducerMap = new HashMap<>(); tempSplitReducerMap.put(i, reducer); tempSplitReducerMap.put(-i - 1, reducer); i--; reducer--; while (i >= 0) { while (reducer >= 0) { tempSplitReducerMap.put(i, reducer); tempSplitReducerMap.put(-i - 1, reducer); i--; reducer--; if (i < 0) break; } reducer = numPartitions - 1; } SPLIT_TO_REDUCER_MAP.put(tableName, tempSplitReducerMap); if (SPLIT_TO_REDUCER_MAP.containsKey(tableName) && SPLIT_TO_REDUCER_MAP.get(tableName).containsKey(index)) { return SPLIT_TO_REDUCER_MAP.get(tableName).get(index); } LOG.trace("Index was not found after recomputing the reducer map"); return 0; } }    }### Answer:
@Test public void testCalculateIndex() { int index = -9; int indexTwo = 8; int indexThree = -1; int indexFour = -15; int expectedResult = 2; int numPartitions = 5; String tableName = "test"; int cutPointArrayLength = 10; MultiTableRRRangePartitioner instance = new MultiTableRRRangePartitioner(); int result = instance.calculateIndex(index, numPartitions, tableName, cutPointArrayLength); int resultTwo = instance.calculateIndex(indexTwo, numPartitions, tableName, cutPointArrayLength); int resultThree = instance.calculateIndex(indexThree, numPartitions, tableName, cutPointArrayLength); int resultFour = instance.calculateIndex(indexFour, numPartitions, tableName, cutPointArrayLength); assertEquals(result, resultTwo); assertEquals(result, expectedResult); Assert.assertNotNull(resultThree); Assert.assertNotNull(resultFour); }
@Test public void testCalculateIndexRangeIsValid() { int numPartitions = 581; int cutPointArrayLength = 195; MultiTableRRRangePartitioner partitioner = new MultiTableRRRangePartitioner(); for (int i = -1 * cutPointArrayLength - 1; i < cutPointArrayLength; i++) { int result = partitioner.calculateIndex(i, numPartitions, "someTableName", cutPointArrayLength); Assert.assertTrue("i: " + i + " result: " + result, 0 <= result); Assert.assertTrue("i: " + i + " result: " + result, result < numPartitions); } }