Skip to content

Commit

Permalink
all_test.go: uniform names
Browse files Browse the repository at this point in the history
Fixes ALTree#17
  • Loading branch information
ALTree committed May 4, 2016
1 parent 27fd314 commit 18a92ea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
32 changes: 16 additions & 16 deletions exp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestExp(t *testing.T) {
for _, test := range []struct {
x string
z string
want string
}{
{"0", "1"},
Expand All @@ -36,13 +36,13 @@ func TestExp(t *testing.T) {
want := new(big.Float).SetPrec(prec)
want.Parse(test.want, 10)

x := new(big.Float).SetPrec(prec)
x.Parse(test.x, 10)
z := new(big.Float).SetPrec(prec)
z.Parse(test.z, 10)

z := floats.Exp(x)
x := floats.Exp(z)

if z.Cmp(want) != 0 {
t.Errorf("prec = %d, Exp(%v) =\ngot %g;\nwant %g", prec, test.x, z, want)
if x.Cmp(want) != 0 {
t.Errorf("prec = %d, Exp(%v) =\ngot %g;\nwant %g", prec, test.z, x, want)
}
}
}
Expand All @@ -52,8 +52,8 @@ func testExpFloat64(scale float64, nTests int, t *testing.T) {
for i := 0; i < nTests; i++ {
r := rand.Float64() * scale

x := big.NewFloat(r).SetPrec(53)
z64, acc := floats.Exp(x).Float64()
z := big.NewFloat(r)
z64, acc := floats.Exp(z).Float64()

want := math.Exp(r)

Expand All @@ -64,7 +64,7 @@ func testExpFloat64(scale float64, nTests int, t *testing.T) {
//
// Just require a relative error smaller than 1e-14.
if math.Abs(z64-want)/want > 1e-14 || acc != big.Exact {
t.Errorf("Exp(%g) =\n got %g (%s);\nwant %g (Exact)", x, z64, acc, want)
t.Errorf("Exp(%g) =\n got %g (%s);\nwant %g (Exact)", z, z64, acc, want)
}
}
}
Expand Down Expand Up @@ -92,22 +92,22 @@ func TestExpSpecialValues(t *testing.T) {
math.Inf(+1),
math.Inf(-1),
} {
x := big.NewFloat(f).SetPrec(53)
z, acc := floats.Exp(x).Float64()
z := big.NewFloat(f)
x64, acc := floats.Exp(z).Float64()
want := math.Exp(f)
if z != want || acc != big.Exact {
t.Errorf("Log(%f) =\n got %g (%s);\nwant %g (Exact)", f, z, acc, want)
if x64 != want || acc != big.Exact {
t.Errorf("Log(%f) =\n got %g (%s);\nwant %g (Exact)", f, x64, acc, want)
}
}
}

// ---------- Benchmarks ----------

func benchmarkExp(num float64, prec uint, b *testing.B) {
func benchmarkExp(z64 float64, prec uint, b *testing.B) {
b.ReportAllocs()
x := new(big.Float).SetPrec(prec).SetFloat64(num)
z := big.NewFloat(z64).SetPrec(prec)
for n := 0; n < b.N; n++ {
floats.Exp(x)
floats.Exp(z)
}
}

Expand Down
34 changes: 17 additions & 17 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestLog(t *testing.T) {
for _, test := range []struct {
x string
z string
want string
}{
// 350 decimal digits are enough to give us up to 1000 binary digits
Expand All @@ -32,13 +32,13 @@ func TestLog(t *testing.T) {
want := new(big.Float).SetPrec(prec)
want.Parse(test.want, 10)

x := new(big.Float).SetPrec(prec)
x.Parse(test.x, 10)
z := new(big.Float).SetPrec(prec)
z.Parse(test.z, 10)

z := floats.Log(x)
x := floats.Log(z)

if z.Cmp(want) != 0 {
t.Errorf("prec = %d, Log(%v) =\ngot %g;\n want %g", prec, test.x, z, want)
if x.Cmp(want) != 0 {
t.Errorf("prec = %d, Log(%v) =\ngot %g;\n want %g", prec, test.z, x, want)
}
}
}
Expand All @@ -48,8 +48,8 @@ func testLogFloat64(scale float64, nTests int, t *testing.T) {
for i := 0; i < nTests; i++ {
r := rand.Float64() * scale

x := big.NewFloat(r).SetPrec(53)
z64, acc := floats.Log(x).Float64()
z := big.NewFloat(r)
x64, acc := floats.Log(z).Float64()

want := math.Log(r)

Expand All @@ -59,8 +59,8 @@ func testLogFloat64(scale float64, nTests int, t *testing.T) {
// returns a result with the last bit off (see Issue #9546).
//
// Just require a relative error smaller than 1e-14.
if math.Abs(z64-want)/want > 1e-14 || acc != big.Exact {
t.Errorf("Log(%g) =\n got %g (%s);\nwant %g (Exact)", x, z64, acc, want)
if math.Abs(x64-want)/want > 1e-14 || acc != big.Exact {
t.Errorf("Log(%g) =\n got %g (%s);\nwant %g (Exact)", z, x64, acc, want)
}
}
}
Expand All @@ -86,22 +86,22 @@ func TestLogSpecialValues(t *testing.T) {
-0.0,
math.Inf(+1),
} {
x := big.NewFloat(f).SetPrec(53)
z, acc := floats.Log(x).Float64()
z := big.NewFloat(f)
x64, acc := floats.Log(z).Float64()
want := math.Log(f)
if z != want || acc != big.Exact {
t.Errorf("Log(%f) =\n got %g (%s);\nwant %g (Exact)", f, z, acc, want)
if x64 != want || acc != big.Exact {
t.Errorf("Log(%f) =\n got %g (%s);\nwant %g (Exact)", f, x64, acc, want)
}
}
}

// ---------- Benchmarks ----------

func benchmarkLog(num float64, prec uint, b *testing.B) {
func benchmarkLog(z64 float64, prec uint, b *testing.B) {
b.ReportAllocs()
x := new(big.Float).SetPrec(prec).SetFloat64(num)
z := big.NewFloat(z64).SetPrec(prec)
for n := 0; n < b.N; n++ {
floats.Log(x)
floats.Log(z)
}
}

Expand Down
12 changes: 6 additions & 6 deletions pow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ func TestPowFloat64Big(t *testing.T) {

func TestPowSpecialValues(t *testing.T) {
for _, f := range []struct {
w, z float64
z, w float64
}{
{2, +0.0},
{2, -0.0},
{4.2, 1.0},
{math.Inf(+1), 2.0},
} {
w := big.NewFloat(f.w).SetPrec(53)
z := big.NewFloat(f.z).SetPrec(53)
x, acc := floats.Pow(w, z).Float64()
want := math.Pow(f.w, f.z)
if x != want || acc != big.Exact {
t.Errorf("Pow(%g, %g) =\n got %g (%s);\nwant %g (Exact)", f.w, f.z, x, acc, want)
w := big.NewFloat(f.w).SetPrec(53)
x64, acc := floats.Pow(z, w).Float64()
want := math.Pow(f.z, f.w)
if x64 != want || acc != big.Exact {
t.Errorf("Pow(%g, %g) =\n got %g (%s);\nwant %g (Exact)", f.z, f.w, x64, acc, want)
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions sqrt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const maxPrec uint = 1100

func TestSqrt(t *testing.T) {
for _, test := range []struct {
x string
z string
want string
}{
// 350 decimal digits are enough to give us up to 1000 binary digits
Expand Down Expand Up @@ -57,13 +57,13 @@ func TestSqrt(t *testing.T) {
want := new(big.Float).SetPrec(prec)
want.Parse(test.want, 10)

x := new(big.Float).SetPrec(prec)
x.Parse(test.x, 10)
z := new(big.Float).SetPrec(prec)
z.Parse(test.z, 10)

z := floats.Sqrt(x)
x := floats.Sqrt(z)

if z.Cmp(want) != 0 {
t.Errorf("prec = %d, Sqrt(%v) =\ngot %g;\nwant %g", prec, test.x, z, want)
if x.Cmp(want) != 0 {
t.Errorf("prec = %d, Sqrt(%v) =\ngot %g;\nwant %g", prec, test.z, x, want)
}
}
}
Expand All @@ -73,13 +73,13 @@ func testSqrtFloat64(scale float64, nTests int, t *testing.T) {
for i := 0; i < nTests; i++ {
r := rand.Float64() * scale

x := big.NewFloat(r).SetPrec(53)
z64, acc := floats.Sqrt(x).Float64()
z := big.NewFloat(r)
x64, acc := floats.Sqrt(z).Float64()

want := math.Sqrt(r)

if z64 != want || acc != big.Exact {
t.Errorf("Sqrt(%g) =\n got %g (%s);\nwant %g (Exact)", x, z64, acc, want)
if x64 != want || acc != big.Exact {
t.Errorf("Sqrt(%g) =\n got %g (%s);\nwant %g (Exact)", z, x64, acc, want)
}
}
}
Expand All @@ -105,22 +105,22 @@ func TestSqrtSpecialValues(t *testing.T) {
-0.0,
math.Inf(+1),
} {
x := big.NewFloat(f).SetPrec(53)
z, acc := floats.Sqrt(x).Float64()
z := big.NewFloat(f)
x64, acc := floats.Sqrt(z).Float64()
want := math.Sqrt(f)
if z != want || acc != big.Exact {
t.Errorf("Sqrt(%g) =\n got %g (%s);\nwant %g (Exact)", f, z, acc, want)
if x64 != want || acc != big.Exact {
t.Errorf("Sqrt(%g) =\n got %g (%s);\nwant %g (Exact)", z, x64, acc, want)
}
}
}

// ---------- Benchmarks ----------

func benchmarkSqrt(num float64, prec uint, b *testing.B) {
func benchmarkSqrt(z64 float64, prec uint, b *testing.B) {
b.ReportAllocs()
x := new(big.Float).SetPrec(prec).SetFloat64(num)
z := big.NewFloat(z64).SetPrec(prec)
for n := 0; n < b.N; n++ {
floats.Sqrt(x)
floats.Sqrt(z)
}
}

Expand Down

0 comments on commit 18a92ea

Please sign in to comment.