github.com/sacloud/libsacloud/v2@v2.32.3/pkg/size/size_test.go (about) 1 // Copyright 2016-2022 The Libsacloud Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package size 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestSizeFunctions(t *testing.T) { 24 cases := []struct { 25 msg string 26 f func(int) int 27 in int 28 out int 29 }{ 30 { 31 msg: "MiBToGiB", 32 f: MiBToGiB, 33 in: 1024, 34 out: 1, 35 }, 36 { 37 msg: "MiBToGiB", 38 f: MiBToGiB, 39 in: 51200, 40 out: 50, 41 }, 42 { 43 msg: "MiBToGiB", 44 f: MiBToGiB, 45 in: 102400, 46 out: 100, 47 }, 48 { 49 msg: "ToGiB with Zero", 50 f: MiBToGiB, 51 in: 0, 52 out: 0, 53 }, 54 { 55 msg: "GiBToMiB", 56 f: GiBToMiB, 57 in: 1, 58 out: 1024, 59 }, 60 { 61 msg: "GiBToMiB", 62 f: GiBToMiB, 63 in: 100, 64 out: 102400, 65 }, 66 { 67 msg: "GiBToMiB with Zero", 68 f: GiBToMiB, 69 in: 0, 70 out: 0, 71 }, 72 } 73 74 for _, tt := range cases { 75 got := tt.f(tt.in) 76 require.Equal(t, tt.out, got, "%s returns unexpected value: expect: %v actual:", tt.msg, tt.out, got) 77 } 78 }