Debian Codegraph @

test/test_direction.py

raw symbols SCIP
1 """Test direction."""
2 import pytest
3 from metar.Datatypes import direction
4
5
6 def test_usage():
7 """Test basic usage."""
8 assert direction("90").value() == 90.0
9 assert direction(90).value() == 90.0
10 assert direction(90.0).value() == 90.0
11 assert direction("90").string() == "90 degrees"
12 assert direction("E").compass() == "E"
13
14
15 def test_error_checking():
16 """Test that exceptions are raised."""
17 with pytest.raises(ValueError):
18 direction("North")
19 with pytest.raises(ValueError):
20 direction(-10)
21 with pytest.raises(ValueError):
22 direction("361")
23
24
25 def test_conversion():
26 """Test conversion of str direction to numeric and back."""
27 assert direction("N").value() == 0.0
28 assert direction("NNE").value() == 22.5
29 assert direction("NE").value() == 45.0
30 assert direction("ENE").value() == 67.5
31 assert direction("E").value() == 90.0
32 assert direction("ESE").value() == 112.5
33 assert direction("SE").value() == 135.0
34 assert direction("SSE").value() == 157.5
35 assert direction("S").value() == 180.0
36 assert direction("SSW").value() == 202.5
37 assert direction("SW").value() == 225.0
38 assert direction("WSW").value() == 247.5
39 assert direction("W").value() == 270.0
40 assert direction("WNW").value() == 292.5
41 assert direction("NW").value() == 315.0
42 assert direction("NNW").value() == 337.5
43
44 assert direction("0").compass() == "N"
45 assert direction("5").compass() == "N"
46 assert direction("355").compass() == "N"
47 assert direction("20").compass() == "NNE"
48 assert direction("60").compass() == "ENE"
49 assert direction("247.5").compass() == "WSW"