### Question:
ProgramVersion implements Comparable<ProgramVersion> { public static int compareVersions(String version, String other) { return ProgramVersion.of(version).compareTo(ProgramVersion.of(other)); } ProgramVersion(String version); @SuppressWarnings("unchecked") final void parseVersion(String version); static ProgramVersion of(String version); static int compareVersions(String version, String other); String toCanonicalString(); @Override int compareTo(ProgramVersion v); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void testCompareMajorMinor() throws Exception { assertTrue(compareVersions("1.0", "1.0") == 0); assertTrue(compareVersions("1.0", "1.1") < 0); assertTrue(compareVersions("1.0", "0.9") > 0); }
@Test public void testCompareMajorMinorPatch() { assertTrue(compareVersions("1.0", "1.0.1") < 0); assertTrue(compareVersions("1.0.1", "1.1") < 0); assertTrue(compareVersions("1.1", "1.1.0") == 0); assertTrue(compareVersions("1.1", "1.0.9.150") > 0); }
@Test public void testCompareMajorMinorLetters() { assertTrue(compareVersions("1.a", "1.a.0") == 0); assertTrue(compareVersions("1.a", "1.b") < 0); assertTrue(compareVersions("1.1", "1.a") > 0); assertTrue(compareVersions("1.g", "1.1") < 0); assertTrue(compareVersions("1.0", "1.a") < 0); }
@Test public void testCompareQualifier() { assertTrue(compareVersions("1.0-alpha", "1.0-alpha") == 0); assertTrue(compareVersions("1.0-alpha", "1.0-beta") < 0); assertTrue(compareVersions("1.0-beta", "1.0-final") < 0); assertTrue(compareVersions("1.0", "1.0-beta") > 0); assertTrue(compareVersions("1.0-alpha", "1.0.1-alpha") < 0); assertTrue(compareVersions("1.0.1-final", "1.1-beta") < 0); assertTrue(compareVersions("1.a-beta", "2.0-final") < 0); }
@Test public void testCompareQualifierBuildnumber() { assertTrue(compareVersions("1.1-alpha", "1.1-alpha-20140414") < 0); assertTrue(compareVersions("1.1-alpha-20140414", "1.1.0-alpha-20140417") < 0); assertTrue(compareVersions("1.1-beta", "1.1.0-alpha-20140417") > 0); assertTrue(compareVersions("1.1-beta", "1.1") < 0); assertTrue(compareVersions("1.1.0", "1.1.1-alpha") < 0); }