Skip to content

Initial implementation of ByteCountFormatter #892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2017
Merged

Initial implementation of ByteCountFormatter #892

merged 2 commits into from
Mar 3, 2017

Conversation

DunnCoding
Copy link
Contributor

Implemented ByteCountFormatter and created tests.

All tests run and pass on MacOS.

@parkera
Copy link
Contributor

parkera commented Feb 24, 2017

@swift-ci please test

@@ -47,48 +47,261 @@ open class ByteCountFormatter : Formatter {
}

public required init?(coder: NSCoder) {
NSUnimplemented()
super.init(coder: coder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably leave this as unimplemented, because clearly the byte count formatter should be restoring settings like allowedUnits, countStyle, etc. from the archive.

XCTAssertEqual(formatter.string(fromByteCount: 6000000000000000000), "0 YB")
XCTAssertEqual(formatter.string(fromByteCount: 0), "Zero KB")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look pretty comprehensive, but I wanted to contribute the tests we have for this as well. Here is a rough table:


if KilobyteIs1000, style = decimal
else if KilobyteIs1024, style = binary
else if DisplayMemorySize, style = memory
else, style = file

if !KilobyteIs1000 && !KilobyteIs1024 && !DisplayMemorySize, use simple 'stringFromByteCount:countStyle:'

if FinderAlgorithmForFractionDigits, adaptive = true
else if ThreeOrMoreSignificantDigits, adaptive = false

if SpecialZeroHandling, allowsNonnumericFormatting = true
else, allowsNonnumericFormatting = false

if IncludeActualByteCount, includesActualByteCount = true

if ZeroPadFractionDigits, zeroPadsFractionDigits = true

if NumberOnly && UnitOnly, includesUnit = false
if !NumberOnly && !UnitOnly, includesCount = false

// --- tests


0LL  options:0 expecting:"Zero KB"
0LL  options:NSByteCountFormatterUseGB expecting:"Zero KB"
0LL  options:NoSpecialZeroHandling expecting:"0 bytes"
0LL  options:NoSpecialZeroHandling | NSByteCountFormatterUseGB expecting:"0 GB"




1LL  options:0 expecting:"1 byte"
1LL  options:NSByteCountFormatterUseKB expecting:"0 KB"
1LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"0 KB"
1LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
1LL  options:ThreeOrMoreSignificantDigits expecting:"1 byte"
1LL  options:NSByteCountFormatterUseKB | ThreeOrMoreSignificantDigits expecting:"0.001 KB"
1LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.001 KB"
1LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.000000001 GB"




550000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550,000 KB"
5500000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

550000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 MB"
5500000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

55LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"0 KB"
550LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"1 KB"
5500LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"6 KB"
55000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55 KB"
550000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 KB"
5500000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5.5 MB"
55000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55 MB"
550000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 MB"
5500000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

55LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.055 KB"
550LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.55 KB"
5500LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5.5 KB"
55000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55 KB"
550000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550 KB"
5500000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5.5 MB"
55000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55 MB"
550000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550 MB"
5500000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseKB | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55,000,000 GB"

55LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55 bytes"
550LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"550 bytes"
5500LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"5,500 bytes"
55000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55,000 bytes"
550000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"550,000 bytes"
5500000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"5,500,000 bytes"
55000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55,000,000 bytes"
550000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"550,000,000 bytes"
5500000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseBytes | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

55LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
550LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
5500LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
55000LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
550000LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
5500000LL  options:NSByteCountFormatterUseGB expecting:"0.01 GB"
55000000LL  options:NSByteCountFormatterUseGB expecting:"0.06 GB"
550000000LL  options:NSByteCountFormatterUseGB expecting:"0.55 GB"
5500000000LL  options:NSByteCountFormatterUseGB expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseGB expecting:"55,000,000 GB"

55LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.000000055 GB"
550LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.00000055 GB"
5500LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.0000055 GB"
55000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.000055 GB"
550000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.00055 GB"
5500000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.0055 GB"
55000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.055 GB"
550000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"0.55 GB"
5500000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5.5 GB"
55000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55 GB"
550000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550 GB"
5500000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5,500 GB"
55000000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55,000 GB"
550000000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"550,000 GB"
5500000000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"5,500,000 GB"
55000000000000000LL  options:NSByteCountFormatterUseGB | ThreeOrMoreSignificantDigits expecting:"55,000,000 GB"




0LL  options:NumberOnly expecting:"0"
0LL  options:UnitOnly expecting:"bytes"
0LL  options:NumberOnly | NSByteCountFormatterUseYBOrHigher expecting:"0"
0LL  options:UnitOnly | NSByteCountFormatterUseYBOrHigher expecting:"YB"
1LL  options:NumberOnly expecting:"1"
1LL  options:UnitOnly expecting:"byte"
1LL  options:NumberOnly | NSByteCountFormatterUseYBOrHigher expecting:"0"
1LL  options:UnitOnly | NSByteCountFormatterUseYBOrHigher expecting:"YB"
550000000LL  options:NumberOnly expecting:"550"
550000000LL  options:UnitOnly expecting:"MB"
550000000LL  options:NumberOnly | NSByteCountFormatterUseKB expecting:"550,000"
550000000LL  options:UnitOnly | NSByteCountFormatterUseKB expecting:"KB"
550000000LL  options:NumberOnly | NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550,000"
550000000LL  options:UnitOnly | NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"KB"
550000000LL  options:NumberOnly | NSByteCountFormatterUseGB expecting:"0.55"
550000000LL  options:UnitOnly | NSByteCountFormatterUseGB | NSByteCountFormatterUseGB expecting:"GB"
550000000LL  options:NumberOnly | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550"
550000000LL  options:UnitOnly | NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"MB"




550000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550,000 KB"
5500000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5,500,000 KB"
55000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL maximum:6000 options:NSByteCountFormatterUseKB | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

550000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 MB"
5500000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500 MB"
55000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55 GB"
550000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550 GB"
5500000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500 GB"
55000000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000 GB"
550000000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"550,000 GB"
5500000000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"5,500,000 GB"
55000000000000000LL maximum:6000 options:NSByteCountFormatterUseMB | NSByteCountFormatterUseGB expecting:"55,000,000 GB"

499LL maximum:1500 options:0 expecting:"499 bytes"
900LL maximum:1500 options:0 expecting:"900 bytes"
999LL maximum:1500 options:0 expecting:"999 bytes"
1000LL maximum:1500 options:0 expecting:"1,000 bytes"
1023LL maximum:1500 options:0 expecting:"1,023 bytes"
1024LL maximum:1500 options:0 expecting:"1,024 bytes"
11999LL maximum:1500 options:0 expecting:"12 KB"
900000LL maximum:1500 options:0 expecting:"900 KB"
12345678LL maximum:1500 options:0 expecting:"12.3 MB"
123456789LL maximum:1500 options:0 expecting:"123.5 MB"
1234567898LL maximum:1500 options:0 expecting:"1,234.6 MB"
12345678987LL maximum:1500 options:0 expecting:"12.35 GB"

499LL maximum:1500000 options:0 expecting:"499 bytes"
900LL maximum:1500000 options:0 expecting:"900 bytes"
999LL maximum:1500000 options:0 expecting:"999 bytes"
1000LL maximum:1500000 options:0 expecting:"1,000 bytes"
1023LL maximum:1500000 options:0 expecting:"1,023 bytes"
1024LL maximum:1500000 options:0 expecting:"1,024 bytes"
11999LL maximum:1500000 options:0 expecting:"11,999 bytes"
900000LL maximum:1500000 options:0 expecting:"900,000 bytes"
12345678LL maximum:1500000 options:0 expecting:"12,346 KB"
123456789LL maximum:1500000 options:0 expecting:"123,457 KB"
1234567898LL maximum:1500000 options:0 expecting:"1,234,568 KB"
12345678987LL maximum:1500000 options:0 expecting:"12,345.7 MB"




499LL  options:ThreeOrMoreSignificantDigits expecting:"499 bytes"
900LL  options:ThreeOrMoreSignificantDigits expecting:"900 bytes"
999LL  options:ThreeOrMoreSignificantDigits expecting:"999 bytes"
1000LL  options:ThreeOrMoreSignificantDigits expecting:"1 KB"
1023LL  options:ThreeOrMoreSignificantDigits expecting:"1.02 KB"
1024LL  options:ThreeOrMoreSignificantDigits expecting:"1.02 KB"
11999LL  options:ThreeOrMoreSignificantDigits expecting:"12 KB"
900000LL  options:ThreeOrMoreSignificantDigits expecting:"900 KB"
12345678LL  options:ThreeOrMoreSignificantDigits expecting:"12.3 MB"
123456789LL  options:ThreeOrMoreSignificantDigits expecting:"123 MB"
1234567898LL  options:ThreeOrMoreSignificantDigits expecting:"1.23 GB"
12345678987LL  options:ThreeOrMoreSignificantDigits expecting:"12.3 GB"




499LL  options:FinderAlgorithmForFractionDigits expecting:"499 bytes"
900LL  options:FinderAlgorithmForFractionDigits expecting:"900 bytes"
999LL  options:FinderAlgorithmForFractionDigits expecting:"999 bytes"
1000LL  options:FinderAlgorithmForFractionDigits expecting:"1 KB"
1023LL  options:FinderAlgorithmForFractionDigits expecting:"1 KB"
1024LL  options:FinderAlgorithmForFractionDigits expecting:"1 KB"
11999LL  options:FinderAlgorithmForFractionDigits expecting:"12 KB"
900000LL  options:FinderAlgorithmForFractionDigits expecting:"900 KB"
12345678LL  options:FinderAlgorithmForFractionDigits expecting:"12.3 MB"
123456789LL  options:FinderAlgorithmForFractionDigits expecting:"123.5 MB"
1234567898LL  options:FinderAlgorithmForFractionDigits expecting:"1.23 GB"
12345678987LL  options:FinderAlgorithmForFractionDigits expecting:"12.35 GB"

999900000  options:FinderAlgorithmForFractionDigits expecting:"999.9 MB"


499LL  options:ZeroPadFractionDigits expecting:"499 bytes"
900LL  options:ZeroPadFractionDigits expecting:"900 bytes"
999LL  options:ZeroPadFractionDigits expecting:"999 bytes"
1000LL  options:ZeroPadFractionDigits expecting:"1 KB"
1023LL  options:ZeroPadFractionDigits expecting:"1 KB"
1024LL  options:ZeroPadFractionDigits expecting:"1 KB"
11999LL  options:ZeroPadFractionDigits expecting:"12 KB"
900000LL  options:ZeroPadFractionDigits expecting:"900 KB"
12345678LL  options:ZeroPadFractionDigits expecting:"12.3 MB"
123456789LL  options:ZeroPadFractionDigits expecting:"123.5 MB"
1234567898LL  options:ZeroPadFractionDigits expecting:"1.23 GB"
12345678987LL  options:ZeroPadFractionDigits expecting:"12.35 GB"

1LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"1 byte"
12LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"12 bytes"
499LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"499 bytes"
900LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"900 bytes"
999LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"999 bytes"
1000LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"1 KB"
1023LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"1 KB"
1024LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"1 KB"
11999LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"12 KB"
900000LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"900 KB"
12345678LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"12.3 MB"
123456789LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"123.5 MB"
1234567898LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"1.23 GB"
12345678987LL  options:FinderAlgorithmForFractionDigits | ZeroPadFractionDigits expecting:"12.35 GB"

1LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"1 byte"
12LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"12 bytes"
499LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"499 bytes"
900LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"900 bytes"
999LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"999 bytes"
1000LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"1.00 KB"
1023LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"1.02 KB"
1024LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"1.02 KB"
11999LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"12.0 KB"
900000LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"900 KB"
12345678LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"12.3 MB"
123456789LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"123 MB"
1234567898LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"1.23 GB"
12345678987LL  options:ThreeOrMoreSignificantDigits | ZeroPadFractionDigits expecting:"12.3 GB"




499LL  options:KilobyteIs1000 expecting:"499 bytes"
900LL  options:KilobyteIs1000 expecting:"900 bytes"
999LL  options:KilobyteIs1000 expecting:"999 bytes"
1000LL  options:KilobyteIs1000 expecting:"1 KB"
1023LL  options:KilobyteIs1000 expecting:"1 KB"
1024LL  options:KilobyteIs1000 expecting:"1 KB"
11999LL  options:KilobyteIs1000 expecting:"12 KB"
900000LL  options:KilobyteIs1000 expecting:"900 KB"
12345678LL  options:KilobyteIs1000 expecting:"12.3 MB"
123456789LL  options:KilobyteIs1000 expecting:"123.5 MB"
1234567898LL  options:KilobyteIs1000 expecting:"1.23 GB"
12345678987LL  options:KilobyteIs1000 expecting:"12.35 GB"




499LL  options:KilobyteIs1024 expecting:"499 bytes"
900LL  options:KilobyteIs1024 expecting:"900 bytes"
999LL  options:KilobyteIs1024 expecting:"999 bytes"
1000LL  options:KilobyteIs1024 expecting:"1,000 bytes"
1023LL  options:KilobyteIs1024 expecting:"1,023 bytes"
1024LL  options:KilobyteIs1024 expecting:"1 KB"
11999LL  options:KilobyteIs1024 expecting:"12 KB"
900000LL  options:KilobyteIs1024 expecting:"879 KB"
12345678LL  options:KilobyteIs1024 expecting:"11.8 MB"
123456789LL  options:KilobyteIs1024 expecting:"117.7 MB"
1234567898LL  options:KilobyteIs1024 expecting:"1.15 GB"
12345678987LL  options:KilobyteIs1024 expecting:"11.5 GB"




9223372036854775807LL  options:NSByteCountFormatterUseTB expecting:"9,223,372.04 TB"
9223372036854775807LL  options:NSByteCountFormatterUseEB expecting:"9.22 EB"
9223372036854775807LL  options:NSByteCountFormatterUseZB expecting:"0.01 ZB"
9223372036854775807LL  options:NSByteCountFormatterUseYBOrHigher expecting:"0 YB"

9223372036854775807LL  options:NSByteCountFormatterUseTB | ThreeOrMoreSignificantDigits expecting:"9,223,372 TB"
9223372036854775807LL  options:NSByteCountFormatterUseEB | ThreeOrMoreSignificantDigits expecting:"9.22 EB"
9223372036854775807LL  options:NSByteCountFormatterUseZB | ThreeOrMoreSignificantDigits expecting:"0.00922 ZB"
9223372036854775807LL  options:NSByteCountFormatterUseYBOrHigher | ThreeOrMoreSignificantDigits expecting:"0.00000922 YB"

0x7FFFFFFFFFFFFFFFLL  options:NSByteCountFormatterUseBytes expecting:"9,223,372,036,854,775,807 bytes"




-1LL  options:0 expecting:"-1 byte"
-2LL  options:0 expecting:"-2 bytes"
-999LL  options:KilobyteIs1024 expecting:"-999 bytes"
-1000LL  options:KilobyteIs1024 expecting:"-1,000 bytes"
-1023LL  options:KilobyteIs1024 expecting:"-1,023 bytes"
-1024LL  options:KilobyteIs1024 expecting:"-1 KB"
-1023LL  options:KilobyteIs1000 expecting:"-1 KB"
-12345678987LL  options:KilobyteIs1000 expecting:"-12.35 GB"
-12345678987LL  options:KilobyteIs1024 expecting:"-11.5 GB"

-1LL  options:NumberOnly expecting:"-1"
-1LL  options:UnitOnly expecting:"byte"

-1234567898LL  options:FinderAlgorithmForFractionDigits expecting:"-1.23 GB"

1LL  options:NSByteCountFormatterUseGB expecting:"0 GB"
-1LL  options:NSByteCountFormatterUseGB expecting:"-0 GB"
-5000LL  options:NSByteCountFormatterUseGB expecting:"-0 GB"
-50000LL  options:NSByteCountFormatterUseGB expecting:"-0 GB"
-500000LL  options:NSByteCountFormatterUseGB expecting:"-0 GB"
-5000000LL  options:NSByteCountFormatterUseGB expecting:"-0.01 GB"
-50000000LL  options:NSByteCountFormatterUseGB expecting:"-0.05 GB"
-500000000LL  options:NSByteCountFormatterUseGB expecting:"-0.5 GB"

INT64_MIN  options:NSByteCountFormatterUseTB expecting:"-9,223,372.04 TB"
INT64_MIN  options:NSByteCountFormatterUseEB expecting:"-9.22 EB"
INT64_MIN  options:NSByteCountFormatterUseZB expecting:"-0.01 ZB"
INT64_MIN  options:NSByteCountFormatterUseYBOrHigher expecting:"-0 YB"

INT64_MIN  options:NSByteCountFormatterUseTB | ThreeOrMoreSignificantDigits expecting:"-9,223,372 TB"
INT64_MIN  options:NSByteCountFormatterUseEB | ThreeOrMoreSignificantDigits expecting:"-9.22 EB"
INT64_MIN  options:NSByteCountFormatterUseZB | ThreeOrMoreSignificantDigits expecting:"-0.00922 ZB"
INT64_MIN  options:NSByteCountFormatterUseYBOrHigher | ThreeOrMoreSignificantDigits expecting:"-0.00000922 YB"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks for supplying that.
At a quick glance I noticed a few cases the initial implementation is missing. Particularly involving the OptionSet. I've begun creating the tests and fixing the issues raised by them, I'll update once I've finished.

Thanks again.

@DunnCoding
Copy link
Contributor Author

@parkera Hi Tony, I've added most of the suggested tests. I've also updated the ByteCountFormatter so the tests now pass on both Mac and Linux.

I couldn't work out what the 'maximum' property is that is being set in some of the tests so I've omitted them for now but if you can provide more information about the maximum property I will add those as well.

Thanks.

@parkera
Copy link
Contributor

parkera commented Mar 3, 2017

Sorry about the maximum arg, that is an artifact of the way our tests are constructed internally. Omitting it makes sense.

@parkera
Copy link
Contributor

parkera commented Mar 3, 2017

@swift-ci please test and merge

@parkera
Copy link
Contributor

parkera commented Mar 3, 2017

Thanks for the great contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants