<commit_before>from math import isclose

from hypothesis import assume, given

from ppb_vector import Vector2
from utils import floats, vectors


@given(scalar=floats(), vector=vectors())
def test_scalar_coordinates(scalar: float, vector: Vector2):
    assert scalar * vector.x == (scalar * vector).x
    assert scalar * vector.y == (scalar * vector).y


@given(scalar1=floats(), scalar2=floats(), x=vectors())
def test_scalar_associative(scalar1: float, scalar2: float, x: Vector2):
    """(scalar1 * scalar2) * x == scalar1 * (scalar2 * x)"""
    left = (scalar1 * scalar2) * x
    right = scalar1 * (scalar2 * x)
    assert left.isclose(right)


@given(scalar=floats(), x=vectors(), y=vectors())
def test_scalar_linear(scalar: float, x: Vector2, y: Vector2):
    assert (scalar * (x + y)).isclose(
        scalar * x + scalar * y,
        rel_to=[x, y, scalar * x, scalar * y],
    )


@given(scalar=floats(), x=vectors())
def test_scalar_length(scalar: float, x: Vector2):
    assert isclose((scalar * x).length, abs(scalar) * x.length)


@given(x=vectors(), scalar=floats())
def test_scalar_division(x: Vector2, scalar: float):
    """Test that (x / λ) = (1 / λ) * x"""
    assume(abs(scalar) > 1e-100)
    assert (x / scalar).isclose((1 / scalar) * x)

@given(x=vectors(), scalar=floats())
def test_scalar_inverse(x: Vector2, scalar: float):
    """Test that (x / λ) = (1 / λ) * x"""
    assume(abs(scalar) > 1e-100)
    assert x.isclose(scalar * x / scalar)<commit_msg>tests/scalar: Fix the docstring of test_scalar_inverse<commit_after>from math import isclose

from hypothesis import assume, given

from ppb_vector import Vector2
from utils import floats, vectors


@given(scalar=floats(), vector=vectors())
def test_scalar_coordinates(scalar: float, vector: Vector2):
    assert scalar * vector.x == (scalar * vector).x
    assert scalar * vector.y == (scalar * vector).y


@given(scalar1=floats(), scalar2=floats(), x=vectors())
def test_scalar_associative(scalar1: float, scalar2: float, x: Vector2):
    """(scalar1 * scalar2) * x == scalar1 * (scalar2 * x)"""
    left = (scalar1 * scalar2) * x
    right = scalar1 * (scalar2 * x)
    assert left.isclose(right)


@given(scalar=floats(), x=vectors(), y=vectors())
def test_scalar_linear(scalar: float, x: Vector2, y: Vector2):
    assert (scalar * (x + y)).isclose(
        scalar * x + scalar * y,
        rel_to=[x, y, scalar * x, scalar * y],
    )


@given(scalar=floats(), x=vectors())
def test_scalar_length(scalar: float, x: Vector2):
    assert isclose((scalar * x).length, abs(scalar) * x.length)


@given(x=vectors(), scalar=floats())
def test_scalar_division(x: Vector2, scalar: float):
    """Test that (x / λ) = (1 / λ) * x"""
    assume(abs(scalar) > 1e-100)
    assert (x / scalar).isclose((1 / scalar) * x)

@given(x=vectors(), scalar=floats())
def test_scalar_inverse(x: Vector2, scalar: float):
    """Test that (λ * x / λ) ≃ x"""
    assume(abs(scalar) > 1e-100)
    assert x.isclose(scalar * x / scalar)
{'fraction_non_alphanumeric': 0.1643789755607633, 'fraction_numerical': 0.02042182792099096, 'mean_word_length': 4.16955017301038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '664193', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1017, 'n_words': 280}