diff options
author | Rob Pike <r@golang.org> | 2009-06-09 09:53:44 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-06-09 09:53:44 -0700 |
commit | 7249ea4df2b4f12a4e7ed446f270cea87e4ffd34 (patch) | |
tree | 7032a11d0cac2ae4d3e90f7a189b575b5a50f848 /src/lib/strconv/decimal_test.go | |
parent | acf6ef7a82b3fe61516a1bac4563706552bdf078 (diff) | |
download | golang-7249ea4df2b4f12a4e7ed446f270cea87e4ffd34.tar.gz |
mv src/lib to src/pkg
tests: all.bash passes, gobuild still works, godoc still works.
R=rsc
OCL=30096
CL=30102
Diffstat (limited to 'src/lib/strconv/decimal_test.go')
-rw-r--r-- | src/lib/strconv/decimal_test.go | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/src/lib/strconv/decimal_test.go b/src/lib/strconv/decimal_test.go deleted file mode 100644 index bc82861bd..000000000 --- a/src/lib/strconv/decimal_test.go +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package strconv - -import ( - "fmt"; - "strconv"; - "testing"; -) - -type shiftTest struct { - i uint64; - shift int; - out string; -} - -var shifttests = []shiftTest { - shiftTest{ 0, -100, "0" }, - shiftTest{ 0, 100, "0" }, - shiftTest{ 1, 100, "1267650600228229401496703205376" }, - shiftTest{ 1, -100, - "0.00000000000000000000000000000078886090522101180541" - "17285652827862296732064351090230047702789306640625" }, - shiftTest{ 12345678, 8, "3160493568" }, - shiftTest{ 12345678, -8, "48225.3046875" }, - shiftTest{ 195312, 9, "99999744" }, - shiftTest{ 1953125, 9, "1000000000" }, -} - -func TestDecimalShift(t *testing.T) { - ok := true; - for i := 0; i < len(shifttests); i++ { - test := &shifttests[i]; - s := strconv.newDecimal(test.i).Shift(test.shift).String(); - if s != test.out { - t.Errorf("Decimal %v << %v = %v, want %v\n", - test.i, test.shift, s, test.out); - } - } -} - -type roundTest struct { - i uint64; - nd int; - down, round, up string; - int uint64; -} - -var roundtests = []roundTest { - roundTest{ 0, 4, "0", "0", "0", 0 }, - roundTest{ 12344999, 4, "12340000", "12340000", "12350000", 12340000 }, - roundTest{ 12345000, 4, "12340000", "12340000", "12350000", 12340000 }, - roundTest{ 12345001, 4, "12340000", "12350000", "12350000", 12350000 }, - roundTest{ 23454999, 4, "23450000", "23450000", "23460000", 23450000 }, - roundTest{ 23455000, 4, "23450000", "23460000", "23460000", 23460000 }, - roundTest{ 23455001, 4, "23450000", "23460000", "23460000", 23460000 }, - - roundTest{ 99994999, 4, "99990000", "99990000", "100000000", 99990000 }, - roundTest{ 99995000, 4, "99990000", "100000000", "100000000", 100000000 }, - roundTest{ 99999999, 4, "99990000", "100000000", "100000000", 100000000 }, - - roundTest{ 12994999, 4, "12990000", "12990000", "13000000", 12990000 }, - roundTest{ 12995000, 4, "12990000", "13000000", "13000000", 13000000 }, - roundTest{ 12999999, 4, "12990000", "13000000", "13000000", 13000000 }, -} - -func TestDecimalRound(t *testing.T) { - for i := 0; i < len(roundtests); i++ { - test := &roundtests[i]; - s := strconv.newDecimal(test.i).RoundDown(test.nd).String(); - if s != test.down { - t.Errorf("Decimal %v RoundDown %d = %v, want %v\n", - test.i, test.nd, s, test.down); - } - s = strconv.newDecimal(test.i).Round(test.nd).String(); - if s != test.round { - t.Errorf("Decimal %v Round %d = %v, want %v\n", - test.i, test.nd, s, test.down); - } - s = strconv.newDecimal(test.i).RoundUp(test.nd).String(); - if s != test.up { - t.Errorf("Decimal %v RoundUp %d = %v, want %v\n", - test.i, test.nd, s, test.up); - } - } -} - -type roundIntTest struct { - i uint64; - shift int; - int uint64; -} - -var roundinttests = []roundIntTest { - roundIntTest{ 0, 100, 0 }, - roundIntTest{ 512, -8, 2 }, - roundIntTest{ 513, -8, 2 }, - roundIntTest{ 640, -8, 2 }, - roundIntTest{ 641, -8, 3 }, - roundIntTest{ 384, -8, 2 }, - roundIntTest{ 385, -8, 2 }, - roundIntTest{ 383, -8, 1 }, - roundIntTest{ 1, 100, 1<<64-1 }, - roundIntTest{ 1000, 0, 1000 }, -} - -func TestDecimalRoundedInteger(t *testing.T) { - for i := 0; i < len(roundinttests); i++ { - test := roundinttests[i]; - // TODO: should be able to use int := here. - int1 := strconv.newDecimal(test.i).Shift(test.shift).RoundedInteger(); - if int1 != test.int { - t.Errorf("Decimal %v >> %v RoundedInteger = %v, want %v\n", - test.i, test.shift, int1, test.int); - } - } -} |