Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
Created March 15, 2016 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsonsmatt/c5833574c123da217bc4 to your computer and use it in GitHub Desktop.
Save parsonsmatt/c5833574c123da217bc4 to your computer and use it in GitHub Desktop.
mmm property checking
def decode(data):
"""
Accepts a byte array and converts it into an Ack packet if possible. If the
decoding fails, then this method raises DecodeError. The following doc test
randomly samples legal values for the acknowledgment number and window size and
asserts that for all those values, Ack.decode(p.encode()) == p
>>> from random import *
>>> ack_nos = [randrange(int(1e6)) for i in range(1,10)]
>>> win_sizes = [randrange(int(1e3)) for i in range(1,10)]
>>> ps = [Ack(x, y) for x in ack_nos for y in win_sizes]
>>> [p for p in ps if Ack.decode(p.encode()) != p]
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment