This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ex1(x=0): | |
if x == 0: return 0 | |
if x*2 == 1: | |
return -1 | |
else: | |
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |