Named sub tests
Vladimir Bauer
7 years ago
| 6 | 6 | |
| 7 | 7 | func TestCounterKiB(t *testing.T) { |
| 8 | 8 | cases := map[string]struct { |
| 9 | value int64 | |
| 10 | verb, expected string | |
| 9 | value int64 | |
| 10 | verb string | |
| 11 | expected string | |
| 11 | 12 | }{ |
| 12 | 13 | "verb %f": {12345678, "%f", "11.773756MiB"}, |
| 13 | 14 | "verb %.0f": {12345678, "%.0f", "12MiB"}, |
| 61 | 62 | "4*TiB %.1f": {4 * TiB, "%.1f", "4.0TiB"}, |
| 62 | 63 | "4*TiB %s": {4 * TiB, "%s", "4.0TiB"}, |
| 63 | 64 | } |
| 64 | for k, tc := range cases { | |
| 65 | got := fmt.Sprintf(tc.verb, CounterKiB(tc.value)) | |
| 66 | if got != tc.expected { | |
| 67 | t.Errorf("%s: Expected: %q, got: %q\n", k, tc.expected, got) | |
| 68 | } | |
| 65 | for name, tc := range cases { | |
| 66 | t.Run(name, func(t *testing.T) { | |
| 67 | got := fmt.Sprintf(tc.verb, CounterKiB(tc.value)) | |
| 68 | if got != tc.expected { | |
| 69 | t.Fatalf("expected: %q, got: %q\n", tc.expected, got) | |
| 70 | } | |
| 71 | }) | |
| 69 | 72 | } |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | func TestCounterKB(t *testing.T) { |
| 73 | 76 | cases := map[string]struct { |
| 74 | value int64 | |
| 75 | verb, expected string | |
| 77 | value int64 | |
| 78 | verb string | |
| 79 | expected string | |
| 76 | 80 | }{ |
| 77 | 81 | "verb %f": {12345678, "%f", "12.345678MB"}, |
| 78 | 82 | "verb %.0f": {12345678, "%.0f", "12MB"}, |
| 126 | 130 | "4*TB %.1f": {4 * TB, "%.1f", "4.0TB"}, |
| 127 | 131 | "4*TB %s": {4 * TB, "%s", "4.0TB"}, |
| 128 | 132 | } |
| 129 | for k, tc := range cases { | |
| 130 | got := fmt.Sprintf(tc.verb, CounterKB(tc.value)) | |
| 131 | if got != tc.expected { | |
| 132 | t.Errorf("%s: Expected: %q, got: %q\n", k, tc.expected, got) | |
| 133 | } | |
| 133 | for name, tc := range cases { | |
| 134 | t.Run(name, func(t *testing.T) { | |
| 135 | got := fmt.Sprintf(tc.verb, CounterKB(tc.value)) | |
| 136 | if got != tc.expected { | |
| 137 | t.Fatalf("expected: %q, got: %q\n", tc.expected, got) | |
| 138 | } | |
| 139 | }) | |
| 134 | 140 | } |
| 135 | 141 | } |
| 6 | 6 | |
| 7 | 7 | func TestSpeedKiB(t *testing.T) { |
| 8 | 8 | cases := map[string]struct { |
| 9 | value int64 | |
| 10 | verb, expected string | |
| 9 | value int64 | |
| 10 | verb string | |
| 11 | expected string | |
| 11 | 12 | }{ |
| 12 | 13 | "verb %f": {12345678, "%f", "11.773756MiB/s"}, |
| 13 | 14 | "verb %.0f": {12345678, "%.0f", "12MiB/s"}, |
| 61 | 62 | "4*TiB/s %.1f": {4 * TiB, "%.1f", "4.0TiB/s"}, |
| 62 | 63 | "4*TiB/s %s": {4 * TiB, "%s", "4.0TiB/s"}, |
| 63 | 64 | } |
| 64 | for k, tc := range cases { | |
| 65 | got := fmt.Sprintf(tc.verb, SpeedKiB(tc.value)) | |
| 66 | if got != tc.expected { | |
| 67 | t.Errorf("%s: Expected: %q, got: %q\n", k, tc.expected, got) | |
| 68 | } | |
| 65 | for name, tc := range cases { | |
| 66 | t.Run(name, func(t *testing.T) { | |
| 67 | got := fmt.Sprintf(tc.verb, SpeedKiB(tc.value)) | |
| 68 | if got != tc.expected { | |
| 69 | t.Fatalf("expected: %q, got: %q\n", tc.expected, got) | |
| 70 | } | |
| 71 | }) | |
| 69 | 72 | } |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | func TestSpeedKB(t *testing.T) { |
| 73 | 76 | cases := map[string]struct { |
| 74 | value int64 | |
| 75 | verb, expected string | |
| 77 | value int64 | |
| 78 | verb string | |
| 79 | expected string | |
| 76 | 80 | }{ |
| 77 | 81 | "verb %f": {12345678, "%f", "12.345678MB/s"}, |
| 78 | 82 | "verb %.0f": {12345678, "%.0f", "12MB/s"}, |
| 126 | 130 | "4*TB/s %.1f": {4 * TB, "%.1f", "4.0TB/s"}, |
| 127 | 131 | "4*TB/s %s": {4 * TB, "%s", "4.0TB/s"}, |
| 128 | 132 | } |
| 129 | for k, tc := range cases { | |
| 130 | got := fmt.Sprintf(tc.verb, SpeedKB(tc.value)) | |
| 131 | if got != tc.expected { | |
| 132 | t.Errorf("%s: Expected: %q, got: %q\n", k, tc.expected, got) | |
| 133 | } | |
| 133 | for name, tc := range cases { | |
| 134 | t.Run(name, func(t *testing.T) { | |
| 135 | got := fmt.Sprintf(tc.verb, SpeedKB(tc.value)) | |
| 136 | if got != tc.expected { | |
| 137 | t.Fatalf("expected: %q, got: %q\n", tc.expected, got) | |
| 138 | } | |
| 139 | }) | |
| 134 | 140 | } |
| 135 | 141 | } |