53 lines
2.7 KiB
Swift
53 lines
2.7 KiB
Swift
//
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
|
|
@testable import SignalServiceKit
|
|
|
|
class OWSFormatTest: XCTestCase {
|
|
|
|
func testTimeIntervals() throws {
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 0), "0:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 0.4), "0:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 0.6), "0:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 0.999), "0:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 1), "0:01")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 60), "1:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 60 + 12), "1:12")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 25 * 60 + 45), "25:45")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 60 * 60 - 1), "59:59")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 60 * 60), "1:00:00")
|
|
XCTAssertEqual(OWSFormat.localizedDurationString(from: 3 * 60 * 60 + 4 * 60 + 37), "3:04:37")
|
|
}
|
|
|
|
func testDecimals() throws {
|
|
XCTAssertEqual(OWSFormat.localizedDecimalString(from: 0), "0")
|
|
XCTAssertEqual(OWSFormat.localizedDecimalString(from: 1), "1")
|
|
XCTAssertEqual(OWSFormat.localizedDecimalString(from: 1000), "1,000")
|
|
XCTAssertEqual(OWSFormat.localizedDecimalString(from: 1234567), "1,234,567")
|
|
}
|
|
|
|
func testFileSizes() throws {
|
|
let kb: UInt64 = 1000
|
|
let mb: UInt64 = 1000 * kb
|
|
let gb: UInt64 = 1000 * mb
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 0), "Zero KB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 1), "1 byte")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 60), "60 bytes")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 1 * kb), "1 KB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: UInt64(3.3 * Double(kb))), "3 KB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: UInt64(13.5 * Double(kb))), "14 KB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 100 * kb), "100 KB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 1 * mb), "1 MB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: UInt64(4.32 * Double(mb))), "4.3 MB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 111 * mb), "111 MB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 1 * gb), "1 GB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: UInt64(2.34 * Double(gb))), "2.34 GB")
|
|
XCTAssertEqual(OWSFormat.localizedFileSizeString(from: 56 * gb), "56 GB")
|
|
}
|
|
}
|