github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/stellar_test.go (about)

     1  // Copyright 2018 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestStellarSimplifyAmount(t *testing.T) {
    13  	units := []struct {
    14  		a, b string
    15  	}{
    16  		{"", ""},
    17  		{"1", "1"},
    18  		{"100", "100"},
    19  		{"100.00", "100"},
    20  		{"100.0000001", "100.0000001"},
    21  		{"100.000000100", "100.0000001"},
    22  		{"0100.00", "0100"},
    23  		{".1", ".1"},
    24  		{".01", ".01"},
    25  		{".010", ".01"},
    26  		{"1.0010000", "1.001"},
    27  		{"1.0000000", "1"},
    28  		{"aaa", "aaa"},
    29  		{"1,231.0010000", "1,231.001"},
    30  		{"1,231.5000000", "1,231.50"},
    31  		{"1,231.0000000", "1,231.00"},
    32  		{"1,231", "1,231"},
    33  	}
    34  	for i, u := range units {
    35  		require.Equal(t, u.b, StellarSimplifyAmount(u.a), "units[%v]", i)
    36  	}
    37  }