示例#1
0
func TestLnFact(t *testing.T) {
	var (
		n uint32
		e float64
		r float64
		d float64
	)
	n, e = 0, 0.0
	r, d = LnFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 1, 0.0
	r, d = LnFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 7, 8.525161361065414300
	r, d = LnFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 33, 85.05446701758151741
	r, d = LnFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnFact: result %.5f, expected %.5f\n", r, e)
	}

}
示例#2
0
func TestQags(t *testing.T) {
	{

		exp_result := 7.716049382715789440E-02
		exp_abserr := 2.216394961010438404E-12

		alpha := 2.6
		f := f1{alpha: alpha}
		result, abserr, status := Qags(f, 0.0, 1.0, 0.0, 1e-10, 1000)
		if !assert.EqualFloat64(result, exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}

		result, abserr, status = Qags(f, 1.0, 0.0, 0.0, 1e-10, 1000)
		if !assert.EqualFloat64(result, -exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, -exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}
	}

}
示例#3
0
func TestFact(t *testing.T) {
	var (
		n uint32
		e float64
		r float64
		d float64
	)
	n, e = 0, 1.0
	r, d = Fact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Fact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 1, 1.0
	r, d = Fact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Fact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 7, 5040.0
	r, d = Fact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Fact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 33, 8.683317618811886496e+36
	r, d = Fact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Fact: result %.5f, expected %.5f\n", r, e)
	}

}
示例#4
0
func testQK(f F, exp_result, exp_abserr, exp_resabs, exp_resasc float, qk QkFunction, a, b float64, prefix string, t *testing.T) {
	var result, abserr, resabs, resasc float64
	result, abserr, resabs, resasc = qk(f, a, b)
	if !assert.EqualFloat64(result, exp_result.value, exp_result.precision, 0) {
		t.Errorf("%s: result: %.15f, expected: %.15f\n", prefix, result, exp_result.value)
	}
	if !assert.EqualFloat64(abserr, exp_abserr.value, exp_abserr.precision, 0) {
		t.Errorf("%s: abserr: %.7f, expected: %.7f\n", prefix, abserr, exp_abserr.value)
	}
	if !assert.EqualFloat64(resabs, exp_resabs.value, exp_resabs.precision, 0) {
		t.Errorf("%s: resabs: %.15f, expected: %.15f\n", prefix, resabs, exp_resabs.value)
	}
	if !assert.EqualFloat64(resasc, exp_resasc.value, exp_resasc.precision, 0) {
		t.Errorf("%s: resasc: %.15f, expected: %.15f\n", prefix, resasc, exp_resasc.value)
	}

	result, abserr, resabs, resasc = qk(f, b, a)
	if !assert.EqualFloat64(result, -exp_result.value, exp_result.precision, 0) {
		t.Errorf("%s: result: %.15f, expected: %.15f\n", prefix, result, -exp_result.value)
	}
	if !assert.EqualFloat64(abserr, exp_abserr.value, exp_abserr.precision, 0) {
		t.Errorf("%s: abserr: %.7f, expected: %.7f\n", prefix, abserr, exp_abserr.value)
	}
	if !assert.EqualFloat64(resabs, exp_resabs.value, exp_resabs.precision, 0) {
		t.Errorf("%s: resabs: %.15f, expected: %.15f\n", prefix, resabs, exp_resabs.value)
	}
	if !assert.EqualFloat64(resasc, exp_resasc.value, exp_resasc.precision, 0) {
		t.Errorf("%s: resasc: %.15f, expected: %.15f\n", prefix, resasc, exp_resasc.value)
	}
}
示例#5
0
func TestTaylorCoeff(t *testing.T) {
	var (
		x float64
		n int
		e float64
		d float64
		r float64
	)
	n, x, e = 10, 1.0/1048576.0, 1.7148961854776073928e-67
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 10, 1.0/1024.0, 2.1738891788497900281e-37
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 10, 1.0, 2.7557319223985890653e-07
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 10, 5.0, 2.6911444554673721340
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 10, 500.0, 2.6911444554673721340e+20
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 100, 100.0, 1.0715102881254669232e+42
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 1000, 200.0, 2.6628790558154746898e-267
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
	n, x, e = 1000, 500.0, 2.3193170139740855074e+131
	r = TaylorCoeff(n, x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("TaylorCoeff: result %.5f, expected %.5f\n", r, e)
	}
}
示例#6
0
func TestLnChoose(t *testing.T) {
	var (
		n, m    uint32
		r, e, d float64
	)
	n, m, e = 7, 3, 3.555348061489413680
	r, d = LnChoose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnChoose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 5, 2, 2.302585092994045684
	r, d = LnChoose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnChoose: result %.5f, expected %.5f\n", r, e)
	}
}
示例#7
0
func TestChoose(t *testing.T) {
	var (
		n, m    uint32
		r, e, d float64
	)

	n, m, e = 7, 3, 35
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 7, 4, 35
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 5, 2, 10
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 5, 3, 10
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 500, 495, 255244687600.0
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 500, 5, 255244687600.0
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 500, 200, 5.054949849935532221e+144
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}

	n, m, e = 500, 300, 5.054949849935532221e+144
	r, d = Choose(n, m), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Choose: result %.5f, expected %.5f\n", r, e)
	}
}
示例#8
0
func TestQng(t *testing.T) {
	{
		exp_result := 7.716049379303083211E-02
		exp_abserr := 9.424302199601294244E-08
		exp_neval := 21
		f := f1{alpha: 2.6}
		result, abserr, neval, status := Qng(f, 0.0, 1.0, 1e-1, 0.0)
		if status != 0 {
			t.Errorf("Don't expect Error code: %d\n", status)
		}
		if !assert.EqualFloat64(result, exp_result, 1e-15, 0) {
			t.Errorf("Result: %f, expect: %f\n", result, exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-7, 0) {
			t.Errorf("Abserr: %f, expect: %f\n", abserr, exp_abserr)
		}
		if neval != exp_neval {
			t.Errorf("Neval: %d, expect: %d\n", neval, exp_neval)
		}
	}
}
示例#9
0
func TestLnDoubleFact(t *testing.T) {
	var (
		n uint32
		e float64
		r float64
		d float64
	)
	n, e = 0, 0.0
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 7, 4.653960350157523371
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 33, 43.292252022541719660
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 34, 45.288575519655959140
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 1034, 3075.6383796271197707
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

	n, e = 1035, 3078.8839081731809169
	r, d = LnDoubleFact(n), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnDoubleFact: result %.5f, expected %.5f\n", r, e)
	}

}
示例#10
0
func TestQag(t *testing.T) {
	{

		exp_result := 7.716049382715854665E-02
		exp_abserr := 6.679384885865053037E-12

		alpha := 2.6
		f := f1{alpha: alpha}
		result, abserr, status := Qag(f, 0.0, 1.0, 0.0, 1e-10, 1000, GSL_INTEG_GAUSS15)
		if !assert.EqualFloat64(result, exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}

		result, abserr, status = Qag(f, 1.0, 0.0, 0.0, 1e-10, 1000, GSL_INTEG_GAUSS15)
		if !assert.EqualFloat64(result, -exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, -exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}
	}

	/* Test the same function using an absolute error bound and the
	   21-point rule */

	{
		exp_result := 7.716049382716050342E-02
		exp_abserr := 2.227969521869139532E-15

		alpha := 2.6
		f := f1{alpha: alpha}
		result, abserr, status := Qag(f, 0.0, 1.0, 1e-14, 0.0, 1000, GSL_INTEG_GAUSS21)
		if !assert.EqualFloat64(result, exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}

		result, abserr, status = Qag(f, 1.0, 0.0, 1e-14, 0.0, 1000, GSL_INTEG_GAUSS21)
		if !assert.EqualFloat64(result, -exp_result, 1e-15, 0) {
			t.Errorf("Smooth: result %.10f, expected %.10f\n", result, -exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Smooth: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Smooth: do not expected error %v\n", status)
		}
	}

	/* Adaptive integration of an oscillatory function which terminates because
	   of roundoff error, uses the 31-pt rule
	{
		exp_result := -7.238969575482959717E-01
		exp_abserr := 1.285805464427459261E-14

		alpha := 1.3
		f := f3{alpha: alpha}
		result, abserr, status := Qag(f, 0.3, 2.71, 1e-14, 0.0, 1000, GSL_INTEG_GAUSS31)
		if !assert.EqualFloat64(result, exp_result, 1e-15, 0) {
			t.Errorf("Oscill: result %.10f, expected %.10f\n", result, exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Oscill: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Oscill: do not expected error %v\n", status)
		}

		result, abserr, status = Qag(f, 2.71, 0.3, 1e-14, 0.0, 1000, GSL_INTEG_GAUSS31)
		if !assert.EqualFloat64(result, -exp_result, 1e-15, 0) {
			t.Errorf("Oscill: result %.10f, expected %.10f\n", result, -exp_result)
		}
		if !assert.EqualFloat64(abserr, exp_abserr, 1e-6, 0) {
			t.Errorf("Oscill: abserr %f, expected %f\n", abserr, exp_abserr)
		}
		if status != 0 {
			t.Errorf("Oscill: do not expected error %v\n", status)
		}
	}
	*/

}
示例#11
0
func TestGamma(t *testing.T) {
	var (
		x float64
		r float64
		e float64
		d float64
	)

	x = 1.0 + 1.0/4096.0
	r = Gamma(x)
	e = 0.9998591371459403421
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 1.0 + 1.0/32.0
	r = Gamma(x)
	e = 0.9829010992836269148
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 2.0 + 1.0/256.0
	r = Gamma(x)
	e = 1.0016577903733583299
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 9.0
	r = Gamma(x)
	e = 40320.0
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 10.0
	r = Gamma(x)
	e = 362880.0
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 100.0
	r = Gamma(x)
	e = 9.332621544394415268e+155
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 170.0
	r = Gamma(x)
	e = 4.269068009004705275e+304
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = 171.0
	r = Gamma(x)
	e = 7.257415615307998967e+306
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = -10.5
	r = Gamma(x)
	e = -2.640121820547716316e-07
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = -11.25
	r = Gamma(x)
	e = 6.027393816261931672e-08
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

	x = -1.0 + 1.0/65536.0
	r = Gamma(x)
	e = -65536.42280587818970
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("Gamma: result %.5f, expected %.5f\n", r, e)
	}

}
示例#12
0
func TestGammaInv(t *testing.T) {
	var (
		x float64
		e float64
		r float64
		d float64
	)
	x, e = 1.0, 1.0
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 2.0, 1.0
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 3.0, 0.5
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 4.0, 1.0/6.0
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 10.0, 1.0/362880.0
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 100.0, 1.0715102881254669232e-156
	r, d = GammaInv(x), 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
	}
	/*
		x, e = 0.0, 0.0
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}


		x, e = -1.0, 0.0
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}


		x, e = -2.0, 0.0
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}

		x, e = -3.0, 0.0
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}

		x, e = -4.0, 0.0
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}

		x, e = -10.5, -1.0/2.640121820547716316e-07
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}

		x, e = -11.25, 1.0/6.027393816261931672e-08
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}

		x, e = -1.0+1.0/65536.0, -1.0/65536.42280587818970
		r, d = GammaInv(x), 1e-6
		if !assert.EqualFloat64(r, e, d, 1) {
			t.Errorf("GammaInv: result %.5f, expected %.5f\n", r, e)
		}
	*/
}
示例#13
0
func TestLnGamma(t *testing.T) {
	var (
		x float64
		r float64
		e float64
		d float64
	)

	// case 1
	x = -0.1
	r = LnGamma(x)
	e = 2.368961332728788655
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}

	// case 2
	x = -1.0 / 256.0
	r = LnGamma(x)
	e = 5.547444766967471595
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}

	// case 3
	x = 1.0e-08
	r = LnGamma(x)
	e = 18.420680738180208905
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}

	// case 4
	x = 0.1
	r = LnGamma(x)
	e = 2.252712651734205
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}

	// case 5
	x = 100.0
	r = LnGamma(x)
	e = 359.1342053695753
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}

	// case 6
	x = -100 - 1.0/65536.0
	r = LnGamma(x)
	e = -352.6490910117097874
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("LnGamma: result %.5f, expected %.5f\n", r, e)
	}
}
示例#14
0
func TestGammaStar(t *testing.T) {
	var (
		x float64
		e float64
		r float64
		d float64
	)
	x, e = 1.0e-08, 3989.423555759890865
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 1.0e-05, 126.17168469882690233
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 0.001, 12.708492464364073506
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}
	x, e = 1.5, 1.0563442442685598666
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 3.0, 1.0280645179187893045
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 9.0, 1.0092984264218189715
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 11.0, 1.0076024283104962850
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 100.0, 1.0008336778720121418
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 1.0e+05, 1.0000008333336805529
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}

	x, e = 1.0e+20, 1.0
	r = GammaStar(x)
	d = 1e-6
	if !assert.EqualFloat64(r, e, d, 1) {
		t.Errorf("GammaStar: result %.5f, expected %.5f\n", r, e)
	}
}