source: code/test_fastsimplexordatastore.py @ 23

Last change on this file since 23 was 23, checked in by trishank, 7 years ago

Add pre-release upPIR from June 2011.

File size: 2.0 KB
Line 
1# this is a bunch of macro tests.   If everything passes, there is no output.
2
3import fastsimplexordatastore
4
5size = 64
6letterxordatastore = fastsimplexordatastore.XORDatastore(size, 16)
7
8startpos = 0
9for char in range(ord("A"), ord("Q")):
10  # put 1K of those chars in...
11  letterxordatastore.set_data(startpos, chr(char) * size)
12  startpos = startpos + size
13
14# can read data out...
15assert(letterxordatastore.get_data(size, 1) == 'B')
16
17# let's create a bitstring that uses A, C, and P.   
18bitstring = chr(int('10100000', 2)) + chr(int('00000001',2))
19xorresult = letterxordatastore.produce_xor_from_bitstring(bitstring)
20
21assert(xorresult[0] == 'R')
22
23letterxordatastore.set_data(10,"Hello there")
24
25mystring = letterxordatastore.get_data(9,13)
26
27assert(mystring == 'AHello thereA')
28
29
30letterxordatastore.set_data(1,"Hello there"*size)
31
32mystring = letterxordatastore.get_data(size*2 - (size*2 %11) + 1,11)
33
34assert(mystring == "Hello there")
35
36# let's try to read the last bytes of data
37mystring = letterxordatastore.get_data(size*15,size)
38
39
40
41try:
42  letterxordatastore = fastsimplexordatastore.XORDatastore(127, 16)
43except TypeError:
44  pass
45else:
46  print "Was allowed to use a block size that isn't a multiple of 64"
47
48try:
49  letterxordatastore.set_data(size*16, "hi")
50except TypeError:
51  pass
52else:
53  print "Was allowed to write past the end of the datastore"
54
55
56try:
57  letterxordatastore.set_data(size*16, 1)
58except TypeError:
59  pass
60else:
61  print "Was allowed to read past the end of the datastore"
62
63
64for blockcount in [9,15,16]:
65  letterxordatastore = fastsimplexordatastore.XORDatastore(size, blockcount)
66
67  # is a 0 block the right size?
68  assert( len(letterxordatastore.produce_xor_from_bitstring(chr(0)*2)) == size )
69
70
71
72  try:
73    letterxordatastore.produce_xor_from_bitstring(chr(0)*1)
74  except TypeError:
75    pass
76  else:
77    print "didn't detect incorrect (short) bitstring length"
78
79
80  try:
81    letterxordatastore.produce_xor_from_bitstring(chr(0)*3)
82  except TypeError:
83    pass
84  else:
85    print "didn't detect incorrect (long) bitstring length"
86
87
88
89
90
Note: See TracBrowser for help on using the repository browser.