-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add Quiver and Streamline Functions #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b1b7f6
67f8254
0b73695
e77ca80
bfbc83e
aef86ba
c28e1a3
0af88c5
9544265
f12ac2d
850a5c7
dc8092b
2c74747
da055a4
fff3a1f
3fc00ea
dc55e05
76ec94f
72a3b43
f4d0973
59e9ca0
ca33267
302f77f
6245375
70d78f6
f6d043d
427d499
573dd6e
b7a6a8a
943b762
c3c52af
136a249
50d7dd1
3addb46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| from unittest import TestCase | ||
| from plotly.graph_objs import graph_objs, Scatter, Data, Marker, Line, Trace | ||
| from plotly.exceptions import PlotlyError | ||
|
|
||
| import plotly.plotly as py | ||
| import plotly.tools as tls | ||
| import math | ||
| from nose.tools import raises | ||
|
|
||
|
|
||
| @raises(PlotlyError) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐄 you can just stick these in your test case: |
||
| def test_unequal_xy_length(): | ||
| data = tls.TraceFactory.create_quiver(x=[1, 2], y=[1], u=[1, 2], v=[1, 2]) | ||
|
|
||
|
|
||
| @raises(ValueError) | ||
| def test_wrong_scale(): | ||
| data = tls.TraceFactory.create_quiver(x=[1], y=[1], u=[1], v=[1], | ||
| scale=0) | ||
|
|
||
|
|
||
| @raises(ValueError) | ||
| def test_wrong_arrow_scale(): | ||
| data = tls.TraceFactory.create_quiver(x=[1], y=[1], u=[1], v=[1], | ||
| arrow_scale=-1) | ||
|
|
||
|
|
||
| class TestQuiver(TestCase): | ||
|
|
||
| def test_one_arrow(self): | ||
| self.assertAlmostEqual(tls.TraceFactory.create_quiver(x=[1], y=[1], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐄 This seems like more work that it's worth, but trust me : D Try and make tests as clear as possible this is one of the places that we'll look at with a lot of scrutiny for code review and this is what keeps stuff working as expected! It's trivial to you now, but this is super helpful to future debuggers (which could be you!). How about: |
||
| u=[1], v=[1], | ||
| scale=1), | ||
| {'y': [1, 2, None, 1.615486170766527, 2, | ||
| 1.820698256761928, None], 'x': [1, 2, None, | ||
| 1.820698256761928, 2, 1.615486170766527, None], | ||
| 'type': 'scatter', 'mode': 'lines'}) | ||
|
|
||
| def test_more_kwargs(self): | ||
| self.assertAlmostEqual(tls.TraceFactory.create_quiver(x=[1, 2], | ||
| y=[1, 2], | ||
| u=[math.cos(1), | ||
| math.cos(2)], | ||
| v=[math.sin(1), | ||
| math.sin(2)], | ||
| arrow_scale=.4, | ||
| angle=math.pi/6, | ||
| line=Line( | ||
| color='purple', | ||
| width=3)), | ||
| {'y': [1, 1.0841470984807897, None, 2, | ||
| 2.0909297426825684, None, | ||
| 1.044191642387781, 1.0841470984807897, | ||
| 1.0658037346225067, None, | ||
| 2.0677536925644366, 2.0909297426825684, | ||
| 2.051107819102551, None], | ||
| 'x': [1, 1.0540302305868139, None, 2, | ||
| 1.9583853163452858, None, | ||
| 1.052143029378767, 1.0540302305868139, | ||
| 1.0184841899864512, None, | ||
| 1.9909870141679737, 1.9583853163452858, | ||
| 1.9546151170949464, None], | ||
| 'line': {'color': 'purple', 'width': 3}, | ||
| 'type': 'scatter', 'mode': 'lines', }) | ||
|
|
||
|
|
||
| @raises(ValueError) | ||
| def test_wrong_arrow_scale(): | ||
| stream = tls.TraceFactory.create_streamline(x=[0, 2], y=[0, 2], | ||
| u=[[-1, -5], [-1, -5]], | ||
| v=[[1, 1], [-3, -3]], | ||
| arrow_scale=0) | ||
|
|
||
|
|
||
| @raises(ValueError) | ||
| def test_wrong_density(): | ||
| stream = tls.TraceFactory.create_streamline(x=[0, 2], y=[0, 2], | ||
| u=[[-1, -5], [-1, -5]], | ||
| v=[[1, 1], [-3, -3]], | ||
| density=-1) | ||
|
|
||
|
|
||
| @raises(PlotlyError) | ||
| def test_uneven_x(): | ||
| stream = tls.TraceFactory.create_streamline(x=[0, 2, 7, 9], y=[0, 2, 4, 6], | ||
| u=[[-1, -5], [-1, -5]], | ||
| v=[[1, 1], [-3, -3]]) | ||
|
|
||
|
|
||
| @raises(PlotlyError) | ||
| def test_uneven_y(): | ||
| stream = tls.TraceFactory.create_streamline(x=[0, 2, 4], y=[0, 2, 6], | ||
| u=[[-1, -5], [-1, -5]], | ||
| v=[[1, 1], [-3, -3]]) | ||
|
|
||
|
|
||
| class TestStreamline(TestCase): | ||
|
|
||
| def test_simple(self): | ||
| self.assertEqual((tls.TraceFactory.create_streamline(x=[0, 2], | ||
| y=[0, 2], | ||
| u=[[-1, -5], | ||
| [-1, -5]], | ||
| v=[[1, 1], | ||
| [-3, -3]], | ||
| density=2, | ||
| arrow_scale=.4, | ||
| angle=math.pi/6, | ||
| line=Line( | ||
| color='purple', | ||
| width=3))).keys(), | ||
| (['y', 'x', 'line', 'type', 'mode'])) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐅 this doesn't really test that |
||