Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 30th, 2012  |  syntax: None  |  size: 1.01 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package foo;
  2.  
  3. import static junit.framework.Assert.assertEquals;
  4. import static junit.framework.Assert.assertFalse;
  5. import static junit.framework.Assert.assertTrue;
  6. import static foo.Version.compare;
  7.  
  8. import org.junit.Before;
  9. import org.junit.Test;
  10.  
  11. /**
  12.  * @author yclian
  13.  * @since 20120507
  14.  * @version 20120507
  15.  */
  16. public class VersionTest {
  17.  
  18.     @Before
  19.     public void setUp() {}
  20.  
  21.     @Test
  22.     public void testCompare() {
  23.         assertEquals(-1, compare("1.0.1").with("1.0.2"));
  24.         assertEquals(1, compare("1.0.2.1").with("1.0.2"));
  25.         assertTrue(compare("1.0.2").eq("1.0.2"));
  26.     }
  27.  
  28.     @Test
  29.     public void testApproximation() {
  30.         assertTrue(compare("1.0.2").agt("1.0")); // ~> 1.0 => >= 1.0 && < 2.0
  31.         assertFalse(compare("2.0").agt("1.0"));
  32.         assertTrue(compare("1.9").agt("1.0")); // ~> 1.0 => >= 1.0 && < 2.0
  33.         assertFalse(compare("0.9").agt("1.0"));
  34.         assertTrue(compare("1.0.2").agt("1.0.2")); // ~> 1.0.2 => >= 1.0.2 && < 1.1
  35.         assertFalse(compare("1.2").agt("1.0.2"));
  36.     }
  37. }