Exemplo n.º 1
0
 /** Tests immutability (by modifying arrays) */
 @Test
 public void testImmutability2() {
   int[] coords = new int[] {1, 2, 3};
   int[] clonedCoords = coords.clone();
   GridCoordinates gc = new GridCoordinatesImpl(coords);
   // Modify the input array, verify that dp returns same value
   coords[1] = 6;
   int[] gcCoords = gc.getCoordinateValues();
   assertTrue(Arrays.equals(gcCoords, clonedCoords));
   // Modify the output array, verify that dp returns same value
   gcCoords[0] = 12;
   assertTrue(Arrays.equals(gc.getCoordinateValues(), clonedCoords));
 }
Exemplo n.º 2
0
 /**
  * Tests immutability (by modifying arrays). This time we test the other constructor of
  * DirectPositionImpl.
  */
 @Test
 public void testImmutability3() {
   int[] otherCoords = new int[] {2, 3};
   int[] refCoords = new int[] {1, 2, 3};
   GridCoordinates gc = new GridCoordinatesImpl(1, otherCoords);
   // Modify the input array, verify that dp returns same value
   otherCoords[1] = 6;
   int[] gcCoords = gc.getCoordinateValues();
   assertTrue(Arrays.equals(gcCoords, refCoords));
   // Modify the output array, verify that dp returns same value
   gcCoords[0] = 12;
   assertTrue(Arrays.equals(gc.getCoordinateValues(), refCoords));
 }
Exemplo n.º 3
0
 /** Tests immutability (1) */
 @Test(expected = UnsupportedOperationException.class)
 public void testImmutability1() {
   GridCoordinates gc = new GridCoordinatesImpl(5, 6, 7, 8);
   gc.setCoordinateValue(1, 4);
 }
Exemplo n.º 4
0
 /** Tests hashCode() method */
 @Test
 public void testHashCode() {
   GridCoordinates gc = new GridCoordinatesImpl(5, 6, 7, 8);
   // Hash code of gc is the hash code of its coordinate array
   assertTrue(gc.hashCode() == Arrays.hashCode(new int[] {5, 6, 7, 8}));
 }
Exemplo n.º 5
0
 private static void testNormalConstructionHelper(GridCoordinates gc) {
   assertTrue(gc.getDimension() == 3);
   assertEquals(gc.getCoordinateValue(0), 2);
   assertEquals(gc.getCoordinateValue(1), 3);
   assertEquals(gc.getCoordinateValue(2), 4);
 }