-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
versionCompare()
needs to have a trinary result
- Added tests for `versionCompare()`
- Loading branch information
Showing
4 changed files
with
47 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestVersionCompare(t *testing.T) { | ||
versionTests := []struct { | ||
left string | ||
right string | ||
result int | ||
}{ | ||
{"0.9.9", "1.0.0", 1}, | ||
{"0.1.0", "0.2.0", 1}, | ||
{"0.3.0", "0.3.1", 1}, | ||
{"0.1.0", "0.1.0", 0}, | ||
{"1.0.0", "0.9.9", -1}, | ||
{"0.2.0", "0.1.0", -1}, | ||
{"0.3.1", "0.3.0", -1}, | ||
} | ||
|
||
for _, tt := range versionTests { | ||
if result := versionCompare(tt.left, tt.right); result != tt.result { | ||
t.Errorf("versionCompare(%s, %s) => %d, wanted: %d", tt.left, tt.right, result, tt.result) | ||
} | ||
} | ||
} |
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