test_victory_data.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from reflex import data
  2. # Test data.
  3. x_num = [1, 2, 3, 4, 5]
  4. x_str = ["Cats", "Dogs", "Birds", "Fish", "Reptiles"]
  5. y = [1, 2, 3, 4, 10]
  6. y1 = [5, 12, 4, 6, 1]
  7. y2 = [
  8. [1, 5, 7, 4, 10, 14],
  9. [1, 2, 3, 4, 10],
  10. [1, 2, 3, 4, 5],
  11. [1, 7, 3, 14, 10],
  12. [1, 2, 6, 4, 10],
  13. ]
  14. amount = [1, 5, 3, 14, 1]
  15. def test_line():
  16. output = data(graph="line", x=x_num, y=y)
  17. expected = [
  18. {"x": 1, "y": 1},
  19. {"x": 2, "y": 2},
  20. {"x": 3, "y": 3},
  21. {"x": 4, "y": 4},
  22. {"x": 5, "y": 10},
  23. ]
  24. assert output == expected
  25. def test_scatter():
  26. output = data(graph="scatter", x=x_num, y=y)
  27. expected = [
  28. {"x": 1, "y": 1},
  29. {"x": 2, "y": 2},
  30. {"x": 3, "y": 3},
  31. {"x": 4, "y": 4},
  32. {"x": 5, "y": 10},
  33. ]
  34. assert output == expected
  35. def test_area():
  36. output = data(graph="area", x=x_num, y=y)
  37. expected = [
  38. {"x": 1, "y": 1},
  39. {"x": 2, "y": 2},
  40. {"x": 3, "y": 3},
  41. {"x": 4, "y": 4},
  42. {"x": 5, "y": 10},
  43. ]
  44. assert output == expected
  45. def test_bar():
  46. output = data(graph="bar", x=x_str, y=y)
  47. expected = [
  48. {"x": "Cats", "y": 1},
  49. {"x": "Dogs", "y": 2},
  50. {"x": "Birds", "y": 3},
  51. {"x": "Fish", "y": 4},
  52. {"x": "Reptiles", "y": 10},
  53. ]
  54. assert output == expected
  55. def test_box_plot():
  56. output = data(graph="box_plot", x=x_num, y=y2)
  57. expected = [
  58. {"x": 1, "y": [1, 5, 7, 4, 10, 14]},
  59. {"x": 2, "y": [1, 2, 3, 4, 10]},
  60. {"x": 3, "y": [1, 2, 3, 4, 5]},
  61. {"x": 4, "y": [1, 7, 3, 14, 10]},
  62. {"x": 5, "y": [1, 2, 6, 4, 10]},
  63. ]
  64. output_specified = data(
  65. graph="box_plot", x=x_num, min_=y1, max_=y1, median=y1, q1=y1, q3=y1
  66. )
  67. expected_specified = [
  68. {"x": 1, "min": 5, "max": 5, "median": 5, "q1": 5, "q3": 5},
  69. {"x": 2, "min": 12, "max": 12, "median": 12, "q1": 12, "q3": 12},
  70. {"x": 3, "min": 4, "max": 4, "median": 4, "q1": 4, "q3": 4},
  71. {"x": 4, "min": 6, "max": 6, "median": 6, "q1": 6, "q3": 6},
  72. {"x": 5, "min": 1, "max": 1, "median": 1, "q1": 1, "q3": 1},
  73. ]
  74. assert output == expected
  75. assert output_specified == expected_specified
  76. def test_histogram():
  77. output = data(graph="histogram", x=x_num)
  78. output2 = data(graph="histogram", x=y1)
  79. expected = [{"x": 1}, {"x": 2}, {"x": 3}, {"x": 4}, {"x": 5}]
  80. expected2 = [{"x": 5}, {"x": 12}, {"x": 4}, {"x": 6}, {"x": 1}]
  81. assert output == expected
  82. assert output2 == expected2
  83. def test_pie():
  84. output = data(graph="pie", x=x_str, y=amount)
  85. expected = [
  86. {"x": "Cats", "y": 1},
  87. {"x": "Dogs", "y": 5},
  88. {"x": "Birds", "y": 3},
  89. {"x": "Fish", "y": 14},
  90. {"x": "Reptiles", "y": 1},
  91. ]
  92. output_labels = data(graph="pie", x=x_str, y=amount, label=x_str)
  93. expected_labels = [
  94. {"x": "Cats", "y": 1, "label": "Cats"},
  95. {"x": "Dogs", "y": 5, "label": "Dogs"},
  96. {"x": "Birds", "y": 3, "label": "Birds"},
  97. {"x": "Fish", "y": 14, "label": "Fish"},
  98. {"x": "Reptiles", "y": 1, "label": "Reptiles"},
  99. ]
  100. assert output == expected
  101. assert output_labels == expected_labels
  102. def test_voronoi():
  103. output = data(graph="voronoi", x=x_num, y=y)
  104. expected = [
  105. {"x": 1, "y": 1},
  106. {"x": 2, "y": 2},
  107. {"x": 3, "y": 3},
  108. {"x": 4, "y": 4},
  109. {"x": 5, "y": 10},
  110. ]
  111. assert output == expected
  112. def test_candlestick():
  113. output = data(graph="candlestick", x=x_num, open=y1, high=y1, low=y1, close=y1)
  114. expected = [
  115. {"x": 1, "open": 5, "high": 5, "low": 5, "close": 5},
  116. {"x": 2, "open": 12, "high": 12, "low": 12, "close": 12},
  117. {"x": 3, "open": 4, "high": 4, "low": 4, "close": 4},
  118. {"x": 4, "open": 6, "high": 6, "low": 6, "close": 6},
  119. {"x": 5, "open": 1, "high": 1, "low": 1, "close": 1},
  120. ]
  121. assert output == expected
  122. def test_errorbar():
  123. output = data(graph="error_bar", x=x_num, y=y1, error_y=y1, error_x=y1)
  124. expected = [
  125. {"x": 1, "y": 5, "errorY": 5, "errorX": 5},
  126. {"x": 2, "y": 12, "errorY": 12, "errorX": 12},
  127. {"x": 3, "y": 4, "errorY": 4, "errorX": 4},
  128. {"x": 4, "y": 6, "errorY": 6, "errorX": 6},
  129. {"x": 5, "y": 1, "errorY": 1, "errorX": 1},
  130. ]
  131. assert output == expected