Mercurial > public > mercurial-scm > hg
comparison tests/test-pathencode.py @ 19319:ec17ddecdf64 stable
test-pathencode: randomize length of each path component
This makes it possible for long and short components to exist in the same path.
This also makes shorter path components more likely. For
randint(1, randint(1, n)), the likelihood that one sees a number k
(1 <= k <= n) is 1/n * (\sum_{k=i}^n 1/i). This decreases with k, much like in
the real world where shorter paths are more common than longer ones.
The previous fix and this one together cause issue3958 to be detected by this
test with reasonable frequency. When this test was run 100 times in a loop, the
issue was detected 30 of those times.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 19 Jun 2013 23:05:40 -0700 |
parents | 9778c77f05d6 |
children | cf1b0a58a0de |
comparison
equal
deleted
inserted
replaced
19318:9778c77f05d6 | 19319:ec17ddecdf64 |
---|---|
123 '''Construct a part of a pathname, without slashes.''' | 123 '''Construct a part of a pathname, without slashes.''' |
124 | 124 |
125 p = pickfrom(rng, firsttable)(rng) | 125 p = pickfrom(rng, firsttable)(rng) |
126 l = len(p) | 126 l = len(p) |
127 ps = [p] | 127 ps = [p] |
128 while l < k: | 128 maxl = rng.randint(1, k) |
129 while l < maxl: | |
129 p = pickfrom(rng, resttable)(rng) | 130 p = pickfrom(rng, resttable)(rng) |
130 l += len(p) | 131 l += len(p) |
131 ps.append(p) | 132 ps.append(p) |
132 ps.append(pickfrom(rng, lasttable)(rng)) | 133 ps.append(pickfrom(rng, lasttable)(rng)) |
133 return ''.join(ps) | 134 return ''.join(ps) |