Skip to content

Instantly share code, notes, and snippets.

View pschanely's full-sized avatar

Phillip Schanely pschanely

View GitHub Profile
@pschanely
pschanely / main.py
Created March 14, 2024 18:17
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created March 14, 2024 18:16
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created March 11, 2024 09:03
Shared via CrossHair Playground
from dataclasses import dataclass
class HasConsistentHash:
'''
A mixin to enforce that classes have hash methods that are consistent
with thier equality checks.
'''
def __eq__(self, other: object) -> bool:
'''
post: implies(__return__, hash(self) == hash(other))
% cat example.py
from hypothesis import given, settings
from hypothesis import strategies as st
@settings(backend="crosshair")
@given(st.sets(st.integers()))
def test(d):
assert d != {42, 123}
test()
@pschanely
pschanely / main.py
Created March 3, 2024 10:15
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created March 1, 2024 19:17
Shared via CrossHair Playground
from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
"""
Removes duplicate numbers from the given list while preserving the order of the remaining elements.
"""
# Precondition: List must not be empty
assert len(numbers) > 0, "List must not be empty"
@pschanely
pschanely / main.py
Created February 29, 2024 11:26
Shared via CrossHair Playground
def ex1(x=0):
if x == 0: return 0
if x*2 == 1:
return -1
else:
return 1
@pschanely
pschanely / main.py
Created February 27, 2024 20:59
Shared via CrossHair Playground
import dataclasses
from typing import List
@dataclasses.dataclass
class AverageableQueue:
'''
A queue of numbers with a O(1) average() operation.
inv: self._total == sum(self._values)
'''
_values: List[int]
@pschanely
pschanely / main.py
Created January 28, 2024 16:30
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created January 28, 2024 12:23
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10