示例#1
0
func TestParsePolynomial(t *testing.T) {
	testCases := []string{"x^2 + 5*x - 1001", "x^2", "-1*x", "2*x + 1", "x + 1", "x", "1", "2"}
	for _, testCase := range testCases {
		p := poly.ParseIntPoly(testCase).String()
		if p != testCase {
			t.Errorf("Parsed %s but got %s\n", testCase, p)
		}
	}
}
示例#2
0
func TestRegulator(t *testing.T) {
	for _, testCase := range regulatorTestCases {
		p := poly.ParseIntPoly(testCase.polyString)
		gotr := regulatorRealQuad(p)
		r := testCase.regulator
		if !dEquals(r, gotr) {
			t.Errorf("Poly %s regulator %f but got %f\n", p, r, gotr)
		}
	}
}
示例#3
0
func TestRandomClassNumbers(t *testing.T) {
	for _, testCase := range classNumberTestCases {
		p := poly.ParseIntPoly(testCase.polyString)
		if p.Degree() > 2 {
			continue
		}
		if Discriminant(p).Sign() > 0 {
			continue
		}
		h := testCase.classNumber
		k := MakeNumberField(p)
		hGot := k.ClassNumber()
		if hGot != h {
			t.Errorf("%s expected class number %d got %d, discriminant %s\n", p.String(), h, hGot, Discriminant(p).String())
		}
	}
}