Skip to main content

Hypothesis strategies for unxt

Project description

unxt-hypothesis

Hypothesis strategies for unxt - unitful quantities in JAX.

This package provides Hypothesis strategies for generating unxt objects for for property-based testing.

Installation

uv add unxt-hypothesis

Usage

from hypothesis import given

import unxt_hypothesis as ust


@given(q=ust.quantities(unit="km/s"))
def test_quantity_property(q):
    # Test some property of quantities
    assert q.value is not None
    assert q.unit is not None


@given(u=ust.units("length"))
def test_unit_property(u):
    # Test some property of units
    assert u is not None


@given(sys=ust.unitsystems("m", "s", "kg", "rad"))
def test_unitsystem_property(sys):
    # Test some property of unit systems
    assert len(sys) == 4

Custom strategies

You can customize the strategies:

from hypothesis import strategies as st

import unxt as u
import unxt_hypothesis as ust


# Generate quantities with specific shapes
@given(q=ust.quantities(unit="m", shape=st.just((3, 3))))
def test_matrix_quantity(q):
    assert q.shape == (3, 3)


# Generate quantities with specific dimensions
@given(q=ust.quantities(unit=ust.units("length")))
def test_length_quantity(q):
    assert u.dimension_of(q) == u.dimension("length")

API

quantities(draw, *, shape=None, dtype=None, unit=None)

Generate random Quantity objects.

Parameters:

  • draw: Hypothesis draw function
  • shape: Strategy for array shapes (optional, defaults to small arrays)
  • dtype: Strategy for array dtypes (optional, defaults to float32)
  • unit: Strategy for unit strings (optional, defaults to common units)

Returns: A unxt.Quantity instance

units(draw, dimension=None, *, max_complexity=2, allow_non_integer_powers=False)

Generate random Unit objects.

Parameters:

  • draw: Hypothesis draw function
  • dimension: Physical dimension (optional, e.g., "length", "velocity")
  • max_complexity: Maximum complexity of compound units (default: 2)
  • allow_non_integer_powers: Allow non-integer powers (default: False)

Returns: A unxt.AbstractUnit instance

unitsystems(*units)

Generate random UnitSystem objects.

Parameters:

  • *units: Variable number of unit specifications. Each can be:
    • str: Fixed unit string (e.g., "m", "kg")
    • unxt.AbstractUnit: Fixed unit object
    • Strategy: A Hypothesis strategy that generates units

Returns: A unxt.AbstractUnitSystem instance

Example:

from hypothesis import given

import unxt_hypothesis as ust


# Fixed unit system
@given(sys=ust.unitsystems("m", "s", "kg", "rad"))
def test_mks_system(sys):
    assert len(sys) == 4


# Varying length unit, other units fixed
@given(sys=ust.unitsystems(ust.units("length"), "s", "kg", "rad"))
def test_varying_length(sys):
    assert len(sys) == 4

Documentation

For comprehensive documentation, examples, and guides, see the unxt documentation.

License

BSD 3-Clause License. See LICENSE for details.

Contributing

Contributions are welcome! Please see the main unxt repository for contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unxt_hypothesis-0.1.dev410.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unxt_hypothesis-0.1.dev410-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file unxt_hypothesis-0.1.dev410.tar.gz.

File metadata

  • Download URL: unxt_hypothesis-0.1.dev410.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unxt_hypothesis-0.1.dev410.tar.gz
Algorithm Hash digest
SHA256 e5c30693907e2a789708a5aa1e207d2752a9c9e8ce6e47bef412207e9b4b5e82
MD5 6a07715e742d5b89c13850c7262fac10
BLAKE2b-256 0eb6f5375eb83fa7cbcd10cc68252d4cd990fc1dffaf95113ce30e92c61c1378

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_hypothesis-0.1.dev410.tar.gz:

Publisher: cd-unxt-hypothesis.yml on GalacticDynamics/unxt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unxt_hypothesis-0.1.dev410-py3-none-any.whl.

File metadata

File hashes

Hashes for unxt_hypothesis-0.1.dev410-py3-none-any.whl
Algorithm Hash digest
SHA256 fbdc06776fdf479e7971b1e39b1896aa81a218f8f07f17beeb112d96f6a167f0
MD5 5ea0220e2aaeb8ef7e2e1d17805c47e7
BLAKE2b-256 baeb192f78d8a7bbdba7b8d80fb0a6433b717492a167d8a37afe5281d098881e

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_hypothesis-0.1.dev410-py3-none-any.whl:

Publisher: cd-unxt-hypothesis.yml on GalacticDynamics/unxt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page