mirror of
https://github.com/NixOS/nix
synced 2024-09-19 23:03:53 -04:00
test: Generate distinct hashes
Gen::just is the constant generator. Don't just return that!
This commit is contained in:
parent
51332020c0
commit
80ea2dcc25
|
@ -11,10 +11,17 @@ using namespace nix;
|
||||||
|
|
||||||
Gen<Hash> Arbitrary<Hash>::arbitrary()
|
Gen<Hash> Arbitrary<Hash>::arbitrary()
|
||||||
{
|
{
|
||||||
|
Hash prototype(htSHA1);
|
||||||
|
return
|
||||||
|
gen::apply(
|
||||||
|
[](const std::vector<uint8_t> & v) {
|
||||||
Hash hash(htSHA1);
|
Hash hash(htSHA1);
|
||||||
for (size_t i = 0; i < hash.hashSize; ++i)
|
assert(v.size() == hash.hashSize);
|
||||||
hash.hash[i] = *gen::arbitrary<uint8_t>();
|
std::copy(v.begin(), v.end(), hash.hash);
|
||||||
return gen::just(hash);
|
return hash;
|
||||||
|
},
|
||||||
|
gen::container<std::vector<uint8_t>>(prototype.hashSize, gen::arbitrary<uint8_t>())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue