From: Zooko O'Whielacronx Date: Mon, 28 Jul 2008 23:42:17 +0000 (-0700) Subject: test: add testutil.flip_one_bit which flips a randomly chosen bit of the input string X-Git-Url: https://git.rkrishnan.org/vdrive/provisioning?a=commitdiff_plain;h=9d14341c7d7444df9f8eb3fcc968fb6687b39671;p=tahoe-lafs%2Ftahoe-lafs.git test: add testutil.flip_one_bit which flips a randomly chosen bit of the input string --- diff --git a/src/allmydata/util/testutil.py b/src/allmydata/util/testutil.py index 2242de65..ec6afdc1 100644 --- a/src/allmydata/util/testutil.py +++ b/src/allmydata/util/testutil.py @@ -1,4 +1,5 @@ import os, signal, time +from random import randrange from twisted.internet import reactor, defer, task from twisted.python import failure @@ -12,6 +13,13 @@ def flip_bit(good, which): pieces = good[:which], good[which:which+1], good[which+1:] return pieces[0] + chr(ord(pieces[1]) ^ 0x01) + pieces[2] +def flip_one_bit(s): + # flip one random bit of the string s + i = randrange(0, len(s)) + result = s[:i] + chr(ord(s[i])^(0x01<