func BenchmarkPolMod(t *testing.B) { f := chunker.Pol(0x2482734cacca49) g := chunker.Pol(0x3af4b284899) for i := 0; i < t.N; i++ { g.Mod(f) } }
func parseBin(s string) chunker.Pol { i, err := strconv.ParseUint(s, 2, 64) if err != nil { panic(err) } return chunker.Pol(i) }
func BenchmarkPolDeg(t *testing.B) { f := chunker.Pol(0x3af4b284899) d := f.Deg() if d != 41 { t.Fatalf("BenchmalPolDeg: Wrong degree %d returned, expected %d", d, 41) } for i := 0; i < t.N; i++ { f.Deg() } }
func TestPolMulOverflow(t *testing.T) { defer func() { // try to recover overflow error err := recover() if e, ok := err.(string); ok && e == "multiplication would overflow uint64" { return } else { t.Logf("invalid error raised: %v", err) // re-raise error if not overflow panic(err) } }() x := chunker.Pol(1 << 63) x.Mul(2) t.Fatal("overflow test did not panic") }
func TestExpandPolynomial(t *testing.T) { pol := chunker.Pol(0x3DA3358B4DC173) s := pol.Expand() Equals(t, "x^53+x^52+x^51+x^50+x^48+x^47+x^45+x^41+x^40+x^37+x^36+x^34+x^32+x^31+x^27+x^25+x^24+x^22+x^19+x^18+x^16+x^15+x^14+x^8+x^6+x^5+x^4+x+1", s) }
d, err := hex.DecodeString(s) if err != nil { panic(err) } return d } type chunk struct { Length uint CutFP uint64 Digest []byte } // polynomial used for all the tests below const testPol = chunker.Pol(0x3DA3358B4DC173) // created for 32MB of random data out of math/rand's Uint32() seeded by // constant 23 // // chunking configuration: // window size 64, avg chunksize 1<<20, min chunksize 1<<19, max chunksize 1<<23 // polynom 0x3DA3358B4DC173 var chunks1 = []chunk{ chunk{2163460, 0x000b98d4cdf00000, parseDigest("4b94cb2cf293855ea43bf766731c74969b91aa6bf3c078719aabdd19860d590d")}, chunk{643703, 0x000d4e8364d00000, parseDigest("5727a63c0964f365ab8ed2ccf604912f2ea7be29759a2b53ede4d6841e397407")}, chunk{1528956, 0x0015a25c2ef00000, parseDigest("a73759636a1e7a2758767791c69e81b69fb49236c6929e5d1b654e06e37674ba")}, chunk{1955808, 0x00102a8242e00000, parseDigest("c955fb059409b25f07e5ae09defbbc2aadf117c97a3724e06ad4abd2787e6824")}, chunk{2222372, 0x00045da878000000, parseDigest("6ba5e9f7e1b310722be3627716cf469be941f7f3e39a4c3bcefea492ec31ee56")}, chunk{2538687, 0x00198a8179900000, parseDigest("8687937412f654b5cfe4a82b08f28393a0c040f77c6f95e26742c2fc4254bfde")}, chunk{609606, 0x001d4e8d17100000, parseDigest("5da820742ff5feb3369112938d3095785487456f65a8efc4b96dac4be7ebb259")},