From 9d14341c7d7444df9f8eb3fcc968fb6687b39671 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Mon, 28 Jul 2008 16:42:17 -0700 Subject: [PATCH] test: add testutil.flip_one_bit which flips a randomly chosen bit of the input string --- src/allmydata/util/testutil.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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<