mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-27 09:18:55 +01:00
Add GreaterThan method for comparing versions
This commit is contained in:
parent
6cfbec4823
commit
47bdc966b2
@ -642,3 +642,15 @@ func TestVersionLessThan(t *testing.T) {
|
|||||||
require.True(t, parsedVersion{1, 200}.lessThan(parsedVersion{1, 205}))
|
require.True(t, parsedVersion{1, 200}.lessThan(parsedVersion{1, 205}))
|
||||||
require.True(t, parsedVersion{0, 200}.lessThan(parsedVersion{1, 1}))
|
require.True(t, parsedVersion{0, 200}.lessThan(parsedVersion{1, 1}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVersionGreaterThan(t *testing.T) {
|
||||||
|
require.False(t, parsedVersion{0, 200}.greaterThan(parsedVersion{0, 200}))
|
||||||
|
require.False(t, parsedVersion{1, 200}.greaterThan(parsedVersion{1, 200}))
|
||||||
|
require.True(t, parsedVersion{0, 201}.greaterThan(parsedVersion{0, 200}))
|
||||||
|
require.True(t, parsedVersion{1, 0}.greaterThan(parsedVersion{0, 200}))
|
||||||
|
require.True(t, parsedVersion{1, 1}.greaterThan(parsedVersion{1, 0}))
|
||||||
|
require.False(t, parsedVersion{0, 199}.greaterThan(parsedVersion{0, 200}))
|
||||||
|
require.False(t, parsedVersion{0, 200}.greaterThan(parsedVersion{0, 205}))
|
||||||
|
require.False(t, parsedVersion{1, 200}.greaterThan(parsedVersion{1, 205}))
|
||||||
|
require.False(t, parsedVersion{0, 200}.greaterThan(parsedVersion{1, 1}))
|
||||||
|
}
|
||||||
|
@ -105,6 +105,13 @@ type parsedVersion struct {
|
|||||||
minorVersion int
|
minorVersion int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pv parsedVersion) greaterThan(other parsedVersion) bool {
|
||||||
|
if pv.majorVersion == other.majorVersion && pv.minorVersion == other.minorVersion {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return !pv.lessThan(other)
|
||||||
|
}
|
||||||
|
|
||||||
func (pv parsedVersion) lessThan(other parsedVersion) bool {
|
func (pv parsedVersion) lessThan(other parsedVersion) bool {
|
||||||
if pv.majorVersion != other.majorVersion {
|
if pv.majorVersion != other.majorVersion {
|
||||||
return pv.majorVersion < other.majorVersion
|
return pv.majorVersion < other.majorVersion
|
||||||
|
Loading…
Reference in New Issue
Block a user