mirror of
https://github.com/diodeinc/pcb.git
synced 2026-09-14 20:17:19 +08:00
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
"""Tests for general utility functions."""
|
|
|
|
load("../units.zen", "Capacitance", "Resistance")
|
|
load("../utils.zen", "E_SERIES", "e3", "e6", "e12", "e24", "e48", "e96", "e192")
|
|
|
|
check(len(E_SERIES["E48"]) == 48, "E48 should contain 48 values")
|
|
check(len(E_SERIES["E192"]) == 192, "E192 should contain 192 values")
|
|
check(e48(Resistance("115ohm")) == Resistance("115ohm"), "E48 should preserve 115 ohm")
|
|
check(e192(Resistance("740.3kohm")) == Resistance("741kohm"), "E192 should snap 740.3 kohm to 741 kohm")
|
|
|
|
for series_name, snap in [
|
|
("E3", e3),
|
|
("E6", e6),
|
|
("E12", e12),
|
|
("E24", e24),
|
|
("E48", e48),
|
|
("E96", e96),
|
|
("E192", e192),
|
|
]:
|
|
check(
|
|
snap(Capacitance("9.97nF")) == Capacitance("10nF"),
|
|
"{} should consider the next decade".format(series_name),
|
|
)
|
|
|
|
# Preserve absolute-nearest behavior where it differs from geometric-nearest.
|
|
check(e12(Capacitance("9.08nF")) == Capacitance("8.2nF"), "E12 should use absolute distance")
|
|
|
|
# Check the same boundary above and below the base-unit decade.
|
|
check(e12(Capacitance("0.997nF")) == Capacitance("1nF"), "E12 should cross a lower decade")
|
|
check(e24(Capacitance("99.7nF")) == Capacitance("100nF"), "E24 should cross a higher decade")
|
|
|
|
# Preserve exact E-series inputs when restoring their original decade.
|
|
for value in ["40.2kohm", "402ohm", "402kohm"]:
|
|
check(e96(Resistance(value)) == Resistance(value), "E96 should preserve exact value " + value)
|
|
check(e24(Capacitance("2.7nF")) == Capacitance("2.7nF"), "E24 should preserve exact value 2.7nF")
|