MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestBigIntModInverse

Function TestBigIntModInverse

bigint_test.go:2050–2080  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2048}
2049
2050func TestBigIntModInverse(t *testing.T) {
2051 var element, modulus, gcd, inverse BigInt
2052 one := NewBigInt(1)
2053 for _, test := range modInverseTests {
2054 (&element).SetString(test.element, 10)
2055 (&modulus).SetString(test.modulus, 10)
2056 (&inverse).ModInverse(&element, &modulus)
2057 (&inverse).Mul(&inverse, &element)
2058 (&inverse).Mod(&inverse, &modulus)
2059 if (&inverse).Cmp(one) != 0 {
2060 t.Errorf("ModInverse(%d,%d)*%d%%%d=%d, not 1", &element, &modulus, &element, &modulus, &inverse)
2061 }
2062 }
2063 // exhaustive test for small values
2064 for n := 2; n < 100; n++ {
2065 (&modulus).SetInt64(int64(n))
2066 for x := 1; x < n; x++ {
2067 (&element).SetInt64(int64(x))
2068 (&gcd).GCD(nil, nil, &element, &modulus)
2069 if (&gcd).Cmp(one) != 0 {
2070 continue
2071 }
2072 (&inverse).ModInverse(&element, &modulus)
2073 (&inverse).Mul(&inverse, &element)
2074 (&inverse).Mod(&inverse, &modulus)
2075 if (&inverse).Cmp(one) != 0 {
2076 t.Errorf("ModInverse(%d,%d)*%d%%%d=%d, not 1", &element, &modulus, &element, &modulus, &inverse)
2077 }
2078 }
2079 }
2080}
2081
2082// testModSqrt is a helper for TestModSqrt,
2083// which checks that ModSqrt can compute a square-root of elt^2.

Callers

nothing calls this directly

Calls 8

NewBigIntFunction · 0.85
ModInverseMethod · 0.80
ModMethod · 0.80
GCDMethod · 0.80
SetStringMethod · 0.45
MulMethod · 0.45
CmpMethod · 0.45
SetInt64Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…