Skip to content

Commit

Permalink
correct zero-padded max version calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwinckles committed Jan 28, 2022
1 parent b924517 commit bcc7254
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public VersionNum(long versionNumber, int zeroPaddingWidth) {
if (zeroPaddingWidth == 0) {
maxVersion = Long.MAX_VALUE;
} else {
maxVersion = (10 * (zeroPaddingWidth - 1)) - 1;
maxVersion = (long) Math.pow(10, zeroPaddingWidth - 1) - 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void shouldIncrementVersionWhenNoPadding() {

@Test
public void shouldIncrementVersionWhenHasPadding() {
var versionNum = VersionNum.fromString("v03");
var versionNum = VersionNum.fromString("v00039");
var nextVersion = versionNum.nextVersionNum();
assertEquals("v03", versionNum.toString());
assertEquals("v04", nextVersion.toString());
assertEquals("v00039", versionNum.toString());
assertEquals("v00040", nextVersion.toString());
}

@Test
Expand All @@ -70,7 +70,7 @@ public void shouldFailDecrementWhenPreviousVersion0() {

@Test
public void shouldFailIncrementWhenNextVersionIsIllegalPaddedNumber() {
var versionNum = VersionNum.fromString("v09");
var versionNum = VersionNum.fromString("v09999");
assertThrows(InvalidVersionException.class, versionNum::nextVersionNum);
}

Expand Down

0 comments on commit bcc7254

Please sign in to comment.