github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/data/size_test.go (about)

     1  // Copyright 2017 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package data
     6  
     7  import "testing"
     8  
     9  func TestSizeString(t *testing.T) {
    10  	for _, c := range []struct {
    11  		Size
    12  		expect string
    13  	}{
    14  		{10 * B, "10B"},
    15  		{727 * B, "727B"},
    16  		{KiB, "1.0KiB"},
    17  		{4*KiB + 100*B, "4.1KiB"},
    18  		{73*KiB + 900*B, "73.9KiB"},
    19  		{2*MiB + 800*KiB, "2.8MiB"},
    20  		{TiB, "1.0TiB"},
    21  		{2*EiB + 100000*TiB, "2.1EiB"},
    22  	} {
    23  		if got, want := c.Size.String(), c.expect; got != want {
    24  			t.Errorf("got %v, want %v", got, want)
    25  		}
    26  		if got, want := (-c.Size).String(), "-"+c.expect; got != want {
    27  			t.Errorf("got %v, want %v", got, want)
    28  		}
    29  	}
    30  }