Changeset d8417cb


Ignore:
Timestamp:
Dec 9, 2012 1:28:06 PM (8 years ago)
Author:
zab <zab@…>
Branches:
master
Children:
32a8bb7
Parents:
863a05b
Message:

more tests for VersionComparator?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/test/scalatest/net/i2p/util/VersionComparatorSpec.scala

    r863a05b rd8417cb  
    44import org.scalatest.matchers.ShouldMatchers
    55
     6
    67class VersionComparatorSpec extends FunSpec with ShouldMatchers {
    7     val vc = new VersionComparator
    8 
    9     describe("A VersionComparator") {
    10         it("should find that 0.1.2 equals 0.1.2") {
    11             vc.compare("0.1.2", "0.1.2") should equal (0)
    12         }
    13         it("should find that 0.1.2 is less than 0.1.3") {
    14             vc.compare("0.1.2", "0.1.3") should equal (-1)
    15         }
    16         it("should find that 0.1.3 is greater than 0.1.2") {
    17             vc.compare("0.1.3", "0.1.2") should equal (1)
    18         }
    19         it("should find that 0.1.2.3.4 is greater than 0.1.2") {
    20             vc.compare("0.1.2.3.4", "0.1.2") should equal (1)
    21         }
    22         it("should find that 0.1.2 is less than 0.1.2.3.4") {
    23             vc.compare("0.1.2", "0.1.2.3.4") should equal (-1)
    24         }
    25         it("should find that 0.1.3 is greater than 0.1.2.3.4") {
    26             vc.compare("0.1.3", "0.1.2.3.4") should equal (1)
    27         }
    28         it("should find that 0.1.2 is equal to 0-1-2") {
    29             vc.compare("0.1.2", "0-1-2") should equal (0)
    30         }
    31         it("should find that 0.1.2 is equal to 0_1_2") {
    32             vc.compare("0.1.2", "0_1_2") should equal (0)
    33         }
    34         it("should find that 0.1.2-foo is equal to 0.1.2-bar") {
    35             vc.compare("0.1.2-foo", "0.1.2-bar") should equal (0)
    36         }
    37         it("should find that -0.1.2 is less than -0.1.3") {
    38             vc.compare("-0.1.2", "-0.1.3") should equal (-1)
    39         }
    40         it("should find that 0..2 is greater than 0.1.2") {
    41             vc.compare("0..2", "0.1.2") should equal (1)
    42         }
    43         it("should find that 0.1.2 is less than 0..2") {
    44             vc.compare("0.1.2", "0..2") should equal (-1)
     8 
     9    private val vc = new VersionComparator
     10   
     11    private def comp(desc : String, A : String, B : String, result : Int) = {
     12        it("should find that " + A +" " + desc +" " + B) {
     13            vc.compare(A,B) should equal (result)
    4514        }
    4615    }
     16   
     17    private def less(A : String, B : String) =
     18      comp("is less than", A, B, -1)
     19   
     20    private def more(A : String, B : String) =
     21      comp("is more than", A, B, 1)
     22     
     23    private def same(A : String, B : String) =
     24      comp("equals", A, B, 0)
     25   
     26    private def invalid(A : String, B : String) = {
     27      it("should throw IAE while comparing "+A+" and "+B) {
     28          intercept[IllegalArgumentException] {
     29              vc.compare(A,B)
     30          }
     31      }
     32    }
     33   
     34    describe("A VersionComparator") {
     35        same("0.1.2","0.1.2")
     36        less("0.1.2","0.1.3")
     37        more("0.1.3","0.1.2")
     38        more("0.1.2.3.4", "0.1.2")
     39        less("0.1.2", "0.1.2.3.4")
     40        more("0.1.3", "0.1.2.3.4")
     41        same("0.1.2","0-1-2")
     42        same("0.1.2","0_1_2")
     43        same("0.1.2-foo", "0.1.2-bar")
     44
     45        // this should be the same, no? --zab
     46        less("0.1.2","0.1.2.0")
     47       
     48        /*********
     49        I think everything below this line should be invalid --zab.
     50        *********/
     51        same("",".")
     52        less("-0.1.2", "-0.1.3")
     53        more("0..2", "0.1.2")
     54        less("0.1.2", "0..2")
     55        same("asdf","fdsa")
     56        same("---","___")
     57        same("1.2.3","0001.0002.0003")
     58        more("as123$Aw4423-234","asdfq45#11--_")
     59       
     60        // non-ascii string
     61        val byteArray = new Array[Byte](10)
     62        byteArray(5) = 1
     63        byteArray(6) = 10
     64        val nonAscii = new String(byteArray)
     65        same(nonAscii,"")
     66       
     67        // huge value, can't fit in a long
     68        val huge = String.valueOf(Long.MaxValue)+"0000.0";
     69        less(huge,"1.2")
     70    }
    4771}
Note: See TracChangeset for help on using the changeset viewer.