| 193 | ################################################################################ |
| 194 | |
| 195 | def test(): |
| 196 | from os import urandom |
| 197 | from random import randint |
| 198 | BLOCKS = DAL1.BLOCKS = 100 |
| 199 | SIZE = DAL1.SIZE = 100 |
| 200 | test1 = DAL1() |
| 201 | test2 = Test(BLOCKS * SIZE) |
| 202 | test1.fail(0.999) |
| 203 | for temp in range(BLOCKS / 2): |
| 204 | print 'Write:', temp + 1, '/', BLOCKS / 2 |
| 205 | write = randint(0, (BLOCKS * SIZE) / 2), urandom(randint(1, SIZE * 2)) |
| 206 | test1.write(*write) |
| 207 | test2.write(*write) |
| 208 | index = randint((BLOCKS * SIZE) / 2, BLOCKS * SIZE) |
| 209 | data = urandom(randint(1, SIZE * 2)) |
| 210 | write = index - len(data) + 1, data |
| 211 | test1.write(*write) |
| 212 | test2.write(*write) |
| 213 | for temp in range(BLOCKS / 20): |
| 214 | print 'Erase:', temp + 1, '/', BLOCKS / 20 |
| 215 | erase = randint(0, (BLOCKS * SIZE) / 2), randint(1, SIZE * 2) |
| 216 | test1.erase(*erase) |
| 217 | test2.erase(*erase) |
| 218 | index = randint((BLOCKS * SIZE) / 2, BLOCKS * SIZE) |
| 219 | size = randint(1, SIZE * 2) |
| 220 | erase = index - size + 1, size |
| 221 | test1.erase(*erase) |
| 222 | test2.erase(*erase) |
| 223 | raw_input('Tested To ' + str(test1.read(0, BLOCKS * SIZE) == \ |
| 224 | test2.read(0, BLOCKS * SIZE))) |
| 225 | |
| 226 | ################################################################################ |
| 227 | |