Skip to content

Commit

Permalink
Add bomb test.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss committed May 20, 2022
1 parent 744fd33 commit fae87ba
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/serialize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,31 @@ def test_deserialize_generator(self):
s = sexp_from_stream(io.BytesIO(blob), to_sexp_f)
b = self.check_serde(s)
assert len(b) == 19124

def test_deserialize_bomb(self):

def make_bomb(depth):
bomb = TEXT
for _ in range(depth):
bomb = to_sexp_f((bomb, bomb))
return bomb

bomb_10 = make_bomb(10)
b10_1 = bomb_10.as_bin(allow_backrefs=False)
b10_2 = bomb_10.as_bin(allow_backrefs=True)
self.assertEqual(len(b10_1), 47103)
self.assertEqual(len(b10_2), 75)

bomb_20 = make_bomb(20)
b20_1 = bomb_20.as_bin(allow_backrefs=False)
b20_2 = bomb_20.as_bin(allow_backrefs=True)
self.assertEqual(len(b20_1), 48234495)
self.assertEqual(len(b20_2), 105)

bomb_30 = make_bomb(30)
# do not uncomment the next line unless you want to run out of memory
# b30_1 = bomb_30.as_bin(allow_backrefs=False)
b30_2 = bomb_30.as_bin(allow_backrefs=True)

# self.assertEqual(len(b30_1), 1)
self.assertEqual(len(b30_2), 135)

0 comments on commit fae87ba

Please sign in to comment.