incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickcha...@apache.org
Subject svn commit: rev 36595 - incubator/depot/trunk/version/src/test/java/org/apache/depot/version
Date Thu, 19 Aug 2004 07:33:23 GMT
Author: nickchalko
Date: Thu Aug 19 00:33:22 2004
New Revision: 36595

Modified:
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
Log:
A lot more tests.

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
Thu Aug 19 00:33:22 2004
@@ -58,27 +58,135 @@
 	public void testEquality() {
 		assertSymetricNotEquals(base, Version.UNKNOWN);
 
-		assertEquals("Version of " + getBaseVersionString(), base, same);
-		assertEquals("Version of " + getBaseVersionString(), same, base);
+		assertSymetricEquals(base, same);
 		assertSymetricNotEquals(nonCompatible, base);
 		assertSymetricNotEquals(compatible, base);
 	}
 
 	public void testComparable() {
-		assertSymetricComparableZero(base, same);
+		assertSymetricComparableEquals(base, same);
 		assertSymetricCompare(base, nonCompatible);
 	}
 
 	public void testComparator() {
 		Version v1 = base;
 		Version v2 = same;
-
+		assertSymetricComparatorEquals(base, same);
 		Version less = base;
 		Version more = nonCompatible;
 		assertSymetricComparator(less, more);
 
 	}
 
+	public void testIncrement() throws VersionException {
+		test5increments(base, getNonCompatibleIncrement(), false);
+		test5increments(base, getCompatibleIncrement(), true);
+
+	}
+
+	/**
+	 * @param start
+	 * @param incrementLevel
+	 * @param compatible
+	 * @throws VersionException
+	 */
+	public void test5increments(Version start, final String incrementLevel,
+			final boolean compatible) throws VersionException {
+
+		testIncrement(start, incrementLevel, compatible, 5);
+	}
+
+	/**
+	 * @param start
+	 * @param incrementLevel
+	 * @param compatible
+	 * @param iterations
+	 * @throws VersionException
+	 */
+	public void testIncrement(Version start, final String incrementLevel,
+			final boolean compatible, int iterations) throws VersionException {
+		Version last = start;
+		for (int i = 0; i < iterations; i++) {
+			Version next = last.increment(incrementLevel);
+			assertVersionReleation(start, next, compatible, -1);
+			assertVersionReleation(last, next, compatible, -1);
+
+		}
+	}
+
+	/**
+	 * Assert the ordering, and compatablity of two versions. Tests eqauls,
+	 * Comparable,Comparator and isCompatible.
+	 * 
+	 * @param v1
+	 *            a Version
+	 * @param v2
+	 *            a Version
+	 * @param compatible
+	 * @param
+	 */
+	public void assertVersionReleation(Version v1, Version v2,
+			final boolean compatible, int compare) {
+
+		if (compare == 0 && !compatible) {
+			throw new IllegalArgumentException(
+					"If a version is equal it must be compatable.  The test setup is illegal");
+		}
+		if (compare == 0) {
+			assertSymetricEquals(v1, v2);
+			assertSymetricComparableEquals(v1, v2);
+			assertSymetricComparatorEquals(v1, v2);
+		} else {
+			assertSymetricNotEquals(v1, v2);
+			Version less = v1, more = v2;
+			if (compare > 0) {
+				less = v2;
+				more = v1;
+			}
+			assertSymetricLess(less, more);
+		}
+		assertSymetricCompatability(v1, v2, compatible);
+	}
+
+	/**
+	 * @param v1
+	 * @param v2
+	 * @param expected
+	 */
+	private void assertSymetricCompatability(Version v1, Version v2,
+			final boolean expected) {
+		assertEquals(v1 + " compatbile with " + v2, expected, v1
+				.isCompatible(v2));
+		assertEquals(v2 + " compatbile with " + v1, expected, v2
+				.isCompatible(v1));
+	}
+
+	/**
+	 * @param less
+	 * @param more
+	 */
+	private void assertSymetricLess(Version less, Version more) {
+		assertSymetricComparator(less, more);
+		assertSymetricCompare(less, more);
+	}
+
+	/**
+	 * @param v1
+	 * @param v2
+	 */
+	private void assertSymetricComparatorEquals(Version v1, Version v2) {
+		Comparator c = v1.getComparator();
+		assertEquals("Using first comparator   " + c + ". " + v1
+				+ " compare to " + v2, 0, v1.compareTo(v2));
+		assertEquals("Using first comparator " + c + ". " + v2 + " compare to "
+				+ v1, 0, v2.compareTo(v1));
+		c = v2.getComparator();
+		assertEquals("Using second comparator " + c + ". " + v1
+				+ " compare to " + v2, 0, v1.compareTo(v2));
+		assertEquals("Using second comparator " + c + ". " + v2, 0, v2
+				.compareTo(v1));
+	}
+
 	/**
 	 * @param less
 	 * @param more
@@ -86,17 +194,17 @@
 	private void assertSymetricComparator(Version less, Version more) {
 		Comparator c = less.getComparator();
 		assertTrue("Using comparator " + c + " of the lesser. " + less
-				+ " compare to " + more + " shoule be <0 but was "
+				+ " compare to " + more + " should be <0 but was "
 				+ less.compareTo(more), less.compareTo(more) < 0);
 		assertTrue("Using comparator " + c + " ofthe lesser. " + more
-				+ " compare to " + less + " shoule be <0 but was "
+				+ " compare to " + less + " should be <0 but was "
 				+ more.compareTo(less), more.compareTo(less) > 0);
 		c = more.getComparator();
 		assertTrue("Using comparator " + c + " of the greator. " + less
-				+ " compare to " + more + " shoule be <0 but was "
+				+ " compare to " + more + " should be <0 but was "
 				+ less.compareTo(more), less.compareTo(more) < 0);
 		assertTrue("Using comparator " + c + " ofthe greator. " + more
-				+ " compare to " + less + " shoule be <0 but was "
+				+ " compare to " + less + " should be <0 but was "
 				+ more.compareTo(less), more.compareTo(less) > 0);
 	}
 
@@ -105,9 +213,9 @@
 	 * @param more
 	 */
 	private void assertSymetricCompare(Version less, Version more) {
-		assertTrue(less + " compare " + more + " shoule be <0 but was "
+		assertTrue(less + " compare " + more + " should be <0 but was "
 				+ less.compareTo(more), less.compareTo(more) < 0);
-		assertTrue(more + " compare " + less + " shoule be > 0 but was "
+		assertTrue(more + " compare " + less + " should be > 0 but was "
 				+ more.compareTo(less), more.compareTo(less) > 0);
 	}
 
@@ -115,7 +223,7 @@
 	 * @param v1
 	 * @param v2
 	 */
-	private void assertSymetricComparableZero(Version v1, Version v2) {
+	private void assertSymetricComparableEquals(Version v1, Version v2) {
 		assertEquals(v1 + " compare " + v2, 0, v1.compareTo(v2));
 		assertEquals(v2 + " compare " + v1, 0, v2.compareTo(v1));
 	}
@@ -151,20 +259,22 @@
 	 * @param v1
 	 * @param v2
 	 */
-	public void assertSymetricNotEquals(Version v1, Version v2) {
+	private void assertSymetricNotEquals(Version v1, Version v2) {
 		assertTrue(v2 + " should not equals " + v1, !v2.equals(v1));
 		assertTrue(v1 + " should not equals " + v2, !v1.equals(v2));
 	}
 
 	/**
-	 * assert v1.eqauls(v2) && v2.equals(v1)
+	 * assert v1.eqauls(v2) && v2.equals(v1) and v1.hashCode == v2.hashCode
 	 * 
 	 * @param v1
 	 * @param v2
 	 */
-	public void assertSymetricEquals(Version v1, Version v2) {
+	private void assertSymetricEquals(Version v1, Version v2) {
 		assertEquals(v2 + " should equal " + v1, v2, v1);
 		assertEquals(v1 + " should equal " + v2, v1, v2);
+		assertEquals("hashcode of " + v1 + " and " + v2, v1.hashCode(), v2
+				.hashCode());
 	}
 
 	/**

Mime
View raw message