Prop Testing

What is a function? Are they easy to test?

x f(x)
- +
0 0
+ +

Simple Tests

Square of a Number

Gradient of a function

  • Positive slope (multiple tests)
  • Negative slope
  • Zero slope:
  • Undefined slope (vertical line):
  • Large coordinate values:
  • Identical points: 

Simple Tests

Tax Calculator

Hash Function

Random Numbers

Best Effort: Without getting all equivalent classes

Has to be a better way

Properties for Integers

from hypothesis import given, strategies as st


@given(st.integers(), st.integers())
def test_ints_are_commutative(x, y):
    assert x + y == y + x


@given(x=st.integers(), y=st.integers())
def test_ints_cancel(x, y):
    assert (x + y) - y == x


@given(st.lists(st.integers()))
def test_reversing_twice_gives_same_list(xs):
    # This will generate lists of arbitrary length (usually between 0 and
    # 100 elements) whose elements are integers.
    ys = list(xs)
    ys.reverse()
    ys.reverse()
    assert xs == ys


@given(st.tuples(st.booleans(), st.text()))
def test_look_tuples_work_too(t):
    # A tuple is generated as the one you provided, with the corresponding
    # types in those positions.
    assert len(t) == 2
    assert isinstance(t[0], bool)
    assert isinstance(t[1], str)

Properties for Random Numbers?

RANDOM Numbers

74	8	38	100	75
63	37	53	95	51
56	62	31	54	28
96	72	31	23	17
58	100	15	7	48
9	20	26	62	69
31	31	81	88	77
78	80	9	91	98
93	93	90	33	40
60	80	66	26	97
69	90	24	3	85
100	4	72	8	24
28	16	40	80	56
7	94	20	42	42
13	44	73	24	29
69	78	83	17	24

random data from weather noise

rand() on windows

Demo Time

Counter + Floor Random

https://chatgpt.com/c/67ad6a59-22f0-800c-a5af-db768fb299b2

RANDU

PRNG

MERSANNE TWISTER

Stateful Stateless / Hypothesis Demo

SchemaThesis

Prop Testing

By Iqbal Talaat Bhatti

Prop Testing

  • 281