github.com/condensat/bank-core@v0.1.0/database/model/FeeInfo_test.go (about)

     1  // Copyright 2020 Condensat Tech. All rights reserved.
     2  // Use of this source code is governed by a MIT
     3  // license that can be found in the LICENSE file.
     4  
     5  package model
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestFeeInfo_IsValid(t *testing.T) {
    12  	const currency = "CURR"
    13  	const minimumFee = 1.0
    14  
    15  	type fields struct {
    16  		Currency CurrencyName
    17  		Minimum  Float
    18  		Rate     Float
    19  	}
    20  	tests := []struct {
    21  		name   string
    22  		fields fields
    23  		want   bool
    24  	}{
    25  		{"default", fields{}, false},
    26  		{"invalid_currency", fields{"", minimumFee, DefaultFeeRate}, false},
    27  		{"invalid_minimum", fields{currency, -minimumFee, DefaultFeeRate}, false},
    28  		{"invalid_rate", fields{currency, minimumFee, -DefaultFeeRate}, false},
    29  
    30  		{"zero", fields{currency, 0.0, 0.0}, true},
    31  		{"valid", fields{currency, minimumFee, DefaultFeeRate}, true},
    32  	}
    33  	for _, tt := range tests {
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			p := &FeeInfo{
    36  				Currency: tt.fields.Currency,
    37  				Minimum:  tt.fields.Minimum,
    38  				Rate:     tt.fields.Rate,
    39  			}
    40  			if got := p.IsValid(); got != tt.want {
    41  				t.Errorf("FeeInfo.Valid() = %v, want %v", got, tt.want)
    42  			}
    43  		})
    44  	}
    45  }
    46  
    47  func TestFeeInfo_Compute(t *testing.T) {
    48  	const currency = "CURR"
    49  	const minimumFee = 1.0
    50  
    51  	type fields struct {
    52  		Currency CurrencyName
    53  		Minimum  Float
    54  		Rate     Float
    55  	}
    56  	type args struct {
    57  		amount Float
    58  	}
    59  	tests := []struct {
    60  		name   string
    61  		fields fields
    62  		args   args
    63  		want   Float
    64  	}{
    65  		{"default", fields{}, args{}, 0.0},
    66  		{"zero", fields{}, args{42.0}, 0.0},
    67  
    68  		{"min_less", fields{currency, minimumFee, DefaultFeeRate}, args{999.0}, 1.0},
    69  		{"minimum", fields{currency, minimumFee, DefaultFeeRate}, args{1000.0}, 1.0},
    70  		{"min_more", fields{currency, minimumFee, DefaultFeeRate}, args{1001.0}, 1.001},
    71  
    72  		{"small", fields{currency, minimumFee, DefaultFeeRate}, args{500.0}, 1.0},
    73  		{"percent", fields{currency, minimumFee, DefaultFeeRate}, args{1337.0}, 1.337},
    74  	}
    75  	for _, tt := range tests {
    76  		t.Run(tt.name, func(t *testing.T) {
    77  			p := &FeeInfo{
    78  				Currency: tt.fields.Currency,
    79  				Minimum:  tt.fields.Minimum,
    80  				Rate:     tt.fields.Rate,
    81  			}
    82  			if got := p.Compute(tt.args.amount); got != tt.want {
    83  				t.Errorf("FeeInfo.Compute() = %v, want %v", got, tt.want)
    84  			}
    85  		})
    86  	}
    87  }