wrapper.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. '''
  2. Created on May 15, 2017
  3. @author: Bart
  4. '''
  5. import unittest
  6. from MatPlotLibWrapper import MatPlotLibWrapper
  7. from plot import Plot, DataSet, DataPoint, Color, LineStyle, XAxis, YAxis
  8. class Test(unittest.TestCase):
  9. def setUp(self):
  10. unittest.TestCase.setUp(self)
  11. self.dps1 = []
  12. self.dps1.append(DataPoint(0, 1))
  13. self.dps1.append(DataPoint(0.1, 1.0))
  14. self.dps1.append(DataPoint(0.2, 1.2))
  15. self.dps1.append(DataPoint(0.3, 1.5))
  16. self.dps1.append(DataPoint(0.4, 1.6))
  17. self.dps1.append(DataPoint(0.5, 1.65))
  18. self.dps1.append(DataPoint(0.6, 1.67))
  19. self.dps2 = []
  20. self.dps2.append(DataPoint(0, 2))
  21. self.dps2.append(DataPoint(0.1, 2.1))
  22. self.dps2.append(DataPoint(0.2, 2.2))
  23. self.dps2.append(DataPoint(0.3, 2.0))
  24. self.dps2.append(DataPoint(0.4, 1.6))
  25. self.dps2.append(DataPoint(0.5, 1))
  26. self.dps2.append(DataPoint(0.6, 0))
  27. self.dps2.append(DataPoint(0.7, 0))
  28. self.dps3 = []
  29. self.dps3.append(DataPoint(0, 1.2))
  30. self.dps3.append(DataPoint(0.2, 1.1))
  31. self.dps3.append(DataPoint(0.4, 1))
  32. self.mw = MatPlotLibWrapper()
  33. def test_oneplot(self):
  34. ds1 = DataSet(self.dps1, color=Color.BLUE, linestyle=LineStyle.X, legend="t1")
  35. p1 = Plot([ds1], "test 1", x=XAxis("time", "s", 0, 1), y=YAxis("val", "kg/s**2", 0, 2), legend=True).to_json()
  36. self.mw.visualize([p1])
  37. def test_threeplots(self):
  38. ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
  39. p1 = Plot([ds1], "test 1", x=XAxis("time", "s", 0, 1), y=YAxis("val1", "kg/s**2", 0, 2), legend=True).to_json()
  40. ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
  41. p2 = Plot([ds2], "test 2", x=XAxis("time", "seconds", 0, 1), y=YAxis("val2", "kg/s**2", 0, 3), legend=True).to_json()
  42. ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
  43. p3 = Plot([ds3], "test 3", x=XAxis("time", "s", 0, 1), y=YAxis("val3", "kg/s**2", 0, 2), legend=True).to_json()
  44. self.mw.visualize([p1, p2, p3])
  45. def test_onemultiplot(self):
  46. ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
  47. ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
  48. ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
  49. 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()
  50. self.mw.visualize([p1])
  51. def test_twomultiplot(self):
  52. ds1 = DataSet(self.dps1, color=Color.RED, linestyle=LineStyle.X, legend="t1")
  53. ds2 = DataSet(self.dps2, color=Color.CYAN, linestyle=LineStyle.DASHED, legend="t2")
  54. ds3 = DataSet(self.dps3, color=Color.BLUE, linestyle=LineStyle.POINT, legend="t3")
  55. 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()
  56. ds1 = DataSet(self.dps1, color=Color.GREEN, linestyle=LineStyle.CIRCLE, legend="t1'")
  57. ds2 = DataSet(self.dps2, color=Color.BLACK, linestyle=LineStyle.DASHDOT, legend="t2'")
  58. ds3 = DataSet(self.dps3, color=Color.MAGENTA, linestyle=LineStyle.STAR, legend="t3'")
  59. 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()
  60. self.mw.visualize([p1, p2])
  61. def test_incomplete(self):
  62. ds1 = DataSet(self.dps1)
  63. p1 = Plot([ds1]).to_json()
  64. self.mw.visualize([p1])
  65. def test_multiplotincomplete(self):
  66. ds1 = DataSet(self.dps1)
  67. ds2 = DataSet(self.dps2)
  68. ds3 = DataSet(self.dps3)
  69. p1 = Plot([ds1, ds2, ds3]).to_json()
  70. self.mw.visualize([p1])
  71. if __name__ == "__main__":
  72. #import sys;sys.argv = ['', 'Test.testName']
  73. unittest.main()