From 7501aee141a125a4e473a36c021ceb75fdadf9cf Mon Sep 17 00:00:00 2001 From: Mawuli Adzoe Date: Mon, 20 Jul 2015 16:00:32 +0000 Subject: [PATCH] Improve godocs. Add testable example for NewAmount This is consistent with the rest of the code base. i.e.: base58/bloom/hash160/hdkeychain. --- example_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 00000000..d0c436fb --- /dev/null +++ b/example_test.go @@ -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 +}