stringcalc 0.1.0.dev2__tar.gz → 0.1.0.dev4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,38 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
- workflow_dispatch: # allow manual triggering
9
- schedule:
10
- - cron: "0 12 1 * *"
11
-
12
- jobs:
13
- build:
14
- runs-on: ubuntu-latest
15
- strategy:
16
- matrix:
17
- python-version: ["3.8", "3.9", "3.10"]
18
-
19
- steps:
20
- - uses: actions/checkout@v3
21
-
22
- - name: Set up Python ${{ matrix.python-version }}
23
- uses: actions/setup-python@v3
24
- with:
25
- python-version: ${{ matrix.python-version }}
26
-
27
- - name: Install dependencies
28
- run: |
29
- python -m pip install --upgrade pip setuptools wheel
30
- python -m pip install flit
31
- flit install --extras=test
32
-
33
- - name: Test with pytest
34
- run: pytest -v
35
-
36
- - name: Check type annotations
37
- run: |
38
- mypy --install-types --non-interactive .
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch: # allow manual triggering
9
+ schedule:
10
+ - cron: "0 12 1 * *"
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version: ["3.8", "3.9", "3.10"]
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v3
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip setuptools wheel
30
+ python -m pip install flit
31
+ flit install --extras=test
32
+
33
+ - name: Test with pytest
34
+ run: pytest -v
35
+
36
+ - name: Check type annotations
37
+ run: |
38
+ mypy --non-interactive .
@@ -1,34 +1,34 @@
1
- repos:
2
- - repo: https://github.com/pre-commit/pre-commit-hooks
3
- rev: "v4.3.0"
4
- hooks:
5
- - id: trailing-whitespace
6
- - id: end-of-file-fixer
7
- - id: check-docstring-first
8
- - id: check-yaml
9
-
10
- - repo: https://github.com/asottile/pyupgrade
11
- rev: "v3.2.0"
12
- hooks:
13
- - id: pyupgrade
14
- args: [--py38-plus]
15
-
16
- - repo: https://github.com/PyCQA/isort
17
- rev: "5.10.1"
18
- hooks:
19
- - id: isort
20
-
21
- - repo: https://github.com/psf/black
22
- rev: "22.10.0"
23
- hooks:
24
- - id: black
25
-
26
- - repo: https://github.com/csachs/pyproject-flake8
27
- rev: "v5.0.4a1.post1"
28
- hooks:
29
- - id: pyproject-flake8 # pflake8
30
-
31
- - repo: https://github.com/pre-commit/mirrors-prettier
32
- rev: "v2.7.1"
33
- hooks:
34
- - id: prettier
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: "v4.4.0"
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-docstring-first
8
+ - id: check-yaml
9
+
10
+ - repo: https://github.com/asottile/pyupgrade
11
+ rev: "v3.3.1"
12
+ hooks:
13
+ - id: pyupgrade
14
+ args: [--py38-plus]
15
+
16
+ - repo: https://github.com/PyCQA/isort
17
+ rev: "5.12.0"
18
+ hooks:
19
+ - id: isort
20
+
21
+ - repo: https://github.com/psf/black
22
+ rev: "23.1.0"
23
+ hooks:
24
+ - id: black
25
+
26
+ - repo: https://github.com/csachs/pyproject-flake8
27
+ rev: "v6.0.0.post1"
28
+ hooks:
29
+ - id: pyproject-flake8 # pflake8
30
+
31
+ - repo: https://github.com/pre-commit/mirrors-prettier
32
+ rev: "v2.7.1"
33
+ hooks:
34
+ - id: prettier
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stringcalc
3
- Version: 0.1.0.dev2
3
+ Version: 0.1.0.dev4
4
4
  Summary: Calculations for instrument strings
5
5
  Author-email: zmoon <zmoon92@gmail.com>
6
6
  Requires-Python: ~=3.8
@@ -24,12 +24,12 @@ Provides-Extra: test
24
24
 
25
25
  # stringcalc
26
26
 
27
+ *Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings*
28
+
27
29
  [![CI workflow status](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
28
30
  [![Version on PyPI](https://img.shields.io/pypi/v/stringcalc.svg)](https://pypi.org/project/stringcalc/)
29
31
  [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
30
32
 
31
- Calculations for instrument strings
32
-
33
33
  ## Prior art
34
34
 
35
35
  ### Web apps
@@ -1,60 +1,60 @@
1
- # stringcalc
2
-
3
- [![CI workflow status](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
4
- [![Version on PyPI](https://img.shields.io/pypi/v/stringcalc.svg)](https://pypi.org/project/stringcalc/)
5
- [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
6
-
7
- Calculations for instrument strings
8
-
9
- ## Prior art
10
-
11
- ### Web apps
12
-
13
- - D'Addario String Tension Pro -- <https://www.daddario.com/string-tension-pro/>
14
- - has been down for some time, partially inspiring this work
15
- - but I remember it being pretty nice
16
- - <https://stringtensioncalculator.com/>
17
- - specifically for [Kalium strings](https://kaliummusic.com/strings/)
18
- - somewhat similar to D'Addario String Tension Pro (from what I remember)
19
- - select scale length (0.25" increments), pitch, and gauge -> shows tension and frequency
20
- - shows 6 (or more) strings at once
21
- - scale length presets include a few multi-scale options
22
- - source: <https://github.com/aaronabramov/string-tension-calculator>
23
- - Shelquist -- <https://wahiduddin.net/calc/calc_guitar_tension_from_size.htm>
24
- - input scale length (in | cm), diameter (in | mm), pitch class, octave
25
- -> shows tension in lb and kg for several D'Addario steel-core string types
26
- - lots of info on the page
27
- - some nice messages if tension is too high or low
28
- - Curt Mangan -- <https://www.curtmangan.com/string-tension-calculator/>
29
- - 6, 7, or 8 strings
30
- - multiple scale length presets, including many multi-scale, but can't set your own
31
- - (guitar / electric bass focused)
32
- - standard tuning default, but a selector allows tuning down all strings by 1--4 half steps
33
- - for each string individually, can change gauge and pitch
34
- - shows tension plot and sum
35
- - Stringjoy -- <https://tension.stringjoy.com/>
36
- - some useful info on the page
37
- - for [Stringjoy strings](https://stringjoy.com/shop/strings/)
38
- - select string type, # of strings (6--9 | 12), scale length (any float, inches)
39
- - for each string individually, can change scale length, pitch, gauge
40
- - shows individual tensions and total tension interactively (i.e. don't need to submit)
41
- - [Theo Parmakis](http://parmakis-instruments.co.uk/about-theo) -- <http://chordgen.rattree.co.uk/tensiontool.php>
42
- - some useful info on the page (« show more information... »)
43
- - unique feature: offers presets for different instruments, including different tunings
44
- - reference presets "are mostly based upon my own instruments, and the gauges I usually string them with"
45
- - once, you find a preset you like, click and can edit
46
- - for whole set, can change scale length (any float, in | mm), string material, winding material (can't set individually), whether to double all
47
- - for each string, can change pitch, plain or wound, string material (steel, nylon, gut, Nylgut), gauge, single or double
48
- - shows tensions for each course and the total
49
- - unique feature: "equalize" button, defaults to tension on top string but can choose which one you want to equalize to
50
- - based on the D'Addario data but also extrapolating to some other materials
51
- - can show tension (lb), string gauge, and frequency (Hz) plots
52
- - nice text format, e.g. `.026 w N @ 25" = 13.165 lb`
53
- - can handle strings starting arbitrarily further up the fretboard (after the `@` in the tuning editor)
54
- - purports to offer the source code, but the link currently (2022-04-15) doesn't work
55
- - <https://rodrigocfd.github.io/string-tension-calc/>
56
- - compare multiple string sets using string tensions and a tension plot (though not total tension)
57
- - electric guitar focused, including a few 7- and 8-string sets
58
- - after selecting a set, can adjust individual strings (gauge and plain/wound) and pitches (-5--+1 half steps)
59
- - can also choose to tune down the whole set by up to 4 half steps, like the Curt Mangan app
60
- - source: <https://github.com/rodrigocfd/string-tension-calc>
1
+ # stringcalc
2
+
3
+ *Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings*
4
+
5
+ [![CI workflow status](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
6
+ [![Version on PyPI](https://img.shields.io/pypi/v/stringcalc.svg)](https://pypi.org/project/stringcalc/)
7
+ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
8
+
9
+ ## Prior art
10
+
11
+ ### Web apps
12
+
13
+ - D'Addario String Tension Pro -- <https://www.daddario.com/string-tension-pro/>
14
+ - has been down for some time, partially inspiring this work
15
+ - but I remember it being pretty nice
16
+ - <https://stringtensioncalculator.com/>
17
+ - specifically for [Kalium strings](https://kaliummusic.com/strings/)
18
+ - somewhat similar to D'Addario String Tension Pro (from what I remember)
19
+ - select scale length (0.25" increments), pitch, and gauge -> shows tension and frequency
20
+ - shows 6 (or more) strings at once
21
+ - scale length presets include a few multi-scale options
22
+ - source: <https://github.com/aaronabramov/string-tension-calculator>
23
+ - Shelquist -- <https://wahiduddin.net/calc/calc_guitar_tension_from_size.htm>
24
+ - input scale length (in | cm), diameter (in | mm), pitch class, octave
25
+ -> shows tension in lb and kg for several D'Addario steel-core string types
26
+ - lots of info on the page
27
+ - some nice messages if tension is too high or low
28
+ - Curt Mangan -- <https://www.curtmangan.com/string-tension-calculator/>
29
+ - 6, 7, or 8 strings
30
+ - multiple scale length presets, including many multi-scale, but can't set your own
31
+ - (guitar / electric bass focused)
32
+ - standard tuning default, but a selector allows tuning down all strings by 1--4 half steps
33
+ - for each string individually, can change gauge and pitch
34
+ - shows tension plot and sum
35
+ - Stringjoy -- <https://tension.stringjoy.com/>
36
+ - some useful info on the page
37
+ - for [Stringjoy strings](https://stringjoy.com/shop/strings/)
38
+ - select string type, # of strings (6--9 | 12), scale length (any float, inches)
39
+ - for each string individually, can change scale length, pitch, gauge
40
+ - shows individual tensions and total tension interactively (i.e. don't need to submit)
41
+ - [Theo Parmakis](http://parmakis-instruments.co.uk/about-theo) -- <http://chordgen.rattree.co.uk/tensiontool.php>
42
+ - some useful info on the page (« show more information... »)
43
+ - unique feature: offers presets for different instruments, including different tunings
44
+ - reference presets "are mostly based upon my own instruments, and the gauges I usually string them with"
45
+ - once, you find a preset you like, click and can edit
46
+ - for whole set, can change scale length (any float, in | mm), string material, winding material (can't set individually), whether to double all
47
+ - for each string, can change pitch, plain or wound, string material (steel, nylon, gut, Nylgut), gauge, single or double
48
+ - shows tensions for each course and the total
49
+ - unique feature: "equalize" button, defaults to tension on top string but can choose which one you want to equalize to
50
+ - based on the D'Addario data but also extrapolating to some other materials
51
+ - can show tension (lb), string gauge, and frequency (Hz) plots
52
+ - nice text format, e.g. `.026 w N @ 25" = 13.165 lb`
53
+ - can handle strings starting arbitrarily further up the fretboard (after the `@` in the tuning editor)
54
+ - purports to offer the source code, but the link currently (2022-04-15) doesn't work
55
+ - <https://rodrigocfd.github.io/string-tension-calc/>
56
+ - compare multiple string sets using string tensions and a tension plot (though not total tension)
57
+ - electric guitar focused, including a few 7- and 8-string sets
58
+ - after selecting a set, can adjust individual strings (gauge and plain/wound) and pitches (-5--+1 half steps)
59
+ - can also choose to tune down the whole set by up to 4 half steps, like the Curt Mangan app
60
+ - source: <https://github.com/rodrigocfd/string-tension-calc>
@@ -65,3 +65,5 @@ exclude = [
65
65
  "^venv/",
66
66
  "^data/",
67
67
  ]
68
+ install_types = true
69
+ ignore_missing_imports = true
@@ -2,4 +2,4 @@
2
2
  Calculations for instrument strings
3
3
  """
4
4
 
5
- __version__ = "0.1.0.dev2"
5
+ __version__ = "0.1.0.dev4"
@@ -3,6 +3,7 @@ CLI
3
3
  """
4
4
  from __future__ import annotations
5
5
 
6
+ import functools
6
7
  import re
7
8
  from pathlib import Path
8
9
 
@@ -31,9 +32,9 @@ def _to_fancy_sci(s: str) -> str:
31
32
  return f"{a}×10{b}"
32
33
 
33
34
 
34
- def error(s: str, *, rc: int = 1) -> None:
35
+ def error(s: str, *, rc: int = 1, markup: bool = True) -> None:
35
36
  """Print error message."""
36
- console.print(s, style=Style(color="red", bold=True), highlight=False)
37
+ console.print(s, style=Style(color="red", bold=True), highlight=False, markup=markup)
37
38
  assert rc != 0
38
39
  raise typer.Exit(rc)
39
40
 
@@ -43,6 +44,26 @@ def info(s: str) -> None:
43
44
  console.print(s, style=Style(color="cyan", bold=True), highlight=False)
44
45
 
45
46
 
47
+ def warning(s: str) -> None:
48
+ """Print warning message."""
49
+ console.print(s, style=Style(color="red", bold=False), highlight=False)
50
+
51
+
52
+ def pretty_warnings(f):
53
+ """Decorator to catch warnings and pretty-print them with Rich after running `f`."""
54
+ import warnings
55
+
56
+ @functools.wraps(f)
57
+ def inner(*args, **kwargs):
58
+ with warnings.catch_warnings(record=True) as w:
59
+ f(*args, **kwargs)
60
+
61
+ for i in range(len(w)):
62
+ warning(f"- {w[i].message}")
63
+
64
+ return inner
65
+
66
+
46
67
  def _version_callback(show: bool):
47
68
  if show:
48
69
  import subprocess
@@ -140,7 +161,7 @@ def pprint_table(df, *, title: str, float_format: str) -> None:
140
161
  @app.command()
141
162
  def frets(
142
163
  N: int = typer.Option(
143
- ..., "-N", "--number", help="Number of frets, starting from nut (fret 0)."
164
+ 17, "-N", "--number", help="Number of frets, starting from nut (fret 0)."
144
165
  ),
145
166
  L: float = typer.Option(..., "-L", "--scale-length", help="Scale length."),
146
167
  float_format: str = typer.Option(r"%.3f", help="Format for float-to-string conversion."),
@@ -155,7 +176,7 @@ def frets(
155
176
  pprint_table(df, title=f"Fret distances for L={L}", float_format=float_format)
156
177
 
157
178
 
158
- _RE_LENGTH_SPEC = re.compile(r"(?P<a>[0-9ns])-(?P<b>[0-9ns])=(?P<d>[0-9e\.\+\-\.]+)")
179
+ _RE_LENGTH_SPEC = re.compile(r"(?P<a>[0-9]+|[ns])-(?P<b>[0-9]+|[ns])=(?P<d>[0-9e\.\+\-\.]+)")
159
180
 
160
181
 
161
182
  def _ab_interp(s: str) -> int | None:
@@ -192,15 +213,25 @@ def length(
192
213
 
193
214
  m = _RE_LENGTH_SPEC.fullmatch(spec)
194
215
  if m is None:
195
- error(f"Input failed to match a-b=d spec format regex {_RE_LENGTH_SPEC.pattern!r}", rc=2)
216
+ error(
217
+ f"Input failed to match a-b=d spec format regex {_RE_LENGTH_SPEC.pattern!r}",
218
+ rc=2,
219
+ markup=False,
220
+ )
196
221
 
197
222
  assert m is not None
198
223
  dct = m.groupdict()
199
- a = _ab_interp(dct["a"])
200
- b = _ab_interp(dct["b"])
201
- d = float(dct["d"])
202
-
203
- res = length_from_distance((a, b), d)
224
+ try:
225
+ a = _ab_interp(dct["a"])
226
+ b = _ab_interp(dct["b"])
227
+ d = float(dct["d"])
228
+ except ValueError as e:
229
+ error(f"Failed to convert input to frets. Message: {e}", rc=2)
230
+
231
+ try:
232
+ res = length_from_distance((a, b), d)
233
+ except ValueError as e:
234
+ error(f"Failed to compute scale length. Message: {e}", rc=2)
204
235
 
205
236
  if round_ is not None:
206
237
  res = round(float(res), round_)
@@ -218,6 +249,7 @@ def length(
218
249
 
219
250
 
220
251
  @app.command(name="gauge")
252
+ @pretty_warnings
221
253
  def gauge_(
222
254
  T: float = typer.Option(..., "-T", "--tension", help="Desired tension"),
223
255
  L: float = typer.Option(..., "-L", "--length", help="String length (scale length)."),
@@ -28,7 +28,7 @@ def distance_et(n: int | npt.ArrayLike, *, L: float) -> np.float_ | npt.NDArray[
28
28
  Parameters
29
29
  ----------
30
30
  n
31
- Fret number.
31
+ Fret number (or array-like of them).
32
32
  If floats are passed, they will be floored before computing.
33
33
  s
34
34
  Scale length.
@@ -9,6 +9,7 @@ from __future__ import annotations
9
9
 
10
10
  import math
11
11
  import re
12
+ import warnings
12
13
  from functools import lru_cache
13
14
  from pathlib import Path
14
15
  from typing import NamedTuple
@@ -254,9 +255,15 @@ def suggest_gauge(
254
255
  data_sort["T"] = T_all[data_sort.index]
255
256
  data_sort["dT"] = data_sort["T"] - T
256
257
 
257
- # TODO: warning if edge is one of the closest
258
+ b = 1.7 # TODO: allow to set this?
259
+ if (data_sort["dT"] > b).all() or (data_sort["dT"] < -b).all():
260
+ warnings.warn(
261
+ f"You are outside the range of what string type group(s) {types} can provide. "
262
+ "Maybe a different string type can give the tension/pitch/length you desire.",
263
+ stacklevel=2,
264
+ )
258
265
 
259
- df = data_sort[["id", "T", "dT"]].sort_values(by="id").reset_index(drop=True)
266
+ df = data_sort[["id", "T", "dT"]].sort_values(by="dT").reset_index(drop=True)
260
267
  desc = {
261
268
  "id": "Product ID",
262
269
  "T": "Tension",
@@ -0,0 +1,90 @@
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from stringcalc import frets
5
+
6
+
7
+ @pytest.mark.parametrize(
8
+ "n, expected",
9
+ [
10
+ (12, 0.5),
11
+ (24, 0.75),
12
+ ([12, 24], np.array([0.5, 0.75], dtype=float)),
13
+ (1, 0.05613),
14
+ (5, 0.25085),
15
+ ],
16
+ )
17
+ def test_d_et_rel(n, expected):
18
+ np.testing.assert_allclose(frets.distance_et(n, L=1), expected, rtol=1e-4)
19
+
20
+
21
+ def test_ds_et_rel():
22
+ ret = frets.distances(N=24, L=1)
23
+ assert ret.loc[12].d == 0.5
24
+ assert ret.loc[24].d == 0.75
25
+
26
+
27
+ def test_ds_invalid():
28
+ with pytest.raises(ValueError, match=r"invalid `method` 'asdf'"):
29
+ frets.distances(N=17, L=21, method="asdf")
30
+
31
+
32
+ @pytest.mark.parametrize(
33
+ "n",
34
+ [
35
+ -1,
36
+ -0.1,
37
+ [-2, -1],
38
+ [-1, 0, 1],
39
+ ],
40
+ )
41
+ def test_d_et_invalid(n):
42
+ with pytest.raises(ValueError, match="input fret numbers should be positive"):
43
+ frets.distance_et(n=-1, L=25)
44
+
45
+
46
+ @pytest.mark.parametrize(
47
+ "ab, d, expected",
48
+ [
49
+ ((0, 2), 2, 18.332),
50
+ ((2, None), 16.3316, 18.332),
51
+ ((2, None), 21, 23.572),
52
+ ((0, 1), 1, 17.817),
53
+ ((1, 0), 1, 17.817),
54
+ ],
55
+ )
56
+ def test_l_from_d(ab, d, expected):
57
+ assert frets.length_from_distance(ab, d) == pytest.approx(expected, abs=5e-4)
58
+
59
+
60
+ def test_l_from_d_pint():
61
+ # Seems not to work with `pytest.approx`
62
+ ret = frets.length_from_distance(ab=(1, 0), d="1in")
63
+ expected = 17.817 * frets.ureg["in"]
64
+ delta = 5e-4 * frets.ureg["in"]
65
+ assert expected - delta <= ret <= expected + delta
66
+
67
+
68
+ def test_l_from_d_invalid_ab():
69
+ with pytest.raises(ValueError, match="must be different"):
70
+ frets.length_from_distance((0, 0), 10)
71
+
72
+
73
+ def test_l_from_d_invalid_d():
74
+ with pytest.raises(ValueError, match="must be positive"):
75
+ frets.length_from_distance((0, 1), -10)
76
+
77
+
78
+ def test_main():
79
+ import runpy
80
+ import warnings
81
+
82
+ mod_name = "stringcalc.frets"
83
+ with warnings.catch_warnings():
84
+ warnings.filterwarnings(
85
+ "ignore",
86
+ category=RuntimeWarning,
87
+ message=rf"{mod_name!r} found in sys\.modules after import of package",
88
+ )
89
+
90
+ runpy.run_module(mod_name, run_name="__main__")
@@ -60,6 +60,22 @@ def test_suggest_gauge():
60
60
  assert ret.id.tolist() == ["NYL031", "NYL032", "NYL033"]
61
61
 
62
62
 
63
+ @pytest.mark.parametrize(
64
+ "pitch",
65
+ ["G1", "G4"],
66
+ )
67
+ def test_suggest_gauge_bounds_warning(pitch):
68
+ T = 15
69
+ L = 21
70
+ types = {"PB"}
71
+
72
+ with pytest.warns(
73
+ UserWarning,
74
+ match=r"You are outside the range of what string type group\(s\) \{'PB'\} can provide\.",
75
+ ):
76
+ suggest_gauge(T=T, L=L, pitch=pitch, types=types)
77
+
78
+
63
79
  @pytest.mark.parametrize(
64
80
  "T,pitch,expected",
65
81
  [
@@ -1,42 +0,0 @@
1
- import numpy as np
2
- import pytest
3
-
4
- from stringcalc import frets
5
-
6
-
7
- @pytest.mark.parametrize(
8
- "n, expected",
9
- [
10
- (12, 0.5),
11
- (24, 0.75),
12
- ([12, 24], np.array([0.5, 0.75], dtype=float)),
13
- (1, 0.05613),
14
- (5, 0.25085),
15
- ],
16
- )
17
- def test_d_et_rel(n, expected):
18
- np.testing.assert_allclose(frets.distance_et(n, L=1), expected, rtol=1e-4)
19
-
20
-
21
- @pytest.mark.parametrize(
22
- "ab, d, expected",
23
- [
24
- ((0, 2), 2, 18.332),
25
- ((2, None), 16.3316, 18.332),
26
- ((2, None), 21, 23.572),
27
- ((0, 1), 1, 17.817),
28
- ((1, 0), 1, 17.817),
29
- ],
30
- )
31
- def test_l_from_d(ab, d, expected):
32
- assert frets.length_from_distance(ab, d) == pytest.approx(expected, abs=5e-4)
33
-
34
-
35
- def test_l_from_d_invalid_ab():
36
- with pytest.raises(ValueError, match="must be different"):
37
- frets.length_from_distance((0, 0), 10)
38
-
39
-
40
- def test_l_from_d_invalid_d():
41
- with pytest.raises(ValueError, match="must be positive"):
42
- frets.length_from_distance((0, 1), -10)
File without changes