Skip to content

Commit

Permalink
Simplify conversions & casts (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlosna authored Sep 22, 2022
1 parent d58084f commit 246a60b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ public String toString() {
public enum ByteUnit {
BYTE(1, "bytes"),
KiB(1024L, "kibibytes"),
MiB((long) Math.pow((double) 1024L, (double) 2L), "mebibytes"),
GiB((long) Math.pow((double) 1024L, (double) 3L), "gibibytes"),
TiB((long) Math.pow((double) 1024L, (double) 4L), "tebibytes"),
PiB((long) Math.pow((double) 1024L, (double) 5L), "pebibytes");
MiB((long) Math.pow(1024.0, 2.0), "mebibytes"),
GiB((long) Math.pow(1024.0, 3.0), "gibibytes"),
TiB((long) Math.pow(1024.0, 4.0), "tebibytes"),
PiB((long) Math.pow(1024.0, 5.0), "pebibytes");

private final long multiplier;
private final String suffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,28 @@ public void testParseKibiBytes() {

@Test
public void testParseMibiBytes() {
assertStringsEqualToBytes((long) (Math.pow(1024.0, 2.0) * 10.0), "10m", "10mb", "10 mibibyte", "10 mibibytes");
assertStringsEqualToBytes(10L * 1024L * 1024L, "10m", "10mb", "10 mibibyte", "10 " + "mibibytes");
}

@Test
public void testParseMebiBytes() {
assertStringsEqualToBytes((long) (Math.pow(1024.0, 2.0) * 10.0), "10m", "10mb", "10 mebibyte", "10 mebibytes");
assertStringsEqualToBytes(10L * 1024L * 1024L, "10m", "10mb", "10 mebibyte", "10 mebibytes");
}

@Test
public void testParseGibiBytes() {
assertStringsEqualToBytes((long) (Math.pow(1024.0, 3.0) * 10.0), "10g", "10gb", "10 gibibyte", "10 gibibytes");
assertStringsEqualToBytes(10L * 1024L * 1024L * 1024L, "10g", "10gb", "10 gibibyte", "10 gibibytes");
}

@Test
public void testParseTebiBytes() {
assertStringsEqualToBytes((long) (Math.pow(1024.0, 4.0) * 10.0), "10t", "10tb", "10 tebibyte", "10 tebibytes");
assertStringsEqualToBytes(10L * 1024L * 1024L * 1024L * 1024L, "10t", "10tb", "10 tebibyte", "10 tebibytes");
}

@Test
public void testParsePebiBytes() {
assertStringsEqualToBytes((long) (Math.pow(1024.0, 5.0) * 10.0), "10p", "10pb", "10 pebibyte", "10 pebibytes");
assertStringsEqualToBytes(
10L * 1024L * 1024L * 1024L * 1024L * 1024L, "10p", "10pb", "10 pebibyte", "10 " + "pebibytes");
}

@Test
Expand Down

0 comments on commit 246a60b

Please sign in to comment.