|
1 | | -package co.yml.charts.ui.bargraph |
2 | | - |
3 | | -import androidx.compose.ui.geometry.Offset |
4 | | -import co.yml.charts.axis.DataCategoryOptions |
5 | | -import co.yml.charts.common.model.Point |
6 | | -import co.yml.charts.ui.barchart.getDrawHorizontalOffset |
7 | | -import co.yml.charts.ui.barchart.getDrawOffset |
8 | | -import co.yml.charts.ui.barchart.getFullBarDetails |
9 | | -import co.yml.charts.ui.barchart.getMaxScrollDistance |
10 | | -import co.yml.charts.ui.barchart.models.BarData |
11 | | -import org.junit.Assert.assertEquals |
12 | | -import org.junit.Assert.assertTrue |
13 | | -import org.junit.Test |
14 | | - |
15 | | -class BarChartTest { |
16 | | - @Test |
17 | | - fun `Given a container with input values valid scroll offset should be returned`() { |
18 | | - // Given |
19 | | - val columnWidth = 104f |
20 | | - val xMax = 100f |
21 | | - val xMin = 0f |
22 | | - val xOffset = 200f |
23 | | - val xLeft = 10f |
24 | | - val paddingRight = 40f |
25 | | - val canvasWidth = 500f |
26 | | - |
27 | | - // When |
28 | | - val scrollDistance = getMaxScrollDistance( |
29 | | - columnWidth, |
30 | | - xMax, |
31 | | - xMin, |
32 | | - xOffset, |
33 | | - xLeft, |
34 | | - paddingRight, |
35 | | - canvasWidth |
36 | | - ) |
37 | | - |
38 | | - assertTrue(scrollDistance > 0) |
39 | | - } |
40 | | - |
41 | | - |
42 | | - @Test |
43 | | - fun `Given a total drawing width lesser than container width container should not be able to scrolled`() { |
44 | | - // Given |
45 | | - val columnWidth = 20f |
46 | | - val xMax = 20f |
47 | | - val xMin = 0f |
48 | | - val xOffset = 20f |
49 | | - val xLeft = 10f |
50 | | - val paddingRight = 40f |
51 | | - val canvasWidth = 500f |
52 | | - |
53 | | - // When |
54 | | - val scrollDistance = getMaxScrollDistance( |
55 | | - columnWidth, |
56 | | - xMax, |
57 | | - xMin, |
58 | | - xOffset, |
59 | | - xLeft, |
60 | | - paddingRight, |
61 | | - canvasWidth |
62 | | - ) |
63 | | - |
64 | | - assertEquals(scrollDistance, 0f) |
65 | | - } |
66 | | - |
67 | | - @Test |
68 | | - fun `Given a point drawOffset should be positive`() { |
69 | | - val point = Point(100f, 20f) |
70 | | - |
71 | | - val drawOffset = getDrawOffset( |
72 | | - point = point, |
73 | | - xMin = 0f, |
74 | | - xOffset = 10f, |
75 | | - xLeft = 20f, |
76 | | - scrollOffset = 50f, |
77 | | - yBottom = 1500f, |
78 | | - yOffset = 20f, |
79 | | - yMin = 0f, |
80 | | - startDrawPadding = 20f, |
81 | | - barWidth = 40f, |
82 | | - zoomScale = 1f |
83 | | - ) |
84 | | - assertTrue(drawOffset.x > 0 && drawOffset.y > 0) |
85 | | - } |
86 | | - |
87 | | - |
88 | | - @Test |
89 | | - fun `Given scroll offset,xleft,xmin are zero drawOffset should be product of xOffset and xValue`() { |
90 | | - val point = Point(1f, 20f) |
91 | | - val xOffset = 20f |
92 | | - |
93 | | - val drawOffset = getDrawOffset( |
94 | | - point = point, |
95 | | - xMin = 0f, |
96 | | - xOffset = xOffset, |
97 | | - xLeft = 0f, |
98 | | - scrollOffset = 0f, |
99 | | - yBottom = 1500f, |
100 | | - yOffset = 20f, |
101 | | - yMin = 0f, |
102 | | - startDrawPadding = 20f, |
103 | | - barWidth = 40f, |
104 | | - zoomScale = 1f |
105 | | - ) |
106 | | - |
107 | | - assertEquals(drawOffset.x, xOffset * point.x) |
108 | | - } |
109 | | - |
110 | | - @Test |
111 | | - fun `Given a point horizontal drawOffset should be positive`() { |
112 | | - val point = Point(250f, 700f) |
113 | | - |
114 | | - val drawOffset = getDrawHorizontalOffset( |
115 | | - point = point, |
116 | | - xLeft = 250f, |
117 | | - scrollOffset = 50f, |
118 | | - yBottom = 950f, |
119 | | - yOffset = 192.5f, |
120 | | - yMin = 0f, |
121 | | - yMax = 9f, |
122 | | - yStart = 150f, |
123 | | - dataCategoryOptions = DataCategoryOptions(), |
124 | | - zoomScale = 1f |
125 | | - ) |
126 | | - |
127 | | - assertTrue(drawOffset.x > 0 && drawOffset.y > 0) |
128 | | - } |
129 | | - |
130 | | - @Test |
131 | | - fun `Given scroll offset,yStart,ymin are zero drawOffset should be product of yOffset and yValue`() { |
132 | | - val point = Point(250f, 700f) |
133 | | - val yOffset = 192.5f |
134 | | - |
135 | | - val drawOffset = getDrawHorizontalOffset( |
136 | | - point = point, |
137 | | - xLeft = 250f, |
138 | | - scrollOffset = 0f, |
139 | | - yBottom = 950f, |
140 | | - yOffset = 192.5f, |
141 | | - yMin = 0f, |
142 | | - yMax = 9f, |
143 | | - yStart = 0f, |
144 | | - dataCategoryOptions = DataCategoryOptions(), |
145 | | - zoomScale = 1f |
146 | | - ) |
147 | | - |
148 | | - assertEquals(drawOffset.y, yOffset * point.y) |
149 | | - } |
150 | | - |
151 | | - @Test |
152 | | - fun `Given individual stacked bar data points return it as full bar points`() { |
153 | | - // Given |
154 | | - val totalPaddingBtwBars = 10f |
155 | | - val yOffset = 50f |
156 | | - val yBottom = 100f |
157 | | - val xPointOffSet = 100f |
158 | | - val barDetails = listOf<BarData>( |
159 | | - BarData(Point(50f, 100f)), |
160 | | - BarData(Point(50f, 200f)), |
161 | | - BarData(Point(50f, 300f)) |
162 | | - ) |
163 | | - |
164 | | - //When |
165 | | - val fullBarDetails = |
166 | | - getFullBarDetails(barDetails, totalPaddingBtwBars, yOffset, yBottom, xPointOffSet) |
167 | | - |
168 | | - //Then |
169 | | - assertEquals(fullBarDetails.first, BarData(Point(50f, 600f))) |
170 | | - } |
171 | | - |
172 | | - |
173 | | - @Test |
174 | | - fun `Given individual stacked bar data points return its full bar offset`() { |
175 | | - // Given |
176 | | - val totalPaddingBtwBars = 10f |
177 | | - val yOffset = 5f |
178 | | - val yBottom = 1200f |
179 | | - val xPointOffSet = 100f |
180 | | - val barDetails = listOf<BarData>( |
181 | | - BarData(Point(50f, 100f)), |
182 | | - BarData(Point(50f, 200f)), |
183 | | - BarData(Point(50f, 300f)) |
184 | | - ) |
185 | | - |
186 | | - //When |
187 | | - val fullBarDetails = |
188 | | - getFullBarDetails(barDetails, totalPaddingBtwBars, yOffset, yBottom, xPointOffSet) |
189 | | - |
190 | | - //Then |
191 | | - assertEquals(fullBarDetails.second, Offset(100f, -1810f)) |
192 | | - } |
193 | | -} |
| 1 | +//package co.yml.charts.ui.bargraph |
| 2 | +// |
| 3 | +//import androidx.compose.ui.geometry.Offset |
| 4 | +//import co.yml.charts.axis.DataCategoryOptions |
| 5 | +//import co.yml.charts.common.model.Point |
| 6 | +//import co.yml.charts.ui.barchart.getDrawHorizontalOffset |
| 7 | +//import co.yml.charts.ui.barchart.getDrawOffset |
| 8 | +//import co.yml.charts.ui.barchart.getFullBarDetails |
| 9 | +//import co.yml.charts.ui.barchart.getMaxScrollDistance |
| 10 | +//import co.yml.charts.ui.barchart.models.BarData |
| 11 | +//import org.junit.Assert.assertEquals |
| 12 | +//import org.junit.Assert.assertTrue |
| 13 | +//import org.junit.Test |
| 14 | +// |
| 15 | +//class BarChartTest { |
| 16 | +// @Test |
| 17 | +// fun `Given a container with input values valid scroll offset should be returned`() { |
| 18 | +// // Given |
| 19 | +// val columnWidth = 104f |
| 20 | +// val xMax = 100f |
| 21 | +// val xMin = 0f |
| 22 | +// val xOffset = 200f |
| 23 | +// val xLeft = 10f |
| 24 | +// val paddingRight = 40f |
| 25 | +// val canvasWidth = 500f |
| 26 | +// |
| 27 | +// // When |
| 28 | +// val scrollDistance = getMaxScrollDistance( |
| 29 | +// columnWidth, |
| 30 | +// xMax, |
| 31 | +// xMin, |
| 32 | +// xOffset, |
| 33 | +// xLeft, |
| 34 | +// paddingRight, |
| 35 | +// canvasWidth |
| 36 | +// ) |
| 37 | +// |
| 38 | +// assertTrue(scrollDistance > 0) |
| 39 | +// } |
| 40 | +// |
| 41 | +// |
| 42 | +// @Test |
| 43 | +// fun `Given a total drawing width lesser than container width container should not be able to scrolled`() { |
| 44 | +// // Given |
| 45 | +// val columnWidth = 20f |
| 46 | +// val xMax = 20f |
| 47 | +// val xMin = 0f |
| 48 | +// val xOffset = 20f |
| 49 | +// val xLeft = 10f |
| 50 | +// val paddingRight = 40f |
| 51 | +// val canvasWidth = 500f |
| 52 | +// |
| 53 | +// // When |
| 54 | +// val scrollDistance = getMaxScrollDistance( |
| 55 | +// columnWidth, |
| 56 | +// xMax, |
| 57 | +// xMin, |
| 58 | +// xOffset, |
| 59 | +// xLeft, |
| 60 | +// paddingRight, |
| 61 | +// canvasWidth |
| 62 | +// ) |
| 63 | +// |
| 64 | +// assertEquals(scrollDistance, 0f) |
| 65 | +// } |
| 66 | +// |
| 67 | +// @Test |
| 68 | +// fun `Given a point drawOffset should be positive`() { |
| 69 | +// val point = Point(100f, 20f) |
| 70 | +// |
| 71 | +// val drawOffset = getDrawOffset( |
| 72 | +// point = point, |
| 73 | +// xMin = 0f, |
| 74 | +// xOffset = 10f, |
| 75 | +// xLeft = 20f, |
| 76 | +// scrollOffset = 50f, |
| 77 | +// yBottom = 1500f, |
| 78 | +// yOffset = 20f, |
| 79 | +// yMin = 0f, |
| 80 | +// startDrawPadding = 20f, |
| 81 | +// barWidth = 40f, |
| 82 | +// zoomScale = 1f |
| 83 | +// ) |
| 84 | +// assertTrue(drawOffset.x > 0 && drawOffset.y > 0) |
| 85 | +// } |
| 86 | +// |
| 87 | +// |
| 88 | +// @Test |
| 89 | +// fun `Given scroll offset,xleft,xmin are zero drawOffset should be product of xOffset and xValue`() { |
| 90 | +// val point = Point(1f, 20f) |
| 91 | +// val xOffset = 20f |
| 92 | +// |
| 93 | +// val drawOffset = getDrawOffset( |
| 94 | +// point = point, |
| 95 | +// xMin = 0f, |
| 96 | +// xOffset = xOffset, |
| 97 | +// xLeft = 0f, |
| 98 | +// scrollOffset = 0f, |
| 99 | +// yBottom = 1500f, |
| 100 | +// yOffset = 20f, |
| 101 | +// yMin = 0f, |
| 102 | +// startDrawPadding = 20f, |
| 103 | +// barWidth = 40f, |
| 104 | +// zoomScale = 1f |
| 105 | +// ) |
| 106 | +// |
| 107 | +// assertEquals(drawOffset.x, xOffset * point.x) |
| 108 | +// } |
| 109 | +// |
| 110 | +// @Test |
| 111 | +// fun `Given a point horizontal drawOffset should be positive`() { |
| 112 | +// val point = Point(250f, 700f) |
| 113 | +// |
| 114 | +// val drawOffset = getDrawHorizontalOffset( |
| 115 | +// point = point, |
| 116 | +// xLeft = 250f, |
| 117 | +// scrollOffset = 50f, |
| 118 | +// yBottom = 950f, |
| 119 | +// yOffset = 192.5f, |
| 120 | +// yMin = 0f, |
| 121 | +// yMax = 9f, |
| 122 | +// yStart = 150f, |
| 123 | +// dataCategoryOptions = DataCategoryOptions(), |
| 124 | +// zoomScale = 1f |
| 125 | +// ) |
| 126 | +// |
| 127 | +// assertTrue(drawOffset.x > 0 && drawOffset.y > 0) |
| 128 | +// } |
| 129 | +// |
| 130 | +// @Test |
| 131 | +// fun `Given scroll offset,yStart,ymin are zero drawOffset should be product of yOffset and yValue`() { |
| 132 | +// val point = Point(250f, 700f) |
| 133 | +// val yOffset = 192.5f |
| 134 | +// |
| 135 | +// val drawOffset = getDrawHorizontalOffset( |
| 136 | +// point = point, |
| 137 | +// xLeft = 250f, |
| 138 | +// scrollOffset = 0f, |
| 139 | +// yBottom = 950f, |
| 140 | +// yOffset = 192.5f, |
| 141 | +// yMin = 0f, |
| 142 | +// yMax = 9f, |
| 143 | +// yStart = 0f, |
| 144 | +// dataCategoryOptions = DataCategoryOptions(), |
| 145 | +// zoomScale = 1f |
| 146 | +// ) |
| 147 | +// |
| 148 | +// assertEquals(drawOffset.y, yOffset * point.y) |
| 149 | +// } |
| 150 | +// |
| 151 | +// @Test |
| 152 | +// fun `Given individual stacked bar data points return it as full bar points`() { |
| 153 | +// // Given |
| 154 | +// val totalPaddingBtwBars = 10f |
| 155 | +// val yOffset = 50f |
| 156 | +// val yBottom = 100f |
| 157 | +// val xPointOffSet = 100f |
| 158 | +// val barDetails = listOf<BarData>( |
| 159 | +// BarData(Point(50f, 100f)), |
| 160 | +// BarData(Point(50f, 200f)), |
| 161 | +// BarData(Point(50f, 300f)) |
| 162 | +// ) |
| 163 | +// |
| 164 | +// //When |
| 165 | +// val fullBarDetails = |
| 166 | +// getFullBarDetails(barDetails, totalPaddingBtwBars, yOffset, yBottom, xPointOffSet) |
| 167 | +// |
| 168 | +// //Then |
| 169 | +// assertEquals(fullBarDetails.first, BarData(Point(50f, 600f))) |
| 170 | +// } |
| 171 | +// |
| 172 | +// |
| 173 | +// @Test |
| 174 | +// fun `Given individual stacked bar data points return its full bar offset`() { |
| 175 | +// // Given |
| 176 | +// val totalPaddingBtwBars = 10f |
| 177 | +// val yOffset = 5f |
| 178 | +// val yBottom = 1200f |
| 179 | +// val xPointOffSet = 100f |
| 180 | +// val barDetails = listOf<BarData>( |
| 181 | +// BarData(Point(50f, 100f)), |
| 182 | +// BarData(Point(50f, 200f)), |
| 183 | +// BarData(Point(50f, 300f)) |
| 184 | +// ) |
| 185 | +// |
| 186 | +// //When |
| 187 | +// val fullBarDetails = |
| 188 | +// getFullBarDetails(barDetails, totalPaddingBtwBars, yOffset, yBottom, xPointOffSet) |
| 189 | +// |
| 190 | +// //Then |
| 191 | +// assertEquals(fullBarDetails.second, Offset(100f, -1810f)) |
| 192 | +// } |
| 193 | +//} |
0 commit comments