File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99arcsin = lambda x : numpy .arcsin (x ) | rad
1010arccos = lambda x : numpy .arccos (x ) | rad
1111arctan = lambda x : numpy .arctan (x ) | rad
12- arctan2 = lambda x , y : numpy .arctan2 (x , y ) | rad
12+ arctan2 = lambda x , y : numpy .arctan2 (
13+ x .value_in (x .unit ) if isinstance (x , quantities .Quantity ) else x ,
14+ y .value_in (x .unit ) if isinstance (x , quantities .Quantity ) else y ,
15+ ) | rad
1316
1417
1518def to_rad (angle ):
Original file line number Diff line number Diff line change 1+ import pytest
2+ from amuse .support .testing import amusetest
3+
4+ from amuse .units import units
5+ from amuse .units .trigo import arctan2
6+
7+
8+ class TestsForIssue1180 (amusetest .TestCase ):
9+
10+ def test_arctan2_without_units (self ):
11+ "Test when input has no units"
12+ x = 1.0
13+ y = 2.0
14+ result = arctan2 (x , y ).value_in (units .rad )
15+ assert result == pytest .approx (0.4636476 , 1e-7 )
16+
17+ def test_arctan2_with_units (self ):
18+ "Test when input has units"
19+ x = 1.0 | units .m
20+ y = 2.0 | units .m
21+ result = arctan2 (x , y ).value_in (units .rad )
22+ assert result == pytest .approx (0.4636476 , 1e-7 )
23+
24+ def test_arctan2_with_units_and_no_units (self ):
25+ "Test when input has units and no units (should fail)"
26+ x = 1.0 | units .m
27+ y = 2.0
28+ with pytest .raises (AttributeError ):
29+ result = arctan2 (x , y ).value_in (units .rad )
30+
31+ def test_arctan2_with_different_units (self ):
32+ "Test when input has different units"
33+ x = 1.0 | units .m
34+ y = 2.0e-3 | units .km
35+ result = arctan2 (x , y ).value_in (units .rad )
36+ assert result == pytest .approx (0.4636476 , 1e-7 )
You can’t perform that action at this time.
0 commit comments