Skip to content

Instantly share code, notes, and snippets.

@zed
Created May 11, 2020 15:40
Show Gist options
  • Select an option

  • Save zed/9fd5322932b814278547819f23bc0b6c to your computer and use it in GitHub Desktop.

Select an option

Save zed/9fd5322932b814278547819f23bc0b6c to your computer and use it in GitHub Desktop.

Revisions

  1. zed created this gist May 11, 2020.
    33 changes: 33 additions & 0 deletions violations.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/usr/bin/env python3
    """
    https://www.youtube.com/watch?v=BleOgPhsdfc
    """
    from dataclasses import dataclass


    @dataclass
    class RedLightViolation:
    """..."""

    place: str
    seconds: float

    def serious(self) -> bool:
    return self.seconds >= 1


    @dataclass
    class SpeedViolation:
    """..."""

    place: str
    excess_speed: int

    def serious(self) -> bool:
    return self.excess_speed > 5


    def test_serious():
    """..."""
    assert RedLightViolation(place="Borg", seconds=1).serious()
    assert SpeedViolation(place="main street", excess_speed=10).serious()