def test_rectangle_with_aspect_ratio_fuzz(): # Fuzz test which checks that requirements are met for a wide range of # cases. for area in range(50): for ratio100 in range(1, 101): ratio = ratio100 / 100.0 w, h = rectangle_with_aspect_ratio(area, ratio) # Area should be sufficient assert w * h >= area # Should be both zero or neither zero assert (w == 0) == (h == 0) # Aspect ratio should meet requirement if area > 0: assert 0.0 < (float(h) / float(w)) <= 1.0
def test_rectangle_with_aspect_ratio(area, ratio, wh): # Human generated cases which make sure the 'sane' thing is done assert rectangle_with_aspect_ratio(area, ratio) == wh