Skip to content

Commit

Permalink
Fix some test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Dec 3, 2023
1 parent 882bd8f commit 711824c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class ScatterSpot extends FlSpot with EquatableMixin {
lerpDouble(a.x, b.x, t)!,
lerpDouble(a.y, b.y, t)!,
show: b.show,
dotPainter: b.dotPainter,
dotPainter: t == 0 ? a.dotPainter : b.dotPainter,
);
}

Expand Down
51 changes: 43 additions & 8 deletions test/chart/data_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,31 @@ class MockData {
radius: 4,
);

static final scatterSpot0 = ScatterSpot(0, 0, color: color0);
static final scatterSpot1 = ScatterSpot(1, 1, color: color1);
static final scatterSpot2 = ScatterSpot(2, 2, color: color2);
static final scatterSpot3 = ScatterSpot(3, 3, color: color3);
static final scatterSpot4 = ScatterSpot(4, 4, color: color4);
static final scatterSpot0 = ScatterSpot(
0,
0,
dotPainter: FlDotCirclePainter(color: color0),
);
static final scatterSpot1 = ScatterSpot(
1,
1,
dotPainter: FlDotCirclePainter(color: color1),
);
static final scatterSpot2 = ScatterSpot(
2,
2,
dotPainter: FlDotCirclePainter(color: color2),
);
static final scatterSpot3 = ScatterSpot(
3,
3,
dotPainter: FlDotCirclePainter(color: color3),
);
static final scatterSpot4 = ScatterSpot(
4,
4,
dotPainter: FlDotCirclePainter(color: color4),
);

static final scatterTouchedSpot = ScatterTouchedSpot(scatterSpot1, 0);

Expand Down Expand Up @@ -2251,9 +2271,24 @@ final ScatterChartData scatterChartData1 = ScatterChartData(
),
),
scatterSpots: [
ScatterSpot(0, 0, show: false, radius: 33, color: Colors.yellow),
ScatterSpot(2, 2, show: false, radius: 11, color: Colors.purple),
ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white),
ScatterSpot(
0,
0,
show: false,
dotPainter: FlDotCirclePainter(radius: 33, color: Colors.yellow),
),
ScatterSpot(
2,
2,
show: false,
dotPainter: FlDotCirclePainter(radius: 11, color: Colors.purple),
),
ScatterSpot(
1,
2,
show: false,
dotPainter: FlDotCirclePainter(radius: 11, color: Colors.white),
),
],
scatterTouchData: ScatterTouchData(
enabled: true,
Expand Down
44 changes: 34 additions & 10 deletions test/chart/scatter_chart/scatter_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ void main() {
0,
0,
show: false,
radius: 33,
color: Colors.yellow,
dotPainter: FlDotCirclePainter(
radius: 33,
color: Colors.yellow,
),
),
ScatterSpot(
2,
2,
show: false,
radius: 11,
color: Colors.purple,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.purple,
),
),
ScatterSpot(
1,
2,
show: false,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.white,
),
),
ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white),
],
),
true,
Expand All @@ -68,17 +80,29 @@ void main() {
2,
2,
show: false,
radius: 11,
color: Colors.purple,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.purple,
),
),
ScatterSpot(
0,
0,
show: false,
radius: 33,
color: Colors.yellow,
dotPainter: FlDotCirclePainter(
radius: 33,
color: Colors.yellow,
),
),
ScatterSpot(
1,
2,
show: false,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.white,
),
),
ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white),
],
),
false,
Expand Down
66 changes: 33 additions & 33 deletions test/chart/scatter_chart/scatter_chart_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void main() {
holder,
);

verify(mockCanvasWrapper.drawCircle(any, any, any)).called(3);
verify(mockCanvasWrapper.drawDot(any, any, any)).called(3);
Utils.changeInstance(utilsMainInstance);
});
});
Expand All @@ -71,17 +71,20 @@ void main() {
test('test 1', () {
const viewSize = Size(100, 100);

final dotPainter1 = FlDotCirclePainter(radius: 18);
final dotPainter3 = FlDotCirclePainter(radius: 4);
final dotPainter4 = FlDotCirclePainter(radius: 6);

final spot1 = ScatterSpot(1, 1, dotPainter: dotPainter1);
final spot2 = ScatterSpot(3, 9, show: false);
final spot3 = ScatterSpot(8, 2, dotPainter: dotPainter3);
final spot4 = ScatterSpot(7, 5, dotPainter: dotPainter4);
final data = ScatterChartData(
minY: 0,
maxY: 10,
minX: 0,
maxX: 10,
scatterSpots: [
ScatterSpot(1, 1, radius: 18),
ScatterSpot(3, 9, show: false),
ScatterSpot(8, 2, radius: 4),
ScatterSpot(7, 5, radius: 6),
],
scatterSpots: [spot1, spot2, spot3, spot4],
titlesData: const FlTitlesData(show: false),
clipData: const FlClipData.all(),
);
Expand All @@ -103,12 +106,9 @@ void main() {
holder,
);

verify(mockCanvasWrapper.drawCircle(const Offset(10, 90), 18, any))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(80, 80), 4, any))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(70, 50), 6, any))
.called(1);
verify(mockCanvasWrapper.drawDot(dotPainter1, spot1, const Offset(10, 90))).called(1);
verify(mockCanvasWrapper.drawDot(dotPainter3, spot3, const Offset(80, 80))).called(1);
verify(mockCanvasWrapper.drawDot(dotPainter4, spot4, const Offset(70, 50))).called(1);

verifyNever(mockCanvasWrapper.drawText(any, any));
verify(mockCanvasWrapper.clipRect(any)).called(1);
Expand Down Expand Up @@ -164,12 +164,12 @@ void main() {
minX: 0,
maxX: 10,
scatterSpots: [
ScatterSpot(1, 1, radius: 18),
ScatterSpot(2, 2, radius: 8),
ScatterSpot(1, 1, dotPainter: FlDotCirclePainter(radius: 18)),
ScatterSpot(2, 2, dotPainter: FlDotCirclePainter(radius: 8)),
ScatterSpot(3, 9, show: false),
ScatterSpot(8, 8, radius: 4),
ScatterSpot(7, 5, radius: 20),
ScatterSpot(4, 6, radius: 24),
ScatterSpot(8, 8, dotPainter: FlDotCirclePainter(radius: 4)),
ScatterSpot(7, 5, dotPainter: FlDotCirclePainter(radius: 20)),
ScatterSpot(4, 6, dotPainter: FlDotCirclePainter(radius: 24)),
],
titlesData: const FlTitlesData(show: false),
clipData: const FlClipData.all(),
Expand Down Expand Up @@ -210,15 +210,15 @@ void main() {
holder,
);

verify(mockCanvasWrapper.drawCircle(const Offset(10, 90), 18, any))
verify(mockCanvasWrapper.drawDot(any, data.scatterSpots[0], const Offset(10, 90)))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(20, 80), 8, any))
verify(mockCanvasWrapper.drawDot(any, data.scatterSpots[1], const Offset(20, 80)))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(80, 20), 4, any))
verify(mockCanvasWrapper.drawDot(any, data.scatterSpots[3], const Offset(80, 20)))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(70, 50), 20, any))
verify(mockCanvasWrapper.drawDot(any, data.scatterSpots[4], const Offset(70, 50)))
.called(1);
verify(mockCanvasWrapper.drawCircle(const Offset(40, 40), 24, any))
verify(mockCanvasWrapper.drawDot(any, data.scatterSpots[5], const Offset(40, 40)))
.called(1);

verify(mockCanvasWrapper.drawText(any, any)).called(4);
Expand All @@ -237,10 +237,10 @@ void main() {
minX: 0,
maxX: 10,
scatterSpots: [
ScatterSpot(1, 1, radius: 18),
ScatterSpot(1, 1, dotPainter: FlDotCirclePainter(radius: 18)),
ScatterSpot(3, 9, show: false),
ScatterSpot(8, 2, radius: 4),
ScatterSpot(7, 5, radius: 6),
ScatterSpot(8, 2, dotPainter: FlDotCirclePainter(radius: 4)),
ScatterSpot(7, 5, dotPainter: FlDotCirclePainter(radius: 6)),
],
showingTooltipIndicators: [0, 2, 3],
titlesData: const FlTitlesData(show: false),
Expand Down Expand Up @@ -287,10 +287,10 @@ void main() {
minX: 0,
maxX: 10,
scatterSpots: [
ScatterSpot(1, 1, radius: 18),
ScatterSpot(1, 1, dotPainter: FlDotCirclePainter(radius: 18)),
ScatterSpot(3, 9, show: false),
ScatterSpot(8, 2, radius: 4),
ScatterSpot(7, 5, radius: 6),
ScatterSpot(8, 2, dotPainter: FlDotCirclePainter(radius: 4)),
ScatterSpot(7, 5, dotPainter: FlDotCirclePainter(radius: 6)),
],
showingTooltipIndicators: [0, 2, 3],
scatterTouchData: ScatterTouchData(
Expand Down Expand Up @@ -657,7 +657,7 @@ void main() {
final spots = [
ScatterSpot(1, 1),
ScatterSpot(2, 4),
ScatterSpot(5, 2, radius: 0.5),
ScatterSpot(5, 2, dotPainter: FlDotCirclePainter(radius: 0.5)),
ScatterSpot(8, 7),
];

Expand Down Expand Up @@ -704,7 +704,7 @@ void main() {
);
expect(touchedSpot4, null);

final radius = spots[2].radius;
final radius = spots[2].size.width / 2;
final touchedSpot5 = scatterChartPainter.handleTouch(
Offset(
50 + (math.cos(math.pi / 4) * radius) - 0.01,
Expand All @@ -731,7 +731,7 @@ void main() {
final spots = [
ScatterSpot(1, 1),
ScatterSpot(2, 4),
ScatterSpot(5, 2, radius: 0.5),
ScatterSpot(5, 2, dotPainter: FlDotCirclePainter(radius: 0.5)),
ScatterSpot(8, 7),
];

Expand Down Expand Up @@ -807,7 +807,7 @@ void main() {
);
expect(touchedSpot4, null);

final radius = spots[2].radius;
final radius = spots[2].size.width / 2;
final touchedSpot5 = scatterChartPainter.handleTouch(
Offset(
50 + (math.cos(math.pi / 4) * radius) - 0.01,
Expand Down
12 changes: 10 additions & 2 deletions test/utils/lerp_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,17 @@ void main() {
MockData.scatterSpot4,
]);
expect(lerpScatterSpotList(list1, list2, 0.5), [
ScatterSpot(0.5, 0.5, color: const Color(0x08080808)),
ScatterSpot(
0.5,
0.5,
dotPainter: FlDotCirclePainter(color: const Color(0x08080808)),
),
MockData.scatterSpot1,
ScatterSpot(1.5, 1.5, color: const Color(0x19191919)),
ScatterSpot(
1.5,
1.5,
dotPainter: FlDotCirclePainter(color: const Color(0x19191919)),
),
MockData.scatterSpot4,
]);
expect(lerpScatterSpotList(list1, list2, 1), list2);
Expand Down

0 comments on commit 711824c

Please sign in to comment.