1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- '''
- Created on May 15, 2017
- @author: Bart
- '''
- import unittest
- from MatPlotLibWrapper import MatPlotLibWrapper
- from plot import Plot, DataSet, DataPoint, Color, LineStyle, XAxis, YAxis
- class Test(unittest.TestCase):
-
- def setUp(self):
- unittest.TestCase.setUp(self)
- self.dps1 = []
- self.dps1.append(DataPoint(0, 1))
- self.dps1.append(DataPoint(0.1, 1.0))
- self.dps1.append(DataPoint(0.2, 1.2))
- self.dps1.append(DataPoint(0.3, 1.5))
- self.dps1.append(DataPoint(0.4, 1.6))
- self.dps1.append(DataPoint(0.5, 1.65))
- self.dps1.append(DataPoint(0.6, 1.67))
- self.dps2 = []
- self.dps2.append(DataPoint(0, 2))
- self.dps2.append(DataPoint(0.1, 2.1))
- self.dps2.append(DataPoint(0.2, 2.2))
- self.dps2.append(DataPoint(0.3, 2.0))
- self.dps2.append(DataPoint(0.4, 1.6))
- self.dps2.append(DataPoint(0.5, 1))
- self.dps2.append(DataPoint(0.6, 0))
- self.dps2.append(DataPoint(0.7, 0))
- self.dps3 = []
- self.dps3.append(DataPoint(0, 1.2))
- self.dps3.append(DataPoint(0.2, 1.1))
- self.dps3.append(DataPoint(0.4, 1))
- self.mw = MatPlotLibWrapper()
- def test_oneplot(self):
- ds1 = DataSet(self.dps1, color=Color.BLUE, linestyle=LineStyle.X, legend="t1")
- p1 = Plot([ds1], "test 1", x=XAxis("time", "s", 0, 1), y=YAxis("val", "kg/s**2", 0, 2), legend=True).to_json()
- self.mw.visualize([p1])
-
- def test_threeplots(self):
- ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
- p1 = Plot([ds1], "test 1", x=XAxis("time", "s", 0, 1), y=YAxis("val1", "kg/s**2", 0, 2), legend=True).to_json()
- ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
- p2 = Plot([ds2], "test 2", x=XAxis("time", "seconds", 0, 1), y=YAxis("val2", "kg/s**2", 0, 3), legend=True).to_json()
- ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
- p3 = Plot([ds3], "test 3", x=XAxis("time", "s", 0, 1), y=YAxis("val3", "kg/s**2", 0, 2), legend=True).to_json()
- self.mw.visualize([p1, p2, p3])
-
- def test_onemultiplot(self):
- ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
- ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
- ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
- p1 = Plot([ds1, ds2, ds3], "test 1+2+3", x=XAxis("time", "s", 0, 1), y=YAxis("val1", "kg/s**2", 0, 2), legend=True).to_json()
- self.mw.visualize([p1])
-
- def test_twomultiplot(self):
- ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
- ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
- ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
- p1 = Plot([ds1, ds2, ds3], "test 1+2+3", x=XAxis("time", "s", 0, 1), y=YAxis("val1", "kg/s**2", 0, 2), legend=True).to_json()
- ds1 = DataSet(self.dps1, color=Color.GREEN, linestyle=LineStyle.CIRCLE, legend="t1'")
- ds2 = DataSet(self.dps2, color=Color.BLACK, linestyle=LineStyle.DASHDOT, legend="t2'")
- ds3 = DataSet(self.dps3, color=Color.MAGENTA, linestyle=LineStyle.STAR, legend="t3'")
- p2 = Plot([ds1, ds2, ds3], "test 1+2+3'", x=XAxis("time", "s", 0, 0.8), y=YAxis("val1", "kg/s**2", 0, 2), legend=True).to_json()
- self.mw.visualize([p1, p2])
-
- def test_incomplete(self):
- ds1 = DataSet(self.dps1)
- p1 = Plot([ds1]).to_json()
- self.mw.visualize([p1])
-
- def test_multiplotincomplete(self):
- ds1 = DataSet(self.dps1)
- ds2 = DataSet(self.dps2)
- ds3 = DataSet(self.dps3)
- p1 = Plot([ds1, ds2, ds3]).to_json()
- self.mw.visualize([p1])
- if __name__ == "__main__":
- #import sys;sys.argv = ['', 'Test.testName']
- unittest.main()
|