Improve godocs. Add testable example for NewAmount
This is consistent with the rest of the code base. i.e.: base58/bloom/hash160/hdkeychain.
This commit is contained in:
parent
3c3f9360f4
commit
7501aee141
1 changed files with 43 additions and 0 deletions
43
example_test.go
Normal file
43
example_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package btcutil_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
. "github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
func ExampleNewAmount() {
|
||||
amountOne, err := NewAmount(1)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(amountOne) //Output 1
|
||||
|
||||
amountFraction, err := NewAmount(0.01234567)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(amountFraction) //Output 2
|
||||
|
||||
amountZero, err := NewAmount(0)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(amountZero) //Output 3
|
||||
|
||||
amountNaN, err := NewAmount(math.NaN())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(amountNaN) //Output 4
|
||||
|
||||
// Output: 1 BTC
|
||||
// 0.01234567 BTC
|
||||
// 0 BTC
|
||||
// invalid bitcoin amount
|
||||
}
|
Loading…
Add table
Reference in a new issue