Skip to content

Commit 7b57033

Browse files
Add UnitDisplay tests
1 parent 6c30c8d commit 7b57033

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

tests/test_post.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"""Tests the post methods."""
22

3-
from concreteproperties.post import string_formatter
3+
import math
4+
5+
import pytest
6+
7+
from concreteproperties.post import si_kn_m, si_n_mm, string_formatter
48

59

610
def test_string_formatter():
@@ -24,4 +28,55 @@ def test_string_formatter():
2428
assert string_formatter(value=14435.654, eng=True, prec=3, scale=1e-3) == "14.44"
2529

2630

27-
# TODO: unit display tests
31+
def test_unit_display():
32+
"""Tests the unit display class."""
33+
assert si_n_mm.length_unit == " mm"
34+
assert si_kn_m.length_unit == " m"
35+
assert si_n_mm.length_scale == pytest.approx(1)
36+
assert si_kn_m.length_scale == pytest.approx(0.001)
37+
assert si_n_mm.force_unit == " N"
38+
assert si_kn_m.force_unit == " kN"
39+
assert si_n_mm.force_scale == pytest.approx(1)
40+
assert si_kn_m.force_scale == pytest.approx(0.001)
41+
assert si_n_mm.mass_unit == " kg"
42+
assert si_kn_m.mass_unit == " kg"
43+
assert si_n_mm.mass_scale == pytest.approx(1)
44+
assert si_kn_m.mass_scale == pytest.approx(1)
45+
assert si_n_mm.angle_unit == " rads"
46+
assert si_kn_m.angle_unit == " rads"
47+
assert si_n_mm.angle_scale == pytest.approx(1)
48+
assert si_kn_m.angle_scale == pytest.approx(1)
49+
si_n_mm.radians = False
50+
assert si_n_mm.angle_unit == " degs"
51+
assert si_n_mm.angle_scale == pytest.approx(180 / math.pi)
52+
assert si_n_mm.area_unit == " mm^2"
53+
assert si_kn_m.area_unit == " m^2"
54+
assert si_n_mm.area_scale == pytest.approx(1)
55+
assert si_kn_m.area_scale == pytest.approx(1e-6)
56+
assert si_n_mm.mass_per_length_unit == " kg/mm"
57+
assert si_kn_m.mass_per_length_unit == " kg/m"
58+
assert si_n_mm.mass_per_length_scale == pytest.approx(1)
59+
assert si_kn_m.mass_per_length_scale == pytest.approx(1e3)
60+
assert si_n_mm.moment_unit == " N.mm"
61+
assert si_kn_m.moment_unit == " kN.m"
62+
assert si_n_mm.moment_scale == pytest.approx(1)
63+
assert si_kn_m.moment_scale == pytest.approx(1e-6)
64+
assert si_n_mm.flex_rig_unit == " N.mm^2"
65+
assert si_kn_m.flex_rig_unit == " kN.m^2"
66+
assert si_n_mm.flex_rig_scale == pytest.approx(1)
67+
assert si_kn_m.flex_rig_scale == pytest.approx(1e-9)
68+
assert si_n_mm.stress_unit == " MPa"
69+
assert si_kn_m.stress_unit == " kPa"
70+
assert si_n_mm.stress_scale == pytest.approx(1)
71+
assert si_kn_m.stress_scale == pytest.approx(1e3)
72+
si_n_mm.length = "um"
73+
assert si_n_mm.stress_unit == " N/um^2"
74+
si_n_mm.length = "mm"
75+
assert si_n_mm.length_3_unit == " mm^3"
76+
assert si_kn_m.length_3_unit == " m^3"
77+
assert si_n_mm.length_3_scale == pytest.approx(1)
78+
assert si_kn_m.length_3_scale == pytest.approx(1e-9)
79+
assert si_n_mm.length_4_unit == " mm^4"
80+
assert si_kn_m.length_4_unit == " m^4"
81+
assert si_n_mm.length_4_scale == pytest.approx(1)
82+
assert si_kn_m.length_4_scale == pytest.approx(1e-12)

0 commit comments

Comments
 (0)