forked from vipshop/vjtools
-
Notifications
You must be signed in to change notification settings - Fork 0
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 vipshop#143 from Diffblue-benchmarks/add-unit-tests
Add unit tests for VJTOP
- Loading branch information
Showing
3 changed files
with
380 additions
and
0 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
249 changes: 249 additions & 0 deletions
249
vjtop/src/test/java/com/vip/vjtools/vjtop/util/FormatsTest.java
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,249 @@ | ||
package com.vip.vjtools.vjtop.util; | ||
|
||
import com.vip.vjtools.vjtop.WarningRule.LongWarning; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import java.util.ArrayList; | ||
|
||
public class FormatsTest { | ||
|
||
@Rule public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void joinInput0NotNullOutputNotNull() { | ||
|
||
// Arrange | ||
final ArrayList<String> list = new ArrayList<String>(); | ||
final String delim = "AAAAAAAA"; | ||
|
||
// Act | ||
final String retval = Formats.join(list, delim); | ||
|
||
// Assert result | ||
Assert.assertEquals("", retval); | ||
} | ||
|
||
@Test | ||
public void joinInput1NullOutputNotNull() { | ||
|
||
// Arrange | ||
final ArrayList<String> list = new ArrayList<String>(); | ||
list.add(""); | ||
final String delim = null; | ||
|
||
// Act | ||
final String retval = Formats.join(list, delim); | ||
|
||
// Assert result | ||
Assert.assertEquals("", retval); | ||
} | ||
|
||
@Test | ||
public void leftStrInputNotNullNegativeOutputStringIndexOutOfBoundsException() { | ||
|
||
// Arrange | ||
final String str = "!"; | ||
final int length = -536_870_911; | ||
|
||
// Act | ||
thrown.expect(StringIndexOutOfBoundsException.class); | ||
Formats.leftStr(str, length); | ||
|
||
// Method is not expected to return due to exception thrown | ||
} | ||
|
||
@Test | ||
public void leftStrInputNotNullZeroOutputNotNull() { | ||
|
||
// Arrange | ||
final String str = "!!!!!!!!"; | ||
final int length = 0; | ||
|
||
// Act | ||
final String retval = Formats.leftStr(str, length); | ||
|
||
// Assert result | ||
Assert.assertEquals("", retval); | ||
} | ||
|
||
@Test | ||
public void rightStrInputNotNullNegativeOutputStringIndexOutOfBoundsException() { | ||
|
||
// Arrange | ||
final String str = "!!!!!!!!"; | ||
final int length = -1_048_568; | ||
|
||
// Act | ||
thrown.expect(StringIndexOutOfBoundsException.class); | ||
Formats.rightStr(str, length); | ||
|
||
// Method is not expected to return due to exception thrown | ||
} | ||
|
||
@Test | ||
public void rightStrInputNotNullPositiveOutputNotNull() { | ||
|
||
// Arrange | ||
final String str = "!!!!!!!!"; | ||
final int length = 2_147_221_512; | ||
|
||
// Act | ||
final String retval = Formats.rightStr(str, length); | ||
|
||
// Assert result | ||
Assert.assertEquals("!!!!!!!!", retval); | ||
} | ||
|
||
@Test | ||
public void shortNameInputNotNullPositivePositiveOutputNotNull() { | ||
|
||
// Arrange | ||
final String str = "!"; | ||
final int length = 1; | ||
final int rightLength = 6; | ||
|
||
// Act | ||
final String retval = Formats.shortName(str, length, rightLength); | ||
|
||
// Assert result | ||
Assert.assertEquals("!", retval); | ||
} | ||
|
||
@Test | ||
public void shortNameInputNotNullPositiveZeroOutputNotNull() { | ||
|
||
// Arrange | ||
final String str = "!!!!!!!!!!"; | ||
final int length = 4; | ||
final int rightLength = 0; | ||
|
||
// Act | ||
final String retval = Formats.shortName(str, length, rightLength); | ||
|
||
// Assert result | ||
Assert.assertEquals("!...", retval); | ||
} | ||
|
||
@Test | ||
public void shortNameInputNotNullZeroNegativeOutputStringIndexOutOfBoundsException() { | ||
|
||
// Arrange | ||
final String str = "!!!!!!!!!!"; | ||
final int length = 0; | ||
final int rightLength = -19; | ||
|
||
// Act | ||
thrown.expect(StringIndexOutOfBoundsException.class); | ||
Formats.shortName(str, length, rightLength); | ||
|
||
// Method is not expected to return due to exception thrown | ||
} | ||
|
||
@Test | ||
public void toFixLengthSizeUnitInputNullOutputNotNull() { | ||
|
||
// Arrange | ||
final Long size = null; | ||
|
||
// Act | ||
final String retval = Formats.toFixLengthSizeUnit(size); | ||
|
||
// Assert result | ||
Assert.assertEquals("NaN", retval); | ||
} | ||
|
||
@Test | ||
public void toFixLengthSizeUnitInputPositiveOutputNotNull() { | ||
|
||
// Arrange | ||
final Long size = 4_611_686_018_427_387_906L; | ||
|
||
// Act | ||
final String retval = Formats.toFixLengthSizeUnit(size); | ||
|
||
// Assert result | ||
Assert.assertEquals("4194304t", retval); | ||
} | ||
|
||
@Test | ||
public void toMBInputNegativeOutputNotNull() { | ||
|
||
// Arrange | ||
final long bytes = -8L; | ||
|
||
// Act | ||
final String retval = Formats.toMB(bytes); | ||
|
||
// Assert result | ||
Assert.assertEquals("NaN", retval); | ||
} | ||
|
||
@Test | ||
public void toMBInputPositiveOutputNotNull() { | ||
|
||
// Arrange | ||
final long bytes = 8L; | ||
|
||
// Act | ||
final String retval = Formats.toMB(bytes); | ||
|
||
// Assert result | ||
Assert.assertEquals("0m", retval); | ||
} | ||
|
||
@Test | ||
public void toSizeUnitInputNegativeOutputNotNull() { | ||
|
||
// Arrange | ||
final Long size = -1023L; | ||
|
||
// Act | ||
final String retval = Formats.toSizeUnit(size); | ||
|
||
// Assert result | ||
Assert.assertEquals("-1023", retval); | ||
} | ||
|
||
@Test | ||
public void toSizeUnitInputNullOutputNotNull() { | ||
|
||
// Arrange | ||
final Long size = null; | ||
|
||
// Act | ||
final String retval = Formats.toSizeUnit(size); | ||
|
||
// Assert result | ||
Assert.assertEquals("NaN", retval); | ||
} | ||
|
||
@Test | ||
public void toSizeUnitInputPositiveOutputNotNull() { | ||
|
||
// Arrange | ||
final Long size = 45_312L; | ||
|
||
// Act | ||
final String retval = Formats.toSizeUnit(size); | ||
|
||
// Assert result | ||
Assert.assertEquals("44k", retval); | ||
} | ||
|
||
@Test | ||
public void toSizeUnitWithColorInputNullNullOutputNullPointerException() { | ||
|
||
// Arrange | ||
final Long size = null; | ||
final LongWarning warning = null; | ||
|
||
// Act | ||
thrown.expect(NullPointerException.class); | ||
Formats.toSizeUnitWithColor(size, warning); | ||
|
||
// Method is not expected to return due to exception thrown | ||
} | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
vjtop/src/test/java/com/vip/vjtools/vjtop/util/UtilsTest.java
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,124 @@ | ||
package com.vip.vjtools.vjtop.util; | ||
|
||
import com.vip.vjtools.vjtop.util.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class UtilsTest { | ||
|
||
@Test | ||
public void calcLoadInputNegativeZeroZeroOutputZero() { | ||
|
||
// Arrange | ||
final Long deltaCpuTime = -4_194_304L; | ||
final long deltaUptime = 0L; | ||
final long factor = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime, factor); | ||
|
||
// Assert result | ||
Assert.assertEquals(0.0, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcLoadInputPositivePositiveOutputPositive() { | ||
|
||
// Arrange | ||
final long deltaCpuTime = 558_348_370L; | ||
final long deltaUptime = 1L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime); | ||
|
||
// Assert result | ||
Assert.assertEquals(0x1.a0008001p+35 /* 5.58348e+10 */, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcLoadInputPositivePositiveZeroOutputPositiveInfinity() { | ||
|
||
// Arrange | ||
final Long deltaCpuTime = 4_194_304L; | ||
final long deltaUptime = 4_611_686_018_427_387_904L; | ||
final long factor = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime, factor); | ||
|
||
// Assert result | ||
Assert.assertEquals(Double.POSITIVE_INFINITY, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcLoadInputPositiveZeroOutputZero() { | ||
|
||
// Arrange | ||
final long deltaCpuTime = 558_348_370L; | ||
final long deltaUptime = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime); | ||
|
||
// Assert result | ||
Assert.assertEquals(0.0, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcLoadInputPositiveZeroZeroOutputZero() { | ||
|
||
// Arrange | ||
final Long deltaCpuTime = 4_194_304L; | ||
final long deltaUptime = 0L; | ||
final long factor = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime, factor); | ||
|
||
// Assert result | ||
Assert.assertEquals(0.0, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcLoadInputZeroZeroOutputZero() { | ||
|
||
// Arrange | ||
final long deltaCpuTime = 0L; | ||
final long deltaUptime = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcLoad(deltaCpuTime, deltaUptime); | ||
|
||
// Assert result | ||
Assert.assertEquals(0.0, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcMemoryUtilizationInputNegativePositiveOutputNegative() { | ||
|
||
// Arrange | ||
final Long threadBytes = -507_680_768_073_012_547L; | ||
final long totalBytes = 1_147_301_170_758_571_992L; | ||
|
||
// Act | ||
final double retval = Utils.calcMemoryUtilization(threadBytes, totalBytes); | ||
|
||
// Assert result | ||
Assert.assertEquals(-0x1.6200000024f82p+5 /* -44.25 */, retval, 0.0); | ||
} | ||
|
||
@Test | ||
public void calcMemoryUtilizationInputPositiveZeroOutputZero() { | ||
|
||
// Arrange | ||
final Long threadBytes = 1L; | ||
final long totalBytes = 0L; | ||
|
||
// Act | ||
final double retval = Utils.calcMemoryUtilization(threadBytes, totalBytes); | ||
|
||
// Assert result | ||
Assert.assertEquals(0.0, retval, 0.0); | ||
} | ||
|
||
} |