private void checkDistanceIsUndefined(SequenceMetric metric, String x, String y) { try { metric.distance(x, y); fail( "Should throw an exception for words of unequal lengths" + " (between \"" + x + "\" and \"" + y + "\")"); } catch (IllegalArgumentException e) { assertTrue(true); } try { metric.distance(y, x); fail( "Should throw an exception for words of unequal lengths" + " (between \"" + y + "\" and \"" + x + "\")"); } catch (IllegalArgumentException e) { assertTrue(true); } }
private void checkDistance(SequenceMetric metric, String x, String y, int expectedDistance) { int distance1 = metric.distance(x, y); int distance2 = metric.distance(y, x); String message = " (between \"" + x + "\" and \"" + y + "\")"; assertEquals("Distance must be non-negative" + message, true, expectedDistance >= 0); assertEquals("Distance must be symmetric" + message, distance1, distance2); assertEquals("Incorrect distance" + message, expectedDistance, distance1); }