示例#1
0
func TestA2Z2A(t *testing.T) {
	eps := nptest.NewEps(1.e-8, 1.e-6)
	var a float64
	for i := 0; i < 1000; i++ {
		a = 1 - rand.Float64()
		eps.EqFloat64(a, A2Z(Z2A(a)), "A->Z->A", t)
	}
}
示例#2
0
func TestZ2A2Z(t *testing.T) {
	eps := nptest.NewEps(1.e-8, 1.e-6)
	var z float64
	for i := 0; i < 1000; i++ {
		z = 100 * rand.Float64()
		eps.EqFloat64(z, Z2A(A2Z(z)), "Z->A->Z", t)
	}
}
示例#3
0
package lineio

import (
	"testing"

	"github.com/npadmana/npgo/nptest"
)

var (
	eps = nptest.NewEps(1.e-9, 1.e-9)
)

func TestParseFloat64s(t *testing.T) {
	inp := []byte(" 1.234   7.9 -2.3 1.2e4  1.2e-4  ")
	var x, y, z, w, v float64
	err := ParseToFloat64s(inp, []byte{' '}, &x, &y, &z, &w, &v)
	if err != nil {
		t.Error(err)
	}
	eps.EqFloat64(1.234, x, "", t)
	eps.EqFloat64(7.9, y, "", t)
	eps.EqFloat64(-2.3, z, "", t)
	eps.EqFloat64(1.2e4, w, "", t)
	eps.EqFloat64(1.2e-4, v, "", t)
}

func TestParseFloat64Arr1(t *testing.T) {
	inp := []byte(" 1.234   7.9 -2.3 1.2e4  1.2e-4  ")
	truth := []float64{1.234, 7.9, -2.3, 1.2e4, 1.2e-4}
	var out []float64
	err := ParseToFloat64Arr(inp, []byte{' '}, &out, true)
示例#4
0
func TestA2Z(t *testing.T) {
	eps := nptest.NewEps(1.e-8, 1.e-6)
	eps.EqFloat64(0, A2Z(1), "z=0, a=1", t)
	eps.EqFloat64(1, A2Z(0.5), "z=1,a=0.5", t)
	eps.EqFloat64(3, A2Z(0.25), "z=3,a=0.25", t)
}
示例#5
0
func TestZ2A(t *testing.T) {
	eps := nptest.NewEps(1.e-8, 1.e-6)
	eps.EqFloat64(1, Z2A(0), "z=0,a=1", t)
	eps.EqFloat64(0.5, Z2A(1), "z=1,a=0.5", t)
	eps.EqFloat64(0.25, Z2A(3), "z=3,a=0.25", t)
}