コード例 #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));
 }
コード例 #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));
 }