import sys
import weakref

import pytest  # type: ignore
from hypothesis import given

from ppb_vector import Vector2
from utils import floats, vectors


class DummyVector:
    """A naïve representation of vectors."""

    x: float
    y: float

    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)


@pytest.mark.skipif(sys.implementation.name != 'cpython',
                    reason="PyPy optimises __slots__ automatically.")
@given(x=floats(), y=floats())
def test_object_size(x, y):
    """Check that Vector2 is 2 times smaller than a naïve version."""
    from pympler.asizeof import asizeof as sizeof  # type: ignore

    assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2


@given(v=vectors())
def test_weak_ref(v):
    """Check that weak references can be made to Vector2s."""
    assert weakref.ref(v) is not None

import sys
import weakref

import pytest  # type: ignore
from hypothesis import given

from ppb_vector import Vector2
from utils import floats, vectors


class DummyVector:
    """A naïve representation of vectors."""

    x: float
    y: float

    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)


@pytest.mark.skipif(sys.implementation.name != 'cpython',
                    reason="PyPy optimises __slots__ automatically.")
@pytest.mark.skipif(sys.implementation.version.minor > 7,
                    reason="Pympler 0.6 is broken under Python 3.8.  See pympler#74")
@given(x=floats(), y=floats())
def test_object_size(x, y):
    """Check that Vector2 is 2 times smaller than a naïve version."""
    from pympler.asizeof import asizeof as sizeof  # type: ignore

    assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2


@given(v=vectors())
def test_weak_ref(v):
    """Check that weak references can be made to Vector2s."""
    assert weakref.ref(v) is not None

Disable test_object_size under CPython 3.8
tests/memory: Disable test_object_size under CPython 3.8

  import sys
  import weakref
  
  import pytest  # type: ignore
  from hypothesis import given
  
  from ppb_vector import Vector2
  from utils import floats, vectors
  
  
  class DummyVector:
      """A naïve representation of vectors."""
  
      x: float
      y: float
  
      def __init__(self, x, y):
          self.x = float(x)
          self.y = float(y)
  
  
  @pytest.mark.skipif(sys.implementation.name != 'cpython',
                      reason="PyPy optimises __slots__ automatically.")
+ @pytest.mark.skipif(sys.implementation.version.minor > 7,
+                     reason="Pympler 0.6 is broken under Python 3.8.  See pympler#74")
  @given(x=floats(), y=floats())
  def test_object_size(x, y):
      """Check that Vector2 is 2 times smaller than a naïve version."""
      from pympler.asizeof import asizeof as sizeof  # type: ignore
  
      assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2
  
  
  @given(v=vectors())
  def test_weak_ref(v):
      """Check that weak references can be made to Vector2s."""
      assert weakref.ref(v) is not None
  
Disable test_object_size under CPython 3.8
## Code Before:
import sys
import weakref

import pytest  # type: ignore
from hypothesis import given

from ppb_vector import Vector2
from utils import floats, vectors


class DummyVector:
    """A naïve representation of vectors."""

    x: float
    y: float

    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)


@pytest.mark.skipif(sys.implementation.name != 'cpython',
                    reason="PyPy optimises __slots__ automatically.")
@given(x=floats(), y=floats())
def test_object_size(x, y):
    """Check that Vector2 is 2 times smaller than a naïve version."""
    from pympler.asizeof import asizeof as sizeof  # type: ignore

    assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2


@given(v=vectors())
def test_weak_ref(v):
    """Check that weak references can be made to Vector2s."""
    assert weakref.ref(v) is not None

## Instruction:
Disable test_object_size under CPython 3.8
## Code After:
import sys
import weakref

import pytest  # type: ignore
from hypothesis import given

from ppb_vector import Vector2
from utils import floats, vectors


class DummyVector:
    """A naïve representation of vectors."""

    x: float
    y: float

    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)


@pytest.mark.skipif(sys.implementation.name != 'cpython',
                    reason="PyPy optimises __slots__ automatically.")
@pytest.mark.skipif(sys.implementation.version.minor > 7,
                    reason="Pympler 0.6 is broken under Python 3.8.  See pympler#74")
@given(x=floats(), y=floats())
def test_object_size(x, y):
    """Check that Vector2 is 2 times smaller than a naïve version."""
    from pympler.asizeof import asizeof as sizeof  # type: ignore

    assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2


@given(v=vectors())
def test_weak_ref(v):
    """Check that weak references can be made to Vector2s."""
    assert weakref.ref(v) is not None
