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:
Mawuli Adzoe 2015-07-20 16:00:32 +00:00
parent 3c3f9360f4
commit 7501aee141

43
example_test.go Normal file
View 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
}