|
| 1 | +import { humanizeDataValue } from "./data"; |
| 2 | +import { BytesUnitId, BytesUnitId as DataFormatUnitId } from "../constants"; |
| 3 | + |
| 4 | +describe("data", () => { |
| 5 | + it("should humanize data value correctly", () => { |
| 6 | + expect(humanizeDataValue(8)).toEqual([1, "B"]); |
| 7 | + expect(humanizeDataValue(8, "bytes" as DataFormatUnitId)).toEqual([8, "B"]); |
| 8 | + expect(humanizeDataValue(-8)).toEqual([-1, "B"]); |
| 9 | + expect(humanizeDataValue(-8, "bytes" as DataFormatUnitId)).toEqual([ |
| 10 | + -8, |
| 11 | + "B", |
| 12 | + ]); |
| 13 | + |
| 14 | + expect(humanizeDataValue(1000, "bytes(B)" as BytesUnitId)).toEqual([ |
| 15 | + 1, |
| 16 | + "KB", |
| 17 | + ]); |
| 18 | + |
| 19 | + expect(humanizeDataValue(1000, "kilobytes(KB)" as BytesUnitId)).toEqual([ |
| 20 | + 1, |
| 21 | + "MB", |
| 22 | + ]); |
| 23 | + |
| 24 | + expect(humanizeDataValue(1000, "megabytes(MB)" as BytesUnitId)).toEqual([ |
| 25 | + 1, |
| 26 | + "GB", |
| 27 | + ]); |
| 28 | + |
| 29 | + expect(humanizeDataValue(1000, "gigabytes(GB)" as BytesUnitId)).toEqual([ |
| 30 | + 1, |
| 31 | + "TB", |
| 32 | + ]); |
| 33 | + |
| 34 | + expect(humanizeDataValue(1000, "terabytes(TB)" as BytesUnitId)).toEqual([ |
| 35 | + 1, |
| 36 | + "PB", |
| 37 | + ]); |
| 38 | + |
| 39 | + expect(humanizeDataValue(1000, "petabytes(PB)" as BytesUnitId)).toEqual([ |
| 40 | + 1000, |
| 41 | + "PB", |
| 42 | + ]); |
| 43 | + |
| 44 | + expect(humanizeDataValue(1, "bibytes(B)" as BytesUnitId)).toEqual([1, "B"]); |
| 45 | + |
| 46 | + expect(humanizeDataValue(1024, "bibytes(B)" as BytesUnitId)).toEqual([ |
| 47 | + 1, |
| 48 | + "KiB", |
| 49 | + ]); |
| 50 | + |
| 51 | + expect(humanizeDataValue(1024, "kibibytes(KiB)" as BytesUnitId)).toEqual([ |
| 52 | + 1, |
| 53 | + "MiB", |
| 54 | + ]); |
| 55 | + |
| 56 | + expect(humanizeDataValue(1024, "mebibytes(MiB)" as BytesUnitId)).toEqual([ |
| 57 | + 1, |
| 58 | + "GiB", |
| 59 | + ]); |
| 60 | + |
| 61 | + expect(humanizeDataValue(1024, "gibibytes(GiB)" as BytesUnitId)).toEqual([ |
| 62 | + 1, |
| 63 | + "TiB", |
| 64 | + ]); |
| 65 | + |
| 66 | + expect(humanizeDataValue(1024, "tebibytes(TiB)" as BytesUnitId)).toEqual([ |
| 67 | + 1, |
| 68 | + "PiB", |
| 69 | + ]); |
| 70 | + |
| 71 | + expect(humanizeDataValue(1024, "pebibytes(PiB)" as BytesUnitId)).toEqual([ |
| 72 | + 1024, |
| 73 | + "PiB", |
| 74 | + ]); |
| 75 | + |
| 76 | + expect(humanizeDataValue(-1000, "bytes(B)" as BytesUnitId)).toEqual([ |
| 77 | + -1, |
| 78 | + "KB", |
| 79 | + ]); |
| 80 | + |
| 81 | + expect(humanizeDataValue(-1000, "kilobytes(KB)" as BytesUnitId)).toEqual([ |
| 82 | + -1, |
| 83 | + "MB", |
| 84 | + ]); |
| 85 | + |
| 86 | + expect(humanizeDataValue(-1000, "megabytes(MB)" as BytesUnitId)).toEqual([ |
| 87 | + -1, |
| 88 | + "GB", |
| 89 | + ]); |
| 90 | + |
| 91 | + expect(humanizeDataValue(-1000, "gigabytes(GB)" as BytesUnitId)).toEqual([ |
| 92 | + -1, |
| 93 | + "TB", |
| 94 | + ]); |
| 95 | + |
| 96 | + expect(humanizeDataValue(-1000, "terabytes(TB)" as BytesUnitId)).toEqual([ |
| 97 | + -1, |
| 98 | + "PB", |
| 99 | + ]); |
| 100 | + |
| 101 | + expect(humanizeDataValue(-1000, "petabytes(PB)" as BytesUnitId)).toEqual([ |
| 102 | + -1000, |
| 103 | + "PB", |
| 104 | + ]); |
| 105 | + |
| 106 | + expect(humanizeDataValue(-1, "bibytes(B)" as BytesUnitId)).toEqual([ |
| 107 | + -1, |
| 108 | + "B", |
| 109 | + ]); |
| 110 | + |
| 111 | + expect(humanizeDataValue(-1024, "bibytes(B)" as BytesUnitId)).toEqual([ |
| 112 | + -1, |
| 113 | + "KiB", |
| 114 | + ]); |
| 115 | + |
| 116 | + expect(humanizeDataValue(-1024, "bibytes(B)" as BytesUnitId)).toEqual([ |
| 117 | + -1, |
| 118 | + "KiB", |
| 119 | + ]); |
| 120 | + |
| 121 | + expect(humanizeDataValue(-1024, "kibibytes(KiB)" as BytesUnitId)).toEqual([ |
| 122 | + -1, |
| 123 | + "MiB", |
| 124 | + ]); |
| 125 | + |
| 126 | + expect(humanizeDataValue(-1024, "mebibytes(MiB)" as BytesUnitId)).toEqual([ |
| 127 | + -1, |
| 128 | + "GiB", |
| 129 | + ]); |
| 130 | + |
| 131 | + expect(humanizeDataValue(-1024, "gibibytes(GiB)" as BytesUnitId)).toEqual([ |
| 132 | + -1, |
| 133 | + "TiB", |
| 134 | + ]); |
| 135 | + |
| 136 | + expect(humanizeDataValue(-1024, "tebibytes(TiB)" as BytesUnitId)).toEqual([ |
| 137 | + -1, |
| 138 | + "PiB", |
| 139 | + ]); |
| 140 | + |
| 141 | + expect(humanizeDataValue(-1024, "pebibytes(PiB)" as BytesUnitId)).toEqual([ |
| 142 | + -1024, |
| 143 | + "PiB", |
| 144 | + ]); |
| 145 | + }); |
| 146 | +}); |
0 commit comments