refactoring TestB1024 and TestB1000
Vladimir Bauer
3 years ago
| 10 | 10 | verb string |
| 11 | 11 | expected string |
| 12 | 12 | }{ |
| 13 | "verb %f": {12345678, "%f", "11.773756MiB"}, | |
| 14 | "verb %.0f": {12345678, "%.0f", "12MiB"}, | |
| 15 | "verb %.1f": {12345678, "%.1f", "11.8MiB"}, | |
| 16 | "verb %.2f": {12345678, "%.2f", "11.77MiB"}, | |
| 17 | "verb %.3f": {12345678, "%.3f", "11.774MiB"}, | |
| 18 | ||
| 13 | "verb %d": {12345678, "%d", "12MiB"}, | |
| 14 | "verb %s": {12345678, "%s", "12MiB"}, | |
| 15 | "verb %f": {12345678, "%f", "11.773756MiB"}, | |
| 16 | "verb %.6f": {12345678, "%.6f", "11.773756MiB"}, | |
| 17 | "verb %.0f": {12345678, "%.0f", "12MiB"}, | |
| 18 | "verb %.1f": {12345678, "%.1f", "11.8MiB"}, | |
| 19 | "verb %.2f": {12345678, "%.2f", "11.77MiB"}, | |
| 20 | "verb %.3f": {12345678, "%.3f", "11.774MiB"}, | |
| 21 | "verb % d": {12345678, "% d", "12 MiB"}, | |
| 22 | "verb % s": {12345678, "% s", "12 MiB"}, | |
| 19 | 23 | "verb % f": {12345678, "% f", "11.773756 MiB"}, |
| 24 | "verb % .6f": {12345678, "% .6f", "11.773756 MiB"}, | |
| 20 | 25 | "verb % .0f": {12345678, "% .0f", "12 MiB"}, |
| 21 | 26 | "verb % .1f": {12345678, "% .1f", "11.8 MiB"}, |
| 22 | 27 | "verb % .2f": {12345678, "% .2f", "11.77 MiB"}, |
| 23 | 28 | "verb % .3f": {12345678, "% .3f", "11.774 MiB"}, |
| 24 | 29 | |
| 25 | "1000 %f": {1000, "%f", "1000.000000b"}, | |
| 26 | "1000 %d": {1000, "%d", "1000b"}, | |
| 27 | "1000 %s": {1000, "%s", "1000b"}, | |
| 28 | "1024 %f": {1024, "%f", "1.000000KiB"}, | |
| 29 | "1024 %d": {1024, "%d", "1KiB"}, | |
| 30 | "1024 %.1f": {1024, "%.1f", "1.0KiB"}, | |
| 31 | "1024 %s": {1024, "%s", "1KiB"}, | |
| 32 | "3*MiB+140KiB %f": {3*int64(_iMiB) + 140*int64(_iKiB), "%f", "3.136719MiB"}, | |
| 33 | "3*MiB+140KiB %d": {3*int64(_iMiB) + 140*int64(_iKiB), "%d", "3MiB"}, | |
| 34 | "3*MiB+140KiB %.1f": {3*int64(_iMiB) + 140*int64(_iKiB), "%.1f", "3.1MiB"}, | |
| 35 | "3*MiB+140KiB %s": {3*int64(_iMiB) + 140*int64(_iKiB), "%s", "3.13671875MiB"}, | |
| 36 | "2*GiB %f": {2 * int64(_iGiB), "%f", "2.000000GiB"}, | |
| 37 | "2*GiB %d": {2 * int64(_iGiB), "%d", "2GiB"}, | |
| 38 | "2*GiB %.1f": {2 * int64(_iGiB), "%.1f", "2.0GiB"}, | |
| 39 | "2*GiB %s": {2 * int64(_iGiB), "%s", "2GiB"}, | |
| 40 | "4*TiB %f": {4 * int64(_iTiB), "%f", "4.000000TiB"}, | |
| 41 | "4*TiB %d": {4 * int64(_iTiB), "%d", "4TiB"}, | |
| 42 | "4*TiB %.1f": {4 * int64(_iTiB), "%.1f", "4.0TiB"}, | |
| 43 | "4*TiB %s": {4 * int64(_iTiB), "%s", "4TiB"}, | |
| 30 | "1000 %d": {1000, "%d", "1000b"}, | |
| 31 | "1000 %s": {1000, "%s", "1000b"}, | |
| 32 | "1000 %f": {1000, "%f", "1000.000000b"}, | |
| 33 | "1000 %.6f": {1000, "%.6f", "1000.000000b"}, | |
| 34 | "1000 %.0f": {1000, "%.0f", "1000b"}, | |
| 35 | "1000 %.1f": {1000, "%.1f", "1000.0b"}, | |
| 36 | "1000 %.2f": {1000, "%.2f", "1000.00b"}, | |
| 37 | "1000 %.3f": {1000, "%.3f", "1000.000b"}, | |
| 38 | "1024 %d": {1024, "%d", "1KiB"}, | |
| 39 | "1024 %s": {1024, "%s", "1KiB"}, | |
| 40 | "1024 %f": {1024, "%f", "1.000000KiB"}, | |
| 41 | "1024 %.6f": {1024, "%.6f", "1.000000KiB"}, | |
| 42 | "1024 %.0f": {1024, "%.0f", "1KiB"}, | |
| 43 | "1024 %.1f": {1024, "%.1f", "1.0KiB"}, | |
| 44 | "1024 %.2f": {1024, "%.2f", "1.00KiB"}, | |
| 45 | "1024 %.3f": {1024, "%.3f", "1.000KiB"}, | |
| 46 | ||
| 47 | "3*MiB+100KiB %d": {3*int64(_iMiB) + 100*int64(_iKiB), "%d", "3MiB"}, | |
| 48 | "3*MiB+100KiB %s": {3*int64(_iMiB) + 100*int64(_iKiB), "%s", "3MiB"}, | |
| 49 | "3*MiB+100KiB %f": {3*int64(_iMiB) + 100*int64(_iKiB), "%f", "3.097656MiB"}, | |
| 50 | "3*MiB+100KiB %.6f": {3*int64(_iMiB) + 100*int64(_iKiB), "%.6f", "3.097656MiB"}, | |
| 51 | "3*MiB+100KiB %.0f": {3*int64(_iMiB) + 100*int64(_iKiB), "%.0f", "3MiB"}, | |
| 52 | "3*MiB+100KiB %.1f": {3*int64(_iMiB) + 100*int64(_iKiB), "%.1f", "3.1MiB"}, | |
| 53 | "3*MiB+100KiB %.2f": {3*int64(_iMiB) + 100*int64(_iKiB), "%.2f", "3.10MiB"}, | |
| 54 | "3*MiB+100KiB %.3f": {3*int64(_iMiB) + 100*int64(_iKiB), "%.3f", "3.098MiB"}, | |
| 55 | ||
| 56 | "2*GiB %d": {2 * int64(_iGiB), "%d", "2GiB"}, | |
| 57 | "2*GiB %s": {2 * int64(_iGiB), "%s", "2GiB"}, | |
| 58 | "2*GiB %f": {2 * int64(_iGiB), "%f", "2.000000GiB"}, | |
| 59 | "2*GiB %.6f": {2 * int64(_iGiB), "%.6f", "2.000000GiB"}, | |
| 60 | "2*GiB %.0f": {2 * int64(_iGiB), "%.0f", "2GiB"}, | |
| 61 | "2*GiB %.1f": {2 * int64(_iGiB), "%.1f", "2.0GiB"}, | |
| 62 | "2*GiB %.2f": {2 * int64(_iGiB), "%.2f", "2.00GiB"}, | |
| 63 | "2*GiB %.3f": {2 * int64(_iGiB), "%.3f", "2.000GiB"}, | |
| 64 | ||
| 65 | "4*TiB %d": {4 * int64(_iTiB), "%d", "4TiB"}, | |
| 66 | "4*TiB %s": {4 * int64(_iTiB), "%s", "4TiB"}, | |
| 67 | "4*TiB %f": {4 * int64(_iTiB), "%f", "4.000000TiB"}, | |
| 68 | "4*TiB %.6f": {4 * int64(_iTiB), "%.6f", "4.000000TiB"}, | |
| 69 | "4*TiB %.0f": {4 * int64(_iTiB), "%.0f", "4TiB"}, | |
| 70 | "4*TiB %.1f": {4 * int64(_iTiB), "%.1f", "4.0TiB"}, | |
| 71 | "4*TiB %.2f": {4 * int64(_iTiB), "%.2f", "4.00TiB"}, | |
| 72 | "4*TiB %.3f": {4 * int64(_iTiB), "%.3f", "4.000TiB"}, | |
| 44 | 73 | } |
| 45 | 74 | for name, tc := range cases { |
| 46 | 75 | t.Run(name, func(t *testing.T) { |
| 58 | 87 | verb string |
| 59 | 88 | expected string |
| 60 | 89 | }{ |
| 61 | "verb %f": {12345678, "%f", "12.345678MB"}, | |
| 62 | "verb %.0f": {12345678, "%.0f", "12MB"}, | |
| 63 | "verb %.1f": {12345678, "%.1f", "12.3MB"}, | |
| 64 | "verb %.2f": {12345678, "%.2f", "12.35MB"}, | |
| 65 | "verb %.3f": {12345678, "%.3f", "12.346MB"}, | |
| 66 | ||
| 90 | "verb %d": {12345678, "%d", "12MB"}, | |
| 91 | "verb %s": {12345678, "%s", "12MB"}, | |
| 92 | "verb %f": {12345678, "%f", "12.345678MB"}, | |
| 93 | "verb %.6f": {12345678, "%.6f", "12.345678MB"}, | |
| 94 | "verb %.0f": {12345678, "%.0f", "12MB"}, | |
| 95 | "verb %.1f": {12345678, "%.1f", "12.3MB"}, | |
| 96 | "verb %.2f": {12345678, "%.2f", "12.35MB"}, | |
| 97 | "verb %.3f": {12345678, "%.3f", "12.346MB"}, | |
| 98 | "verb % d": {12345678, "% d", "12 MB"}, | |
| 99 | "verb % s": {12345678, "% s", "12 MB"}, | |
| 67 | 100 | "verb % f": {12345678, "% f", "12.345678 MB"}, |
| 101 | "verb % .6f": {12345678, "% .6f", "12.345678 MB"}, | |
| 68 | 102 | "verb % .0f": {12345678, "% .0f", "12 MB"}, |
| 69 | 103 | "verb % .1f": {12345678, "% .1f", "12.3 MB"}, |
| 70 | 104 | "verb % .2f": {12345678, "% .2f", "12.35 MB"}, |
| 71 | 105 | "verb % .3f": {12345678, "% .3f", "12.346 MB"}, |
| 72 | 106 | |
| 73 | "1000 %f": {1000, "%f", "1.000000KB"}, | |
| 74 | "1000 %d": {1000, "%d", "1KB"}, | |
| 75 | "1000 %s": {1000, "%s", "1KB"}, | |
| 76 | "1024 %f": {1024, "%f", "1.024000KB"}, | |
| 77 | "1024 %d": {1024, "%d", "1KB"}, | |
| 78 | "1024 %.1f": {1024, "%.1f", "1.0KB"}, | |
| 79 | "1024 %s": {1024, "%s", "1.024KB"}, | |
| 80 | "3*MB+140*KB %f": {3*int64(_MB) + 140*int64(_KB), "%f", "3.140000MB"}, | |
| 81 | "3*MB+140*KB %d": {3*int64(_MB) + 140*int64(_KB), "%d", "3MB"}, | |
| 82 | "3*MB+140*KB %.1f": {3*int64(_MB) + 140*int64(_KB), "%.1f", "3.1MB"}, | |
| 83 | "3*MB+140*KB %s": {3*int64(_MB) + 140*int64(_KB), "%s", "3.14MB"}, | |
| 84 | "2*GB %f": {2 * int64(_GB), "%f", "2.000000GB"}, | |
| 85 | "2*GB %d": {2 * int64(_GB), "%d", "2GB"}, | |
| 86 | "2*GB %.1f": {2 * int64(_GB), "%.1f", "2.0GB"}, | |
| 87 | "2*GB %s": {2 * int64(_GB), "%s", "2GB"}, | |
| 88 | "4*TB %f": {4 * int64(_TB), "%f", "4.000000TB"}, | |
| 89 | "4*TB %d": {4 * int64(_TB), "%d", "4TB"}, | |
| 90 | "4*TB %.1f": {4 * int64(_TB), "%.1f", "4.0TB"}, | |
| 91 | "4*TB %s": {4 * int64(_TB), "%s", "4TB"}, | |
| 107 | "1000 %d": {1000, "%d", "1KB"}, | |
| 108 | "1000 %s": {1000, "%s", "1KB"}, | |
| 109 | "1000 %f": {1000, "%f", "1.000000KB"}, | |
| 110 | "1000 %.6f": {1000, "%.6f", "1.000000KB"}, | |
| 111 | "1000 %.0f": {1000, "%.0f", "1KB"}, | |
| 112 | "1000 %.1f": {1000, "%.1f", "1.0KB"}, | |
| 113 | "1000 %.2f": {1000, "%.2f", "1.00KB"}, | |
| 114 | "1000 %.3f": {1000, "%.3f", "1.000KB"}, | |
| 115 | "1024 %d": {1024, "%d", "1KB"}, | |
| 116 | "1024 %s": {1024, "%s", "1KB"}, | |
| 117 | "1024 %f": {1024, "%f", "1.024000KB"}, | |
| 118 | "1024 %.6f": {1024, "%.6f", "1.024000KB"}, | |
| 119 | "1024 %.0f": {1024, "%.0f", "1KB"}, | |
| 120 | "1024 %.1f": {1024, "%.1f", "1.0KB"}, | |
| 121 | "1024 %.2f": {1024, "%.2f", "1.02KB"}, | |
| 122 | "1024 %.3f": {1024, "%.3f", "1.024KB"}, | |
| 123 | ||
| 124 | "3*MB+100*KB %d": {3*int64(_MB) + 100*int64(_KB), "%d", "3MB"}, | |
| 125 | "3*MB+100*KB %s": {3*int64(_MB) + 100*int64(_KB), "%s", "3MB"}, | |
| 126 | "3*MB+100*KB %f": {3*int64(_MB) + 100*int64(_KB), "%f", "3.100000MB"}, | |
| 127 | "3*MB+100*KB %.6f": {3*int64(_MB) + 100*int64(_KB), "%.6f", "3.100000MB"}, | |
| 128 | "3*MB+100*KB %.0f": {3*int64(_MB) + 100*int64(_KB), "%.0f", "3MB"}, | |
| 129 | "3*MB+100*KB %.1f": {3*int64(_MB) + 100*int64(_KB), "%.1f", "3.1MB"}, | |
| 130 | "3*MB+100*KB %.2f": {3*int64(_MB) + 100*int64(_KB), "%.2f", "3.10MB"}, | |
| 131 | "3*MB+100*KB %.3f": {3*int64(_MB) + 100*int64(_KB), "%.3f", "3.100MB"}, | |
| 132 | ||
| 133 | "2*GB %d": {2 * int64(_GB), "%d", "2GB"}, | |
| 134 | "2*GB %s": {2 * int64(_GB), "%s", "2GB"}, | |
| 135 | "2*GB %f": {2 * int64(_GB), "%f", "2.000000GB"}, | |
| 136 | "2*GB %.6f": {2 * int64(_GB), "%.6f", "2.000000GB"}, | |
| 137 | "2*GB %.0f": {2 * int64(_GB), "%.0f", "2GB"}, | |
| 138 | "2*GB %.1f": {2 * int64(_GB), "%.1f", "2.0GB"}, | |
| 139 | "2*GB %.2f": {2 * int64(_GB), "%.2f", "2.00GB"}, | |
| 140 | "2*GB %.3f": {2 * int64(_GB), "%.3f", "2.000GB"}, | |
| 141 | ||
| 142 | "4*TB %d": {4 * int64(_TB), "%d", "4TB"}, | |
| 143 | "4*TB %s": {4 * int64(_TB), "%s", "4TB"}, | |
| 144 | "4*TB %f": {4 * int64(_TB), "%f", "4.000000TB"}, | |
| 145 | "4*TB %.6f": {4 * int64(_TB), "%.6f", "4.000000TB"}, | |
| 146 | "4*TB %.0f": {4 * int64(_TB), "%.0f", "4TB"}, | |
| 147 | "4*TB %.1f": {4 * int64(_TB), "%.1f", "4.0TB"}, | |
| 148 | "4*TB %.2f": {4 * int64(_TB), "%.2f", "4.00TB"}, | |
| 149 | "4*TB %.3f": {4 * int64(_TB), "%.3f", "4.000TB"}, | |
| 92 | 150 | } |
| 93 | 151 | for name, tc := range cases { |
| 94 | 152 | t.Run(name, func(t *testing.T) { |