Skip to content

Commit

Permalink
Fix gauss function typos
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Sep 21, 2023
1 parent 9c29b1a commit f93a1cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes relevant to the users of python-tcod are documented here.
This project adheres to [Semantic Versioning](https://semver.org/) since version `2.0.0`.

## [Unreleased]
### Changed
- Renamed `gauss` methods to fix typos.

## [16.1.1] - 2023-07-10
### Changed
Expand Down
19 changes: 17 additions & 2 deletions tcod/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Any, Hashable

import tcod.constants
from tcod._internal import deprecate
from tcod.cffi import ffi, lib

MERSENNE_TWISTER = tcod.constants.RNG_MT
Expand Down Expand Up @@ -110,7 +111,7 @@ def uniform(self, low: float, high: float) -> float:
"""
return float(lib.TCOD_random_get_double(self.random_c, low, high))

def guass(self, mu: float, sigma: float) -> float:
def gauss(self, mu: float, sigma: float) -> float:
"""Return a random number using Gaussian distribution.
Args:
Expand All @@ -119,10 +120,17 @@ def guass(self, mu: float, sigma: float) -> float:
Returns:
float: A random float.
.. versionchanged:: Unreleased
Renamed from `guass` to `gauss`.
"""
return float(lib.TCOD_random_get_gaussian_double(self.random_c, mu, sigma))

def inverse_guass(self, mu: float, sigma: float) -> float:
@deprecate("This is a typo, rename this to 'gauss'", category=FutureWarning)
def guass(self, mu: float, sigma: float) -> float: # noqa: D102
return self.gauss(mu, sigma)

def inverse_gauss(self, mu: float, sigma: float) -> float:
"""Return a random Gaussian number using the Box-Muller transform.
Args:
Expand All @@ -131,9 +139,16 @@ def inverse_guass(self, mu: float, sigma: float) -> float:
Returns:
float: A random float.
.. versionchanged:: Unreleased
Renamed from `inverse_guass` to `inverse_gauss`.
"""
return float(lib.TCOD_random_get_gaussian_double_inv(self.random_c, mu, sigma))

@deprecate("This is a typo, rename this to 'inverse_gauss'", category=FutureWarning)
def inverse_guass(self, mu: float, sigma: float) -> float: # noqa: D102
return self.inverse_gauss(mu, sigma)

def __getstate__(self) -> Any:
"""Pack the self.random_c attribute into a portable state."""
state = self.__dict__.copy()
Expand Down
9 changes: 9 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tcod.constants
import tcod.event
import tcod.libtcodpy
import tcod.random

with pytest.warns():
import libtcodpy
Expand Down Expand Up @@ -53,3 +54,11 @@ def test_line_where() -> None:
with pytest.warns():
where = tcod.libtcodpy.line_where(1, 0, 3, 4)
np.testing.assert_array_equal(where, [[1, 1, 2, 2, 3], [0, 1, 2, 3, 4]])


def test_gauss_typo() -> None:
rng = tcod.random.Random()
with pytest.warns(FutureWarning, match=r"gauss"):
rng.guass(1, 1)
with pytest.warns(FutureWarning, match=r"inverse_gauss"):
rng.inverse_guass(1, 1)

0 comments on commit f93a1cb

Please sign in to comment.