-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #726 from open-horizon/issue_607
issue 607: Rework unit-test for VersionSuite
- Loading branch information
Showing
8 changed files
with
150 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.125.1 | ||
2.125.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
src/test/scala/org/openhorizon/exchangeapi/VersionSuite.scala
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/test/scala/org/openhorizon/exchangeapi/utility/version/TestVersion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//package org.openhorizon.exchangeapi.route.version | ||
|
||
package org.openhorizon.exchangeapi | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
import org.junit.runner.RunWith | ||
import org.scalatestplus.junit.JUnitRunner | ||
import org.openhorizon.exchangeapi._ | ||
import org.openhorizon.exchangeapi.utility.{Version, VersionRange} | ||
|
||
/** | ||
* Tests for the Version | ||
*/ | ||
@RunWith(classOf[JUnitRunner]) | ||
class TestVersion extends AnyFunSuite with Matchers { | ||
test("Version validity tests") { | ||
// Valid versions | ||
assert(Version("1.2.3").isValid) | ||
assert(Version("1.0.0").isValid) | ||
assert(Version("0.0.0").isValid) | ||
assert(Version("infinity").isValid) | ||
assert(Version("Infinity").isValid) | ||
assert(Version("INFINITY").isValid) | ||
|
||
// Invalid versions | ||
assert(!Version("1.2.3.4").isValid) // Too many segments | ||
assert(!Version("x").isValid) // Non-numeric | ||
assert(!Version("").isValid) // Empty string | ||
assert(!Version("1.2.a").isValid) // Invalid character | ||
assert(!Version("1..2").isValid) // Double dot | ||
assert(!Version("1.2..3").isValid) // Double dot in the middle | ||
assert(!Version("1.2.-3").isValid) // Negative number | ||
assert(!Version("-1.2.3").isValid) // Negative number at start | ||
assert(!Version("1.2.3-").isValid) // Hyphen at the end | ||
} | ||
|
||
test("Version string representation") { | ||
assert(Version("1.2.3").toString === "1.2.3") | ||
assert(Version("infinity").toString === "infinity") | ||
assert(Version("0.0.0").toString === "0.0.0") | ||
} | ||
|
||
test("Version equality tests") { | ||
assert(Version("1.0.0") === Version("1")) | ||
assert(Version("1.2.3") === Version("1.2.3")) | ||
assert(Version("1.2.3") != Version("1.3.2")) | ||
assert(Version("0.0.0") === Version("0.0.0")) | ||
} | ||
|
||
test("Version comparison tests") { | ||
assert(Version("2.2.3") > Version("1.3.2")) | ||
assert(Version("1.2.3") > Version("1.2.2")) | ||
assert(Version("1.2.3") >= Version("1.2.3")) | ||
assert(Version("1.3.3") >= Version("1.2.3")) | ||
assert(!(Version("1.2.2") >= Version("1.2.3"))) | ||
|
||
assert(Version("infinity") > Version("1.3.2")) | ||
assert(!(Version("1.2.3") > Version("INFINITY"))) | ||
|
||
// Testing with leading zeros | ||
assert(Version("1.2.3") === Version("01.2.3")) | ||
assert(Version("1.2.3") > Version("1.2.02")) | ||
assert(Version("1.2.3") >= Version("1.02.3")) | ||
} | ||
|
||
test("Edge cases and performance tests") { | ||
// Check upper limits | ||
assert(Version("999999999.999999999.999999999").isValid) | ||
|
||
// Check behavior with invalid but interesting formats | ||
assert(Version("1.0.0").isValid) | ||
assert(Version("1.0").isValid) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/scala/org/openhorizon/exchangeapi/utility/version/TestVersionRange.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.openhorizon.exchangeapi | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
import org.junit.runner.RunWith | ||
import org.scalatestplus.junit.JUnitRunner | ||
import org.openhorizon.exchangeapi._ | ||
import org.openhorizon.exchangeapi.utility.{Version, VersionRange} | ||
|
||
/** | ||
* Tests for the Version Range | ||
*/ | ||
@RunWith(classOf[JUnitRunner]) | ||
class TestVersionRange extends AnyFunSuite with Matchers { | ||
test("VersionRange tests") { | ||
// Basic string representation tests | ||
assert(VersionRange("1").toString === "[1.0.0,infinity)") | ||
assert(VersionRange("1,infinity]").toString === "[1.0.0,infinity]") | ||
assert(VersionRange("1.2,2").toString === "[1.2.0,2.0.0)") | ||
|
||
// Validity tests | ||
assert(!VersionRange("1,x").isValid) // Invalid due to non-numeric | ||
assert(VersionRange("1,infinity]").isValid) // Valid range with infinity | ||
assert(VersionRange("1,INFINITY]").isValid) // Case insensitivity | ||
assert(VersionRange("1").isValid) // Single version as valid range | ||
assert(VersionRange("1.0.0").isValid) // Valid single version | ||
assert(VersionRange("1.2,2.0.0").isValid) // Valid range | ||
|
||
// Inclusion tests | ||
assert(Version("1.2") in VersionRange("1")) // Included in range starting with 1 | ||
assert(Version("1.2") notIn VersionRange("1, 1.1")) // Not included in this range | ||
assert(Version("1.2") in VersionRange("1.2")) // Exact match | ||
assert(Version("1.2") notIn VersionRange("(1.2")) // Not included due to exclusive start | ||
assert(Version("1.2.3") in VersionRange("1.2,1.2.3]")) // Included in inclusive end range | ||
assert(Version("1.2.3") in VersionRange("1.2")) // Included in single version range | ||
assert(Version("1.2.3") in VersionRange("1.2,")) // Open-ended range | ||
assert(Version("1.2.3") notIn VersionRange("(1.2,1.2.3")) // Exclusive lower bound | ||
assert(Version("1.2.3") notIn VersionRange("(1.2,1.2.3)")) // Exclusive bounds | ||
assert(Version("1.2.3") in VersionRange("1.2,infinity")) // Open-ended to infinity | ||
assert(Version("1.2.3") in VersionRange("1.2,INFINITY")) // Case insensitivity for infinity | ||
assert(Version("1.2.3") in VersionRange("1.2,1.4")) // Included in this range | ||
assert(Version("1.2.3") in VersionRange("[1.0.0,2.0.0)")) // Within valid range | ||
assert(Version("1.0.0") in VersionRange("[1.0.0,2.0.0)")) // Exact match | ||
assert(Version("2.0.0") notIn VersionRange("[1.0.0,2.0.0)")) // Outside range | ||
} | ||
|
||
test("Additional VersionRange edge cases") { | ||
// Test for overlapping ranges | ||
assert(Version("1.5") in VersionRange("1.0,1.6")) // In overlapping range | ||
assert(Version("1.0") in VersionRange("[1.0,1.5)")) // Lower bound inclusive | ||
assert(Version("1.5") in VersionRange("(1.0,2.0)")) // Upper bound exclusive | ||
assert(Version("1.0") notIn VersionRange("(1.0,1.5)")) // Exclusive lower bound | ||
|
||
// Edge case with negative version numbers | ||
assert(!VersionRange("-1.0,0").isValid) // Invalid range with negative version | ||
} | ||
|
||
test("Invalid VersionRange formats") { | ||
assert(!VersionRange("").isValid) // Empty string | ||
assert(!VersionRange(",2").isValid) // Invalid start | ||
assert(!VersionRange("1,2,3").isValid) // Too many elements | ||
assert(!VersionRange("1.0,)2.0").isValid) // Unmatched parentheses and invalid character | ||
} | ||
} |