Ejemplo n.º 1
0
func testRegionSplit(helper bigRegionSplitHelper, t *testing.T) {
	const iterlim = 255
	parent := bigbase.BigBaseNumerics{}
	parent.Precision = prec
	parent.SqrtDivergeLimit = parent.MakeBigFloat(2.0)
	parent.IterateLimit = iterlim

	initMin := bigbase.BigComplex{helper.left, helper.bottom}
	initMax := bigbase.BigComplex{helper.right, helper.top}

	topLeftMin := bigbase.BigComplex{helper.left, helper.midI}
	topLeftMax := bigbase.BigComplex{helper.midR, helper.top}

	topRightMin := bigbase.BigComplex{helper.midR, helper.midI}
	topRightMax := bigbase.BigComplex{helper.right, helper.top}

	bottomLeftMin := bigbase.BigComplex{helper.left, helper.bottom}
	bottomLeftMax := bigbase.BigComplex{helper.midR, helper.midI}

	bottomRightMin := bigbase.BigComplex{helper.midR, helper.bottom}
	bottomRightMax := bigbase.BigComplex{helper.right, helper.midI}

	subjectRegion := createBigRegion(parent, initMin, initMax)

	expected := []bigRegion{
		createBigRegion(parent, topLeftMin, topLeftMax),
		createBigRegion(parent, topRightMin, topRightMax),
		createBigRegion(parent, bottomLeftMin, bottomLeftMax),
		createBigRegion(parent, bottomRightMin, bottomRightMax),
	}

	numerics := BigRegionNumerics{}
	numerics.BigBaseNumerics = parent
	numerics.Region = subjectRegion
	numerics.Split()
	actualChildren := numerics.subregion.children

	for i, expectReg := range expected {
		actReg := actualChildren[i]
		exPoints := expectReg.points()
		acPoints := actReg.points()

		fail := false
		for j, ep := range exPoints {
			ap := acPoints[j]
			okay := bigbase.BigComplexEq(ep.C, ap.C)
			if !okay {
				fail = true
				t.Log("Region", i, "error at point", j,
					"\nexpected\t", bigbase.DbgC(*ep.C),
					"\nbut received\t", bigbase.DbgC(*ap.C))
			}
		}
		if fail {
			t.Fail()
		}
	}
}
// regionEq returns true when its inputs have the same locations in space
func regionEq(areg, breg bigRegion) bool {
	aths := areg.points()
	bths := breg.points()

	for i, a := range aths {
		b := bths[i]
		if !bigbase.BigComplexEq(a.C, b.C) {
			return false
		}
	}

	return true
}