mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
vendor cleanup: remove unused,non-go and test files
This commit is contained in:
210
vendor/gopkg.in/inf.v0/benchmark_test.go
generated
vendored
210
vendor/gopkg.in/inf.v0/benchmark_test.go
generated
vendored
@ -1,210 +0,0 @@
|
||||
package inf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const maxcap = 1024 * 1024
|
||||
const bits = 256
|
||||
const maxscale = 32
|
||||
|
||||
var once sync.Once
|
||||
|
||||
var decInput [][2]Dec
|
||||
var intInput [][2]big.Int
|
||||
|
||||
var initBench = func() {
|
||||
decInput = make([][2]Dec, maxcap)
|
||||
intInput = make([][2]big.Int, maxcap)
|
||||
max := new(big.Int).Lsh(big.NewInt(1), bits)
|
||||
r := rand.New(rand.NewSource(0))
|
||||
for i := 0; i < cap(decInput); i++ {
|
||||
decInput[i][0].SetUnscaledBig(new(big.Int).Rand(r, max)).
|
||||
SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale)))
|
||||
decInput[i][1].SetUnscaledBig(new(big.Int).Rand(r, max)).
|
||||
SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale)))
|
||||
}
|
||||
for i := 0; i < cap(intInput); i++ {
|
||||
intInput[i][0].Rand(r, max)
|
||||
intInput[i][1].Rand(r, max)
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkDec1(b *testing.B, f func(z *Dec)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&decInput[i%maxcap][0])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkDec2(b *testing.B, f func(x, y *Dec)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&decInput[i%maxcap][0], &decInput[i%maxcap][1])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkInt1(b *testing.B, f func(z *big.Int)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&intInput[i%maxcap][0])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkInt2(b *testing.B, f func(x, y *big.Int)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&intInput[i%maxcap][0], &intInput[i%maxcap][1])
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Dec_String(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
x.String()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_StringScan(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
s := x.String()
|
||||
d := new(Dec)
|
||||
fmt.Sscan(s, d)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_GobEncode(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
x.GobEncode()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_GobEnDecode(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
g, _ := x.GobEncode()
|
||||
new(Dec).GobDecode(g)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Add(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
ys := y.Scale()
|
||||
y.SetScale(x.Scale())
|
||||
_ = new(Dec).Add(x, y)
|
||||
y.SetScale(ys)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_AddMixed(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Add(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Sub(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
ys := y.Scale()
|
||||
y.SetScale(x.Scale())
|
||||
_ = new(Dec).Sub(x, y)
|
||||
y.SetScale(ys)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_SubMixed(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Sub(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Mul(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Mul(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Mul_QuoExact(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
v := new(Dec).Mul(x, y)
|
||||
_ = new(Dec).QuoExact(v, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_QuoRound_Fixed_Down(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).QuoRound(x, y, 0, RoundDown)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_QuoRound_Fixed_HalfUp(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).QuoRound(x, y, 0, RoundHalfUp)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_String(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
x.String()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_StringScan(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
s := x.String()
|
||||
d := new(big.Int)
|
||||
fmt.Sscan(s, d)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_GobEncode(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
x.GobEncode()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_GobEnDecode(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
g, _ := x.GobEncode()
|
||||
new(big.Int).GobDecode(g)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Add(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Add(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Sub(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Sub(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Mul(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Mul(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Quo(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Quo(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_QuoRem(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_, _ = new(big.Int).QuoRem(x, y, new(big.Int))
|
||||
})
|
||||
}
|
33
vendor/gopkg.in/inf.v0/dec_go1_2_test.go
generated
vendored
33
vendor/gopkg.in/inf.v0/dec_go1_2_test.go
generated
vendored
@ -1,33 +0,0 @@
|
||||
// +build go1.2
|
||||
|
||||
package inf
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ encoding.TextMarshaler = new(Dec)
|
||||
var _ encoding.TextUnmarshaler = new(Dec)
|
||||
|
||||
type Obj struct {
|
||||
Val *Dec
|
||||
}
|
||||
|
||||
func TestDecJsonMarshalUnmarshal(t *testing.T) {
|
||||
o := Obj{Val: NewDec(123, 2)}
|
||||
js, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal(%v): got %v, want ok", o, err)
|
||||
}
|
||||
o2 := &Obj{}
|
||||
err = json.Unmarshal(js, o2)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Unmarshal(%#q): got %v, want ok", js, err)
|
||||
}
|
||||
if o.Val.Scale() != o2.Val.Scale() ||
|
||||
o.Val.UnscaledBig().Cmp(o2.Val.UnscaledBig()) != 0 {
|
||||
t.Fatalf("json.Unmarshal(json.Marshal(%v)): want %v, got %v", o, o, o2)
|
||||
}
|
||||
}
|
40
vendor/gopkg.in/inf.v0/dec_internal_test.go
generated
vendored
40
vendor/gopkg.in/inf.v0/dec_internal_test.go
generated
vendored
@ -1,40 +0,0 @@
|
||||
package inf
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var decQuoRemZZZ = []struct {
|
||||
z, x, y *Dec
|
||||
r *big.Rat
|
||||
srA, srB int
|
||||
}{
|
||||
// basic examples
|
||||
{NewDec(1, 0), NewDec(2, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(15, 1), NewDec(3, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(1, 1), NewDec(1, 0), NewDec(10, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(0, 0), NewDec(2, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1},
|
||||
{NewDec(0, 0), NewDec(2, 0), NewDec(6, 0), big.NewRat(1, 3), 1, 1},
|
||||
{NewDec(1, 1), NewDec(2, 0), NewDec(12, 0), big.NewRat(2, 3), 1, 1},
|
||||
|
||||
// examples from the Go Language Specification
|
||||
{NewDec(1, 0), NewDec(5, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1},
|
||||
{NewDec(-1, 0), NewDec(-5, 0), NewDec(3, 0), big.NewRat(-2, 3), -1, 1},
|
||||
{NewDec(-1, 0), NewDec(5, 0), NewDec(-3, 0), big.NewRat(-2, 3), 1, -1},
|
||||
{NewDec(1, 0), NewDec(-5, 0), NewDec(-3, 0), big.NewRat(2, 3), -1, -1},
|
||||
}
|
||||
|
||||
func TestDecQuoRem(t *testing.T) {
|
||||
for i, a := range decQuoRemZZZ {
|
||||
z, rA, rB := new(Dec), new(big.Int), new(big.Int)
|
||||
s := scaleQuoExact{}.Scale(a.x, a.y)
|
||||
z.quoRem(a.x, a.y, s, true, rA, rB)
|
||||
if a.z.Cmp(z) != 0 || a.r.Cmp(new(big.Rat).SetFrac(rA, rB)) != 0 {
|
||||
t.Errorf("#%d QuoRemZZZ got %v, %v, %v; expected %v, %v", i, z, rA, rB, a.z, a.r)
|
||||
}
|
||||
if a.srA != rA.Sign() || a.srB != rB.Sign() {
|
||||
t.Errorf("#%d QuoRemZZZ wrong signs, got %v, %v; expected %v, %v", i, rA.Sign(), rB.Sign(), a.srA, a.srB)
|
||||
}
|
||||
}
|
||||
}
|
379
vendor/gopkg.in/inf.v0/dec_test.go
generated
vendored
379
vendor/gopkg.in/inf.v0/dec_test.go
generated
vendored
@ -1,379 +0,0 @@
|
||||
package inf_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
type decFunZZ func(z, x, y *inf.Dec) *inf.Dec
|
||||
type decArgZZ struct {
|
||||
z, x, y *inf.Dec
|
||||
}
|
||||
|
||||
var decSumZZ = []decArgZZ{
|
||||
{inf.NewDec(0, 0), inf.NewDec(0, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1, 0), inf.NewDec(1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1111111110, 0), inf.NewDec(123456789, 0), inf.NewDec(987654321, 0)},
|
||||
{inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(864197532, 0), inf.NewDec(-123456789, 0), inf.NewDec(987654321, 0)},
|
||||
{inf.NewDec(-1111111110, 0), inf.NewDec(-123456789, 0), inf.NewDec(-987654321, 0)},
|
||||
{inf.NewDec(12, 2), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
}
|
||||
|
||||
var decProdZZ = []decArgZZ{
|
||||
{inf.NewDec(0, 0), inf.NewDec(0, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(0, 0), inf.NewDec(1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1, 0), inf.NewDec(1, 0), inf.NewDec(1, 0)},
|
||||
{inf.NewDec(-991*991, 0), inf.NewDec(991, 0), inf.NewDec(-991, 0)},
|
||||
{inf.NewDec(2, 3), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
{inf.NewDec(2, -3), inf.NewDec(1, -1), inf.NewDec(2, -2)},
|
||||
{inf.NewDec(2, 3), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
}
|
||||
|
||||
func TestDecSignZ(t *testing.T) {
|
||||
var zero inf.Dec
|
||||
for _, a := range decSumZZ {
|
||||
s := a.z.Sign()
|
||||
e := a.z.Cmp(&zero)
|
||||
if s != e {
|
||||
t.Errorf("got %d; want %d for z = %v", s, e, a.z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecAbsZ(t *testing.T) {
|
||||
var zero inf.Dec
|
||||
for _, a := range decSumZZ {
|
||||
var z inf.Dec
|
||||
z.Abs(a.z)
|
||||
var e inf.Dec
|
||||
e.Set(a.z)
|
||||
if e.Cmp(&zero) < 0 {
|
||||
e.Sub(&zero, &e)
|
||||
}
|
||||
if z.Cmp(&e) != 0 {
|
||||
t.Errorf("got z = %v; want %v", z, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDecFunZZ(t *testing.T, msg string, f decFunZZ, a decArgZZ) {
|
||||
var z inf.Dec
|
||||
f(&z, a.x, a.y)
|
||||
if (&z).Cmp(a.z) != 0 {
|
||||
t.Errorf("%s%+v\n\tgot z = %v; want %v", msg, a, &z, a.z)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecSumZZ(t *testing.T) {
|
||||
AddZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Add(x, y) }
|
||||
SubZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Sub(x, y) }
|
||||
for _, a := range decSumZZ {
|
||||
arg := a
|
||||
testDecFunZZ(t, "AddZZ", AddZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.z, a.y, a.x}
|
||||
testDecFunZZ(t, "AddZZ symmetric", AddZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.x, a.z, a.y}
|
||||
testDecFunZZ(t, "SubZZ", SubZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.y, a.z, a.x}
|
||||
testDecFunZZ(t, "SubZZ symmetric", SubZZ, arg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecProdZZ(t *testing.T) {
|
||||
MulZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Mul(x, y) }
|
||||
for _, a := range decProdZZ {
|
||||
arg := a
|
||||
testDecFunZZ(t, "MulZZ", MulZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.z, a.y, a.x}
|
||||
testDecFunZZ(t, "MulZZ symmetric", MulZZ, arg)
|
||||
}
|
||||
}
|
||||
|
||||
var decUnscaledTests = []struct {
|
||||
d *inf.Dec
|
||||
u int64 // ignored when ok == false
|
||||
ok bool
|
||||
}{
|
||||
{new(inf.Dec), 0, true},
|
||||
{inf.NewDec(-1<<63, 0), -1 << 63, true},
|
||||
{inf.NewDec(-(-1<<63 + 1), 0), -(-1<<63 + 1), true},
|
||||
{new(inf.Dec).Neg(inf.NewDec(-1<<63, 0)), 0, false},
|
||||
{new(inf.Dec).Sub(inf.NewDec(-1<<63, 0), inf.NewDec(1, 0)), 0, false},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), 0, false},
|
||||
}
|
||||
|
||||
func TestDecUnscaled(t *testing.T) {
|
||||
for i, tt := range decUnscaledTests {
|
||||
u, ok := tt.d.Unscaled()
|
||||
if ok != tt.ok {
|
||||
t.Errorf("#%d Unscaled: got %v, expected %v", i, ok, tt.ok)
|
||||
} else if ok && u != tt.u {
|
||||
t.Errorf("#%d Unscaled: got %v, expected %v", i, u, tt.u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decRoundTests = [...]struct {
|
||||
in *inf.Dec
|
||||
s inf.Scale
|
||||
r inf.Rounder
|
||||
exp *inf.Dec
|
||||
}{
|
||||
{inf.NewDec(123424999999999993, 15), 2, inf.RoundHalfUp, inf.NewDec(12342, 2)},
|
||||
{inf.NewDec(123425000000000001, 15), 2, inf.RoundHalfUp, inf.NewDec(12343, 2)},
|
||||
{inf.NewDec(123424999999999993, 15), 15, inf.RoundHalfUp, inf.NewDec(123424999999999993, 15)},
|
||||
{inf.NewDec(123424999999999993, 15), 16, inf.RoundHalfUp, inf.NewDec(1234249999999999930, 16)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -1, inf.RoundHalfUp, inf.NewDec(1844674407370955162, -1)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -2, inf.RoundHalfUp, inf.NewDec(184467440737095516, -2)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -3, inf.RoundHalfUp, inf.NewDec(18446744073709552, -3)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -4, inf.RoundHalfUp, inf.NewDec(1844674407370955, -4)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -5, inf.RoundHalfUp, inf.NewDec(184467440737096, -5)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -6, inf.RoundHalfUp, inf.NewDec(18446744073710, -6)},
|
||||
}
|
||||
|
||||
func TestDecRound(t *testing.T) {
|
||||
for i, tt := range decRoundTests {
|
||||
z := new(inf.Dec).Round(tt.in, tt.s, tt.r)
|
||||
if tt.exp.Cmp(z) != 0 {
|
||||
t.Errorf("#%d Round got %v; expected %v", i, z, tt.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decStringTests = []struct {
|
||||
in string
|
||||
out string
|
||||
val int64
|
||||
scale inf.Scale // skip SetString if negative
|
||||
ok bool
|
||||
scanOk bool
|
||||
}{
|
||||
{in: "", ok: false, scanOk: false},
|
||||
{in: "a", ok: false, scanOk: false},
|
||||
{in: "z", ok: false, scanOk: false},
|
||||
{in: "+", ok: false, scanOk: false},
|
||||
{in: "-", ok: false, scanOk: false},
|
||||
{in: "g", ok: false, scanOk: false},
|
||||
{in: ".", ok: false, scanOk: false},
|
||||
{in: ".-0", ok: false, scanOk: false},
|
||||
{in: ".+0", ok: false, scanOk: false},
|
||||
// Scannable but not SetStringable
|
||||
{"0b", "ignored", 0, 0, false, true},
|
||||
{"0x", "ignored", 0, 0, false, true},
|
||||
{"0xg", "ignored", 0, 0, false, true},
|
||||
{"0.0g", "ignored", 0, 1, false, true},
|
||||
// examples from godoc for Dec
|
||||
{"0", "0", 0, 0, true, true},
|
||||
{"0.00", "0.00", 0, 2, true, true},
|
||||
{"ignored", "0", 0, -2, true, false},
|
||||
{"1", "1", 1, 0, true, true},
|
||||
{"1.00", "1.00", 100, 2, true, true},
|
||||
{"10", "10", 10, 0, true, true},
|
||||
{"ignored", "10", 1, -1, true, false},
|
||||
// other tests
|
||||
{"+0", "0", 0, 0, true, true},
|
||||
{"-0", "0", 0, 0, true, true},
|
||||
{"0.0", "0.0", 0, 1, true, true},
|
||||
{"0.1", "0.1", 1, 1, true, true},
|
||||
{"0.", "0", 0, 0, true, true},
|
||||
{"-10", "-10", -1, -1, true, true},
|
||||
{"-1", "-1", -1, 0, true, true},
|
||||
{"-0.1", "-0.1", -1, 1, true, true},
|
||||
{"-0.01", "-0.01", -1, 2, true, true},
|
||||
{"+0.", "0", 0, 0, true, true},
|
||||
{"-0.", "0", 0, 0, true, true},
|
||||
{".0", "0.0", 0, 1, true, true},
|
||||
{"+.0", "0.0", 0, 1, true, true},
|
||||
{"-.0", "0.0", 0, 1, true, true},
|
||||
{"0.0000000000", "0.0000000000", 0, 10, true, true},
|
||||
{"0.0000000001", "0.0000000001", 1, 10, true, true},
|
||||
{"-0.0000000000", "0.0000000000", 0, 10, true, true},
|
||||
{"-0.0000000001", "-0.0000000001", -1, 10, true, true},
|
||||
{"-10", "-10", -10, 0, true, true},
|
||||
{"+10", "10", 10, 0, true, true},
|
||||
{"00", "0", 0, 0, true, true},
|
||||
{"023", "23", 23, 0, true, true}, // decimal, not octal
|
||||
{"-02.3", "-2.3", -23, 1, true, true}, // decimal, not octal
|
||||
}
|
||||
|
||||
func TestDecGetString(t *testing.T) {
|
||||
z := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if !test.ok {
|
||||
continue
|
||||
}
|
||||
z.SetUnscaled(test.val)
|
||||
z.SetScale(test.scale)
|
||||
|
||||
s := z.String()
|
||||
if s != test.out {
|
||||
t.Errorf("#%da got %s; want %s", i, s, test.out)
|
||||
}
|
||||
|
||||
s = fmt.Sprintf("%d", z)
|
||||
if s != test.out {
|
||||
t.Errorf("#%db got %s; want %s", i, s, test.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecSetString(t *testing.T) {
|
||||
tmp := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if test.scale < 0 {
|
||||
// SetString only supports scale >= 0
|
||||
continue
|
||||
}
|
||||
// initialize to a non-zero value so that issues with parsing
|
||||
// 0 are detected
|
||||
tmp.Set(inf.NewDec(1234567890, 123))
|
||||
n1, ok1 := new(inf.Dec).SetString(test.in)
|
||||
n2, ok2 := tmp.SetString(test.in)
|
||||
expected := inf.NewDec(test.val, test.scale)
|
||||
if ok1 != test.ok || ok2 != test.ok {
|
||||
t.Errorf("#%d (input '%s') ok incorrect (should be %t)", i, test.in, test.ok)
|
||||
continue
|
||||
}
|
||||
if !ok1 {
|
||||
if n1 != nil {
|
||||
t.Errorf("#%d (input '%s') n1 != nil", i, test.in)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !ok2 {
|
||||
if n2 != nil {
|
||||
t.Errorf("#%d (input '%s') n2 != nil", i, test.in)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if n1.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val)
|
||||
}
|
||||
if n2.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecScan(t *testing.T) {
|
||||
tmp := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if test.scale < 0 {
|
||||
// SetString only supports scale >= 0
|
||||
continue
|
||||
}
|
||||
// initialize to a non-zero value so that issues with parsing
|
||||
// 0 are detected
|
||||
tmp.Set(inf.NewDec(1234567890, 123))
|
||||
n1, n2 := new(inf.Dec), tmp
|
||||
nn1, err1 := fmt.Sscan(test.in, n1)
|
||||
nn2, err2 := fmt.Sscan(test.in, n2)
|
||||
if !test.scanOk {
|
||||
if err1 == nil || err2 == nil {
|
||||
t.Errorf("#%d (input '%s') ok incorrect, should be %t", i, test.in, test.scanOk)
|
||||
}
|
||||
continue
|
||||
}
|
||||
expected := inf.NewDec(test.val, test.scale)
|
||||
if nn1 != 1 || err1 != nil || nn2 != 1 || err2 != nil {
|
||||
t.Errorf("#%d (input '%s') error %d %v, %d %v", i, test.in, nn1, err1, nn2, err2)
|
||||
continue
|
||||
}
|
||||
if n1.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val)
|
||||
}
|
||||
if n2.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decScanNextTests = []struct {
|
||||
in string
|
||||
ok bool
|
||||
next rune
|
||||
}{
|
||||
{"", false, 0},
|
||||
{"a", false, 'a'},
|
||||
{"z", false, 'z'},
|
||||
{"+", false, 0},
|
||||
{"-", false, 0},
|
||||
{"g", false, 'g'},
|
||||
{".", false, 0},
|
||||
{".-0", false, '-'},
|
||||
{".+0", false, '+'},
|
||||
{"0b", true, 'b'},
|
||||
{"0x", true, 'x'},
|
||||
{"0xg", true, 'x'},
|
||||
{"0.0g", true, 'g'},
|
||||
}
|
||||
|
||||
func TestDecScanNext(t *testing.T) {
|
||||
for i, test := range decScanNextTests {
|
||||
rdr := strings.NewReader(test.in)
|
||||
n1 := new(inf.Dec)
|
||||
nn1, _ := fmt.Fscan(rdr, n1)
|
||||
if (test.ok && nn1 == 0) || (!test.ok && nn1 > 0) {
|
||||
t.Errorf("#%d (input '%s') ok incorrect should be %t", i, test.in, test.ok)
|
||||
continue
|
||||
}
|
||||
r := rune(0)
|
||||
nn2, err := fmt.Fscanf(rdr, "%c", &r)
|
||||
if test.next != r {
|
||||
t.Errorf("#%d (input '%s') next incorrect, got %c should be %c, %d, %v", i, test.in, r, test.next, nn2, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decGobEncodingTests = []string{
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"10",
|
||||
"42",
|
||||
"1234567890",
|
||||
"298472983472983471903246121093472394872319615612417471234712061",
|
||||
}
|
||||
|
||||
func TestDecGobEncoding(t *testing.T) {
|
||||
var medium bytes.Buffer
|
||||
enc := gob.NewEncoder(&medium)
|
||||
dec := gob.NewDecoder(&medium)
|
||||
for i, test := range decGobEncodingTests {
|
||||
for j := 0; j < 2; j++ {
|
||||
for k := inf.Scale(-5); k <= 5; k++ {
|
||||
medium.Reset() // empty buffer for each test case (in case of failures)
|
||||
stest := test
|
||||
if j != 0 {
|
||||
// negative numbers
|
||||
stest = "-" + test
|
||||
}
|
||||
var tx inf.Dec
|
||||
tx.SetString(stest)
|
||||
tx.SetScale(k) // test with positive, negative, and zero scale
|
||||
if err := enc.Encode(&tx); err != nil {
|
||||
t.Errorf("#%d%c: encoding failed: %s", i, 'a'+j, err)
|
||||
}
|
||||
var rx inf.Dec
|
||||
if err := dec.Decode(&rx); err != nil {
|
||||
t.Errorf("#%d%c: decoding failed: %s", i, 'a'+j, err)
|
||||
}
|
||||
if rx.Cmp(&tx) != 0 {
|
||||
t.Errorf("#%d%c: transmission failed: got %s want %s", i, 'a'+j, &rx, &tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
vendor/gopkg.in/inf.v0/example_test.go
generated
vendored
62
vendor/gopkg.in/inf.v0/example_test.go
generated
vendored
@ -1,62 +0,0 @@
|
||||
package inf_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
import "gopkg.in/inf.v0"
|
||||
|
||||
func ExampleDec_SetString() {
|
||||
d := new(inf.Dec)
|
||||
d.SetString("012345.67890") // decimal; leading 0 ignored; trailing 0 kept
|
||||
fmt.Println(d)
|
||||
// Output: 12345.67890
|
||||
}
|
||||
|
||||
func ExampleDec_Scan() {
|
||||
// The Scan function is rarely used directly;
|
||||
// the fmt package recognizes it as an implementation of fmt.Scanner.
|
||||
d := new(inf.Dec)
|
||||
_, err := fmt.Sscan("184467440.73709551617", d)
|
||||
if err != nil {
|
||||
log.Println("error scanning value:", err)
|
||||
} else {
|
||||
fmt.Println(d)
|
||||
}
|
||||
// Output: 184467440.73709551617
|
||||
}
|
||||
|
||||
func ExampleDec_QuoRound_scale2RoundDown() {
|
||||
// 10 / 3 is an infinite decimal; it has no exact Dec representation
|
||||
x, y := inf.NewDec(10, 0), inf.NewDec(3, 0)
|
||||
// use 2 digits beyond the decimal point, round towards 0
|
||||
z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundDown)
|
||||
fmt.Println(z)
|
||||
// Output: 3.33
|
||||
}
|
||||
|
||||
func ExampleDec_QuoRound_scale2RoundCeil() {
|
||||
// -42 / 400 is an finite decimal with 3 digits beyond the decimal point
|
||||
x, y := inf.NewDec(-42, 0), inf.NewDec(400, 0)
|
||||
// use 2 digits beyond decimal point, round towards positive infinity
|
||||
z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundCeil)
|
||||
fmt.Println(z)
|
||||
// Output: -0.10
|
||||
}
|
||||
|
||||
func ExampleDec_QuoExact_ok() {
|
||||
// 1 / 25 is a finite decimal; it has exact Dec representation
|
||||
x, y := inf.NewDec(1, 0), inf.NewDec(25, 0)
|
||||
z := new(inf.Dec).QuoExact(x, y)
|
||||
fmt.Println(z)
|
||||
// Output: 0.04
|
||||
}
|
||||
|
||||
func ExampleDec_QuoExact_fail() {
|
||||
// 1 / 3 is an infinite decimal; it has no exact Dec representation
|
||||
x, y := inf.NewDec(1, 0), inf.NewDec(3, 0)
|
||||
z := new(inf.Dec).QuoExact(x, y)
|
||||
fmt.Println(z)
|
||||
// Output: <nil>
|
||||
}
|
73
vendor/gopkg.in/inf.v0/rounder_example_test.go
generated
vendored
73
vendor/gopkg.in/inf.v0/rounder_example_test.go
generated
vendored
@ -1,73 +0,0 @@
|
||||
package inf_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
// This example displays the results of Dec.Round with each of the Rounders.
|
||||
//
|
||||
func ExampleRounder() {
|
||||
var vals = []struct {
|
||||
x string
|
||||
s inf.Scale
|
||||
}{
|
||||
{"-0.18", 1}, {"-0.15", 1}, {"-0.12", 1}, {"-0.10", 1},
|
||||
{"-0.08", 1}, {"-0.05", 1}, {"-0.02", 1}, {"0.00", 1},
|
||||
{"0.02", 1}, {"0.05", 1}, {"0.08", 1}, {"0.10", 1},
|
||||
{"0.12", 1}, {"0.15", 1}, {"0.18", 1},
|
||||
}
|
||||
|
||||
var rounders = []struct {
|
||||
name string
|
||||
rounder inf.Rounder
|
||||
}{
|
||||
{"RoundDown", inf.RoundDown}, {"RoundUp", inf.RoundUp},
|
||||
{"RoundCeil", inf.RoundCeil}, {"RoundFloor", inf.RoundFloor},
|
||||
{"RoundHalfDown", inf.RoundHalfDown}, {"RoundHalfUp", inf.RoundHalfUp},
|
||||
{"RoundHalfEven", inf.RoundHalfEven}, {"RoundExact", inf.RoundExact},
|
||||
}
|
||||
|
||||
fmt.Println("The results of new(inf.Dec).Round(x, s, inf.RoundXXX):")
|
||||
fmt.Println()
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight)
|
||||
fmt.Fprint(w, "x\ts\t|\t")
|
||||
for _, r := range rounders {
|
||||
fmt.Fprintf(w, "%s\t", r.name[5:])
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
for _, v := range vals {
|
||||
fmt.Fprintf(w, "%s\t%d\t|\t", v.x, v.s)
|
||||
for _, r := range rounders {
|
||||
x, _ := new(inf.Dec).SetString(v.x)
|
||||
z := new(inf.Dec).Round(x, v.s, r.rounder)
|
||||
fmt.Fprintf(w, "%d\t", z)
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
// Output:
|
||||
// The results of new(inf.Dec).Round(x, s, inf.RoundXXX):
|
||||
//
|
||||
// x s | Down Up Ceil Floor HalfDown HalfUp HalfEven Exact
|
||||
// -0.18 1 | -0.1 -0.2 -0.1 -0.2 -0.2 -0.2 -0.2 <nil>
|
||||
// -0.15 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.2 -0.2 <nil>
|
||||
// -0.12 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.1 -0.1 <nil>
|
||||
// -0.10 1 | -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1
|
||||
// -0.08 1 | 0.0 -0.1 0.0 -0.1 -0.1 -0.1 -0.1 <nil>
|
||||
// -0.05 1 | 0.0 -0.1 0.0 -0.1 0.0 -0.1 0.0 <nil>
|
||||
// -0.02 1 | 0.0 -0.1 0.0 -0.1 0.0 0.0 0.0 <nil>
|
||||
// 0.00 1 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
|
||||
// 0.02 1 | 0.0 0.1 0.1 0.0 0.0 0.0 0.0 <nil>
|
||||
// 0.05 1 | 0.0 0.1 0.1 0.0 0.0 0.1 0.0 <nil>
|
||||
// 0.08 1 | 0.0 0.1 0.1 0.0 0.1 0.1 0.1 <nil>
|
||||
// 0.10 1 | 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
|
||||
// 0.12 1 | 0.1 0.2 0.2 0.1 0.1 0.1 0.1 <nil>
|
||||
// 0.15 1 | 0.1 0.2 0.2 0.1 0.1 0.2 0.2 <nil>
|
||||
// 0.18 1 | 0.1 0.2 0.2 0.1 0.2 0.2 0.2 <nil>
|
||||
|
||||
}
|
109
vendor/gopkg.in/inf.v0/rounder_test.go
generated
vendored
109
vendor/gopkg.in/inf.v0/rounder_test.go
generated
vendored
@ -1,109 +0,0 @@
|
||||
package inf_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
var decRounderInputs = [...]struct {
|
||||
quo *inf.Dec
|
||||
rA, rB *big.Int
|
||||
}{
|
||||
// examples from go language spec
|
||||
{inf.NewDec(1, 0), big.NewInt(2), big.NewInt(3)}, // 5 / 3
|
||||
{inf.NewDec(-1, 0), big.NewInt(-2), big.NewInt(3)}, // -5 / 3
|
||||
{inf.NewDec(-1, 0), big.NewInt(2), big.NewInt(-3)}, // 5 / -3
|
||||
{inf.NewDec(1, 0), big.NewInt(-2), big.NewInt(-3)}, // -5 / -3
|
||||
// examples from godoc
|
||||
{inf.NewDec(-1, 1), big.NewInt(-8), big.NewInt(10)},
|
||||
{inf.NewDec(-1, 1), big.NewInt(-5), big.NewInt(10)},
|
||||
{inf.NewDec(-1, 1), big.NewInt(-2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-8), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-5), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(0), big.NewInt(1)},
|
||||
{inf.NewDec(0, 1), big.NewInt(2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(5), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(8), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(2), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(5), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(8), big.NewInt(10)},
|
||||
}
|
||||
|
||||
var decRounderResults = [...]struct {
|
||||
rounder inf.Rounder
|
||||
results [len(decRounderInputs)]*inf.Dec
|
||||
}{
|
||||
{inf.RoundExact, [...]*inf.Dec{nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil,
|
||||
inf.NewDec(0, 1), nil, nil, nil, nil, nil, nil}},
|
||||
{inf.RoundDown, [...]*inf.Dec{
|
||||
inf.NewDec(1, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(1, 0),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}},
|
||||
{inf.RoundUp, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfDown, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfUp, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfEven, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundFloor, [...]*inf.Dec{
|
||||
inf.NewDec(1, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(1, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}},
|
||||
{inf.RoundCeil, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
}
|
||||
|
||||
func TestDecRounders(t *testing.T) {
|
||||
for i, a := range decRounderResults {
|
||||
for j, input := range decRounderInputs {
|
||||
q := new(inf.Dec).Set(input.quo)
|
||||
rA, rB := new(big.Int).Set(input.rA), new(big.Int).Set(input.rB)
|
||||
res := a.rounder.Round(new(inf.Dec), q, rA, rB)
|
||||
if a.results[j] == nil && res == nil {
|
||||
continue
|
||||
}
|
||||
if (a.results[j] == nil && res != nil) ||
|
||||
(a.results[j] != nil && res == nil) ||
|
||||
a.results[j].Cmp(res) != 0 {
|
||||
t.Errorf("#%d,%d Rounder got %v; expected %v", i, j, res, a.results[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user