| 97 | ################################################################################ |
| 98 | |
| 99 | def test(): |
| 100 | from os import remove, urandom |
| 101 | from random import randint |
| 102 | test = DAL2(1024, 1024) |
| 103 | memo = [None for temp in range(1024)] |
| 104 | for temp in range(1024): |
| 105 | status = randint(1, 255) |
| 106 | block = test.open(status) |
| 107 | data = urandom(1024) |
| 108 | test.write(block, data) |
| 109 | memo[block] = status, data |
| 110 | for temp in range(1024): |
| 111 | block = randint(0, 1023) |
| 112 | if test.status(block): |
| 113 | test.close(block) |
| 114 | memo[block] = None |
| 115 | test.dump('temp') |
| 116 | other = DAL2(1, 1) |
| 117 | other.load('temp', False) |
| 118 | remove('temp') |
| 119 | try: |
| 120 | for index, information in enumerate(memo): |
| 121 | if information is None: |
| 122 | assert other.status(index) == 0 |
| 123 | else: |
| 124 | assert other.status(index) == information[0] |
| 125 | assert other.read(index) == information[1] |
| 126 | valid = False |
| 127 | try: |
| 128 | other.status(1024) |
| 129 | except: |
| 130 | valid = True |
| 131 | assert valid |
| 132 | raw_input('Tested To True') |
| 133 | except: |
| 134 | raw_input('Tested To False') |
| 135 | |
| 136 | ################################################################################ |
| 137 | |