Skip to content

Instantly share code, notes, and snippets.

@radupotop
Last active February 8, 2021 12:15
Show Gist options
  • Save radupotop/46d2007053568a0b64a998b9bcad78d4 to your computer and use it in GitHub Desktop.
Save radupotop/46d2007053568a0b64a998b9bcad78d4 to your computer and use it in GitHub Desktop.
Hypothesis play around
from hypothesis import given, strategies as st
def q(list):
"""Quicksort"""
return [] if list==[] else q([x for x in list[1:] if x < list[0]]) + [list[0]] + q([x for x in list[1:] if x >= list[0]])
@given(st.lists(st.integers(min_value=-10000, max_value=10000)))
def test_qsort(int_list):
print(int_list)
assert q(int_list) == sorted(int_list)
@radupotop
Copy link
Author

Output

> pytest -svv test_x.py
================================================================================================== test session starts ==================================================================================================
platform linux -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/radu/Projects/coding-challenges/.hypothesis/examples')
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/radu/Projects/coding-challenges
plugins: hypothesis-6.1.1, benchmark-3.2.3, asyncio-0.14.0, case-1.5.3
collected 1 item                                                                                                                                                                                                        

test_x.py::test_qsort []
[0]
[0]
[0]
[0]
[0]
[0]
[]
[0]
[593]
[6100]
[-744, 539, 5937, 2543]
[-744, -256, 6914, 5937, 2543]
[-256, -256, 6914, 5937, 2543]
[9901]
[3548, -7738, -580]
[-3548, -7738, -580]
[-8476, 363, -8148]
[-8148, 363, -8148]
[-2691, 6865, 98]
[98, 6865, 98]
[-1989, 5200, 9637, -8692]
[-8692, 5200, 9637, -8692]
[-6426, -9774, -7705, -2497, -3609, -6207]
[-1281, -1574, -286, -265, 257]
[-265, -1574, -286, -265, 257]
[-1574, -1574, -286, -265, 257]
[-1574, -265, -286, -265, 257]
[-1574, -265, -257, -265, 257]
[-1574, -265, -1574, -265, 257]
[-6835, -3262]
[-4471, -3070, 6244, 7983, 8146, 4760, 7874, -5226, -9720, 6202, 7620, -1990, 2910, -7516, -3927]
[9955, -6805, 4306]
[9955, 6805, 4306]
[9955]
[9955, 4494, 2602, -4802]
[9955, 2602, 2602, -4802]
[-2131, 1216, -3720, -3946, 6326, 6400, -78]
[-3720, 1216, -3720, -3946, 6326, 6400, -78]
[-1800, -9682, 628, -572, -4424, 6722, -2145, 966, 910, 9648, 2817, -5282, -3880, -1049, 6688, 7723, -8410]
[-136, -5659, 1032, -2393, 7982]
[-9418, 8439, 5479, 679, 1021, -9531, 6264, -5200, -7621]
[-5200, 8439, 5479, 679, 1021, -9531, 6264, -5200, -7621]
[7131]
[-6596, 2843, 1493, -6288, 2997, 6103]
[5113, 1423, 4976, 1009, 3772, -3470, 9978, -8610]
[1573, -2699, -241, 8708, -9948, -8316, -5533]
[-5298, -927, -7761, -4832, 8503, -1025, 4920, -7924, -427, 2006, 663, -7581, -4752, -5141]
[-927, -927, -7761, -4832, 8503, -1025, 4920, -7924, -427, 2006, 663, -7581, -4752, -5141]
[-7274, -9415, 498, 7319, -3147, 7164, 9011, 3377, 9697, -562, -6738]
[-7274, -562, 498, 7319, -3147, 7164, 9011, 3377, 9697, -562, -6738]
[-6738, -562, 498, 7319, -3147, 7164, 9011, 3377, 9697, -562, -6738]
[-7466, -4246, 6824, -2294, 1920]
[-4246, -4246, 6824, -2294, 1920]
[-4246, -4246, 6824, -2294, 1920]
[-4246, -2294, 6824, -2294, 1920]
[-4246, -4246]
[-4246, -4246, 5304, 8199, 9555, -6799]
[-6799, -4246, 5304, 8199, 9555, -6799]
[2589]
[-1857, 9394, -8087, 8148, 2611, -6015, 9398, 2894, 4012, 3954, 9513, -1651]
[-9419]
[-203, -2503, 7378]
[-203, -203, 7378]
[-203, -203, -28, 2985, 6, 3061, -3746, 6082, -6579, 182, 2940, -7767, -7528, 7467, 9849, -3386]
[-257]
[-7087, -4480, -4096, 6026, -5414, 2592, -4082]
[-696, 9850, 8278, -9977, -3853, -3319, 8886, 3720, -3308, -4417, -9761, 6370, 3319, -1149, 5862, 2118, -7735, 2064, 1796, -5964, 3352, -2874, 6759, -9422, 7168, -5807, -6009]
[-3694, -5651, -9898, 1888, -7536]
[-1025, 4870, -9898, 1888, -7536]
[-7536, 4870, -9898, 1888, -7536]
[-9898, 4870, -9898, 1888, -7536]
[-8745, -6267, -7890, -1244, -1440, 2301, -6514, 7203, -8947, -8889, 6426, 5191, -6353, 9944, 8345, -5833, 7530, -6677, -5811, 352, -7248, -2315, 616, -9478, 1238, -4636, 7699, 1811, 6065, -6928, 9954, -1982, -7126, -1676, 333]
[-9637]
[-1535, -4751, 9508, -6099, -6563, 2711, -3724, -842, 5930, 987, 1649, -6987, -4763, -1382, -4715, 4310]
[8499, 3146, 7620, -2348, 6823, 268, 5244, 3683, -7356, 7881]
[8499, 3146, 7620, -2348, 6823, 268, 5244, 3683, -7356, 7881]
[5148, 4933, -6765, -3005, 9381]
[4933, 4933, -6765, -3005, 9381]
[8759, -797]
[-797, -797]
[9372, -6388, 1671, -6398, 3586]
[5928, -9619, -7057, -996, -7771, -9674, -3147, -7901, -7316, 3694]
[3694, -9619, -7057, -996, -7771, -9674, -3147, -7901, -7316, 3694]
[-1403, 7665, -9991]
[-9991, 7665, -9991]
[-2045, -2903, -6711, 1449, 1341]
[-5489, -1653, -3537, -8030]
[-5489, -8030, -3537, -8030]
[-5489, -3537, -7686, -3537, -8030]
[-5489, -3537, -7686, -3537, -8030]
[-5489, -3537, -7686, -5489, -8030]
[-5489, -3537, -7686, -5489, -5489]
[-3537, -3537, -7686, -5489, -5489]
[154, 3636, 8928]
[2213, -1584, 2047, 8164, -7174, -6399, 483, -9657, 3579]
[-8397, -8144]
[-8144, -8144]
[-1781, 4207, -457, 3328, 9387, -7959, -591, 4386, -8794, 9802, 6796, 3592, -6516, -4600, -394, -7951, 6232, 4421, -1724, -8208, -8637]
[7844, -5084, -9569, -1643, 9498, 4355, -6273]
PASSED

=================================================================================================== 1 passed in 0.24s ===================================================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment