github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/util/parse_test.go (about)

     1  package util
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func TestFormatAmount(t *testing.T) {
     9  	type args struct {
    10  		amount float64
    11  	}
    12  	tests := []struct {
    13  		name string
    14  		args args
    15  		want int
    16  	}{
    17  		{name: "1", args: args{amount: 1.16}, want: 116},
    18  		{name: "2", args: args{amount: 1.13}, want: 113},
    19  	}
    20  	for _, tt := range tests {
    21  		t.Run(tt.name, func(t *testing.T) {
    22  			assert.Equalf(t, tt.want, FormatAmount(tt.args.amount), "FormatAmount(%v)", tt.args.amount)
    23  		})
    24  	}
    25  }
    26  
    27  func TestFormatResUrl(t *testing.T) {
    28  	type args struct {
    29  		dfs string
    30  		url string
    31  	}
    32  	tests := []struct {
    33  		name string
    34  		args args
    35  		want string
    36  	}{
    37  		{name: "1", args: args{"dfs", "url"}, want: "dfs/url"},
    38  	}
    39  	for _, tt := range tests {
    40  		t.Run(tt.name, func(t *testing.T) {
    41  			assert.Equalf(t, tt.want, FormatResUrl(tt.args.dfs, tt.args.url), "FormatResUrl(%v, %v)", tt.args.dfs, tt.args.url)
    42  		})
    43  	}
    44  }
    45  
    46  func TestParseAmount(t *testing.T) {
    47  	type args struct {
    48  		amount int
    49  	}
    50  	tests := []struct {
    51  		name string
    52  		args args
    53  		want float64
    54  	}{
    55  		{name: "1", args: args{amount: 116}, want: 1.16},
    56  		{name: "2", args: args{amount: 101}, want: 1.01},
    57  	}
    58  	for _, tt := range tests {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  			assert.Equalf(t, tt.want, ParseAmount(tt.args.amount), "ParseAmount(%v)", tt.args.amount)
    61  		})
    62  	}
    63  }