1.0.0
This commit is contained in:
152
test/utils/canvas_wrapper_test.dart
Normal file
152
test/utils/canvas_wrapper_test.dart
Normal file
@@ -0,0 +1,152 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_data.dart';
|
||||
import 'package:fl_chart/src/utils/canvas_wrapper.dart';
|
||||
import 'package:fl_chart/src/utils/utils.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../chart/data_pool.dart';
|
||||
import 'canvas_wrapper_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([Canvas, FlDotPainter, Utils])
|
||||
void main() {
|
||||
final mockCanvas = MockCanvas();
|
||||
final canvasWrapper = CanvasWrapper(mockCanvas, MockData.size1);
|
||||
|
||||
test('test drawRRect', () {
|
||||
canvasWrapper.drawRRect(MockData.rRect1, MockData.paint1);
|
||||
verify(mockCanvas.drawRRect(MockData.rRect1, MockData.paint1)).called(1);
|
||||
});
|
||||
|
||||
test('test save', () {
|
||||
canvasWrapper.save();
|
||||
verify(mockCanvas.save()).called(1);
|
||||
});
|
||||
|
||||
test('test restore', () {
|
||||
canvasWrapper.restore();
|
||||
verify(mockCanvas.restore()).called(1);
|
||||
});
|
||||
|
||||
test('test clipRect', () {
|
||||
canvasWrapper.clipRect(MockData.rect1);
|
||||
verify(mockCanvas.clipRect(MockData.rect1)).called(1);
|
||||
});
|
||||
|
||||
test('test translate', () {
|
||||
canvasWrapper.translate(11, 232);
|
||||
verify(mockCanvas.translate(11, 232)).called(1);
|
||||
});
|
||||
|
||||
test('test rotate', () {
|
||||
canvasWrapper.rotate(12);
|
||||
verify(mockCanvas.rotate(12)).called(1);
|
||||
});
|
||||
|
||||
test('test drawPath', () {
|
||||
canvasWrapper.drawPath(MockData.path1, MockData.paint1);
|
||||
verify(mockCanvas.drawPath(MockData.path1, MockData.paint1)).called(1);
|
||||
});
|
||||
|
||||
test('test saveLayer', () {
|
||||
canvasWrapper.saveLayer(MockData.rect1, MockData.paint1);
|
||||
verify(mockCanvas.saveLayer(MockData.rect1, MockData.paint1)).called(1);
|
||||
});
|
||||
|
||||
test('test drawPicture', () {
|
||||
canvasWrapper.drawPicture(MockData.picture1());
|
||||
verify(mockCanvas.drawPicture(MockData.picture1())).called(1);
|
||||
});
|
||||
|
||||
test('test clipPath', () {
|
||||
canvasWrapper.clipPath(MockData.path1);
|
||||
verify(mockCanvas.clipPath(MockData.path1)).called(1);
|
||||
});
|
||||
|
||||
test('test drawRect', () {
|
||||
canvasWrapper.drawRect(MockData.rect1, MockData.paint1);
|
||||
verify(mockCanvas.drawRect(MockData.rect1, MockData.paint1)).called(1);
|
||||
});
|
||||
|
||||
test('test drawLine', () {
|
||||
canvasWrapper.drawLine(MockData.offset1, MockData.offset2, MockData.paint1);
|
||||
verify(
|
||||
mockCanvas.drawLine(
|
||||
MockData.offset1,
|
||||
MockData.offset2,
|
||||
MockData.paint1,
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('test drawCircle', () {
|
||||
canvasWrapper.drawCircle(MockData.offset1, 12, MockData.paint1);
|
||||
verify(mockCanvas.drawCircle(MockData.offset1, 12, MockData.paint1))
|
||||
.called(1);
|
||||
});
|
||||
|
||||
test('test drawArc', () {
|
||||
canvasWrapper.drawArc(MockData.rect1, 12, 22, false, MockData.paint1);
|
||||
verify(mockCanvas.drawArc(MockData.rect1, 12, 22, false, MockData.paint1))
|
||||
.called(1);
|
||||
});
|
||||
|
||||
test('test drawDot', () {
|
||||
final painter = MockFlDotPainter();
|
||||
canvasWrapper.drawDot(painter, MockData.lineBarSpot1, MockData.offset1);
|
||||
verify(painter.draw(mockCanvas, MockData.lineBarSpot1, MockData.offset1))
|
||||
.called(1);
|
||||
});
|
||||
|
||||
test('test drawRotated', () {
|
||||
final utilsMainInstance = Utils();
|
||||
final mockUtils = MockUtils();
|
||||
when(mockUtils.radians(any)).thenAnswer((realInvocation) => 12);
|
||||
Utils.changeInstance(mockUtils);
|
||||
|
||||
var calledCallback = false;
|
||||
void callback() {
|
||||
calledCallback = true;
|
||||
}
|
||||
|
||||
canvasWrapper.drawRotated(
|
||||
size: const Size(240, 240),
|
||||
rotationOffset: MockData.offset1,
|
||||
drawOffset: MockData.offset2,
|
||||
angle: 12,
|
||||
drawCallback: callback,
|
||||
);
|
||||
verify(mockCanvas.save()).called(1);
|
||||
verify(mockCanvas.translate(123, 123)).called(1);
|
||||
verify(mockCanvas.rotate(12)).called(1);
|
||||
verify(mockCanvas.translate(-122, -122)).called(1);
|
||||
expect(calledCallback, true);
|
||||
verify(mockCanvas.restore()).called(1);
|
||||
Utils.changeInstance(utilsMainInstance);
|
||||
});
|
||||
|
||||
test('test drawText', () {
|
||||
final tp = MockData.textPainter2;
|
||||
canvasWrapper.drawText(tp, MockData.offset1);
|
||||
verify(tp.paint(mockCanvas, MockData.offset1)).called(1);
|
||||
});
|
||||
|
||||
test('test drawVerticalText', () {
|
||||
final tp = MockData.textPainter2;
|
||||
final mockUtils = MockUtils();
|
||||
when(mockUtils.radians(any)).thenAnswer((realInvocation) => 90);
|
||||
Utils.changeInstance(mockUtils);
|
||||
|
||||
canvasWrapper.drawVerticalText(tp, MockData.offset1);
|
||||
verify(mockCanvas.save()).called(1);
|
||||
verify(mockCanvas.translate(MockData.offset1.dx, MockData.offset1.dy))
|
||||
.called(1);
|
||||
verify(mockCanvas.rotate(90)).called(1);
|
||||
verify(mockCanvas.translate(-MockData.offset1.dx, -MockData.offset1.dy))
|
||||
.called(1);
|
||||
verify(tp.paint(mockCanvas, MockData.offset1)).called(1);
|
||||
verify(mockCanvas.restore()).called(1);
|
||||
});
|
||||
}
|
||||
626
test/utils/canvas_wrapper_test.mocks.dart
Normal file
626
test/utils/canvas_wrapper_test.mocks.dart
Normal file
@@ -0,0 +1,626 @@
|
||||
// Mocks generated by Mockito 5.4.5 from annotations
|
||||
// in fl_chart/test/utils/canvas_wrapper_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:typed_data' as _i5;
|
||||
import 'dart:ui' as _i2;
|
||||
|
||||
import 'package:fl_chart/fl_chart.dart' as _i3;
|
||||
import 'package:fl_chart/src/utils/utils.dart' as _i6;
|
||||
import 'package:flutter/material.dart' as _i4;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: must_be_immutable
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeRect_0 extends _i1.SmartFake implements _i2.Rect {
|
||||
_FakeRect_0(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeColor_1 extends _i1.SmartFake implements _i2.Color {
|
||||
_FakeColor_1(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeSize_2 extends _i1.SmartFake implements _i2.Size {
|
||||
_FakeSize_2(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeFlDotPainter_3 extends _i1.SmartFake implements _i3.FlDotPainter {
|
||||
_FakeFlDotPainter_3(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeOffset_4 extends _i1.SmartFake implements _i2.Offset {
|
||||
_FakeOffset_4(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeBorderSide_5 extends _i1.SmartFake implements _i4.BorderSide {
|
||||
_FakeBorderSide_5(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
class _FakeTextStyle_6 extends _i1.SmartFake implements _i4.TextStyle {
|
||||
_FakeTextStyle_6(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
/// A class which mocks [Canvas].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockCanvas extends _i1.Mock implements _i2.Canvas {
|
||||
MockCanvas() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void save() => super.noSuchMethod(
|
||||
Invocation.method(#save, []),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void saveLayer(_i2.Rect? bounds, _i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#saveLayer, [bounds, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void restore() => super.noSuchMethod(
|
||||
Invocation.method(#restore, []),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void restoreToCount(int? count) => super.noSuchMethod(
|
||||
Invocation.method(#restoreToCount, [count]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
int getSaveCount() =>
|
||||
(super.noSuchMethod(Invocation.method(#getSaveCount, []), returnValue: 0)
|
||||
as int);
|
||||
|
||||
@override
|
||||
void translate(double? dx, double? dy) => super.noSuchMethod(
|
||||
Invocation.method(#translate, [dx, dy]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void scale(double? sx, [double? sy]) => super.noSuchMethod(
|
||||
Invocation.method(#scale, [sx, sy]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void rotate(double? radians) => super.noSuchMethod(
|
||||
Invocation.method(#rotate, [radians]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void skew(double? sx, double? sy) => super.noSuchMethod(
|
||||
Invocation.method(#skew, [sx, sy]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void transform(_i5.Float64List? matrix4) => super.noSuchMethod(
|
||||
Invocation.method(#transform, [matrix4]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i5.Float64List getTransform() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getTransform, []),
|
||||
returnValue: _i5.Float64List(0),
|
||||
)
|
||||
as _i5.Float64List);
|
||||
|
||||
@override
|
||||
void clipRect(
|
||||
_i2.Rect? rect, {
|
||||
_i2.ClipOp? clipOp = _i2.ClipOp.intersect,
|
||||
bool? doAntiAlias = true,
|
||||
}) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clipRect,
|
||||
[rect],
|
||||
{#clipOp: clipOp, #doAntiAlias: doAntiAlias},
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void clipRRect(_i2.RRect? rrect, {bool? doAntiAlias = true}) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#clipRRect, [rrect], {#doAntiAlias: doAntiAlias}),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void clipPath(_i2.Path? path, {bool? doAntiAlias = true}) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#clipPath, [path], {#doAntiAlias: doAntiAlias}),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i2.Rect getLocalClipBounds() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getLocalClipBounds, []),
|
||||
returnValue: _FakeRect_0(
|
||||
this,
|
||||
Invocation.method(#getLocalClipBounds, []),
|
||||
),
|
||||
)
|
||||
as _i2.Rect);
|
||||
|
||||
@override
|
||||
_i2.Rect getDestinationClipBounds() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getDestinationClipBounds, []),
|
||||
returnValue: _FakeRect_0(
|
||||
this,
|
||||
Invocation.method(#getDestinationClipBounds, []),
|
||||
),
|
||||
)
|
||||
as _i2.Rect);
|
||||
|
||||
@override
|
||||
void drawColor(_i2.Color? color, _i2.BlendMode? blendMode) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawColor, [color, blendMode]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawLine(_i2.Offset? p1, _i2.Offset? p2, _i2.Paint? paint) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawLine, [p1, p2, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawPaint(_i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#drawPaint, [paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawRect(_i2.Rect? rect, _i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#drawRect, [rect, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawRRect(_i2.RRect? rrect, _i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#drawRRect, [rrect, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawDRRect(_i2.RRect? outer, _i2.RRect? inner, _i2.Paint? paint) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawDRRect, [outer, inner, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawOval(_i2.Rect? rect, _i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#drawOval, [rect, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawCircle(_i2.Offset? c, double? radius, _i2.Paint? paint) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawCircle, [c, radius, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawArc(
|
||||
_i2.Rect? rect,
|
||||
double? startAngle,
|
||||
double? sweepAngle,
|
||||
bool? useCenter,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawArc, [
|
||||
rect,
|
||||
startAngle,
|
||||
sweepAngle,
|
||||
useCenter,
|
||||
paint,
|
||||
]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawPath(_i2.Path? path, _i2.Paint? paint) => super.noSuchMethod(
|
||||
Invocation.method(#drawPath, [path, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawImage(_i2.Image? image, _i2.Offset? offset, _i2.Paint? paint) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawImage, [image, offset, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawImageRect(
|
||||
_i2.Image? image,
|
||||
_i2.Rect? src,
|
||||
_i2.Rect? dst,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawImageRect, [image, src, dst, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawImageNine(
|
||||
_i2.Image? image,
|
||||
_i2.Rect? center,
|
||||
_i2.Rect? dst,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawImageNine, [image, center, dst, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawPicture(_i2.Picture? picture) => super.noSuchMethod(
|
||||
Invocation.method(#drawPicture, [picture]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawParagraph(_i2.Paragraph? paragraph, _i2.Offset? offset) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#drawParagraph, [paragraph, offset]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawPoints(
|
||||
_i2.PointMode? pointMode,
|
||||
List<_i2.Offset>? points,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawPoints, [pointMode, points, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawRawPoints(
|
||||
_i2.PointMode? pointMode,
|
||||
_i5.Float32List? points,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawRawPoints, [pointMode, points, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawVertices(
|
||||
_i2.Vertices? vertices,
|
||||
_i2.BlendMode? blendMode,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawVertices, [vertices, blendMode, paint]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawAtlas(
|
||||
_i2.Image? atlas,
|
||||
List<_i2.RSTransform>? transforms,
|
||||
List<_i2.Rect>? rects,
|
||||
List<_i2.Color>? colors,
|
||||
_i2.BlendMode? blendMode,
|
||||
_i2.Rect? cullRect,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawAtlas, [
|
||||
atlas,
|
||||
transforms,
|
||||
rects,
|
||||
colors,
|
||||
blendMode,
|
||||
cullRect,
|
||||
paint,
|
||||
]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawRawAtlas(
|
||||
_i2.Image? atlas,
|
||||
_i5.Float32List? rstTransforms,
|
||||
_i5.Float32List? rects,
|
||||
_i5.Int32List? colors,
|
||||
_i2.BlendMode? blendMode,
|
||||
_i2.Rect? cullRect,
|
||||
_i2.Paint? paint,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawRawAtlas, [
|
||||
atlas,
|
||||
rstTransforms,
|
||||
rects,
|
||||
colors,
|
||||
blendMode,
|
||||
cullRect,
|
||||
paint,
|
||||
]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawShadow(
|
||||
_i2.Path? path,
|
||||
_i2.Color? color,
|
||||
double? elevation,
|
||||
bool? transparentOccluder,
|
||||
) => super.noSuchMethod(
|
||||
Invocation.method(#drawShadow, [
|
||||
path,
|
||||
color,
|
||||
elevation,
|
||||
transparentOccluder,
|
||||
]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [FlDotPainter].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockFlDotPainter extends _i1.Mock implements _i3.FlDotPainter {
|
||||
MockFlDotPainter() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.Color get mainColor =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#mainColor),
|
||||
returnValue: _FakeColor_1(this, Invocation.getter(#mainColor)),
|
||||
)
|
||||
as _i2.Color);
|
||||
|
||||
@override
|
||||
List<Object?> get props =>
|
||||
(super.noSuchMethod(Invocation.getter(#props), returnValue: <Object?>[])
|
||||
as List<Object?>);
|
||||
|
||||
@override
|
||||
void draw(_i2.Canvas? canvas, _i3.FlSpot? spot, _i2.Offset? offsetInCanvas) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#draw, [canvas, spot, offsetInCanvas]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i2.Size getSize(_i3.FlSpot? spot) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getSize, [spot]),
|
||||
returnValue: _FakeSize_2(this, Invocation.method(#getSize, [spot])),
|
||||
)
|
||||
as _i2.Size);
|
||||
|
||||
@override
|
||||
_i3.FlDotPainter lerp(_i3.FlDotPainter? a, _i3.FlDotPainter? b, double? t) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#lerp, [a, b, t]),
|
||||
returnValue: _FakeFlDotPainter_3(
|
||||
this,
|
||||
Invocation.method(#lerp, [a, b, t]),
|
||||
),
|
||||
)
|
||||
as _i3.FlDotPainter);
|
||||
|
||||
@override
|
||||
bool hitTest(
|
||||
_i3.FlSpot? spot,
|
||||
_i2.Offset? touched,
|
||||
_i2.Offset? center,
|
||||
double? extraThreshold,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#hitTest, [
|
||||
spot,
|
||||
touched,
|
||||
center,
|
||||
extraThreshold,
|
||||
]),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
}
|
||||
|
||||
/// A class which mocks [Utils].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUtils extends _i1.Mock implements _i6.Utils {
|
||||
MockUtils() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
double radians(double? degrees) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#radians, [degrees]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double degrees(double? radians) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#degrees, [radians]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double translateRotatedPosition(double? size, double? degree) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#translateRotatedPosition, [size, degree]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
_i2.Offset calculateRotationOffset(_i2.Size? size, double? degree) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#calculateRotationOffset, [size, degree]),
|
||||
returnValue: _FakeOffset_4(
|
||||
this,
|
||||
Invocation.method(#calculateRotationOffset, [size, degree]),
|
||||
),
|
||||
)
|
||||
as _i2.Offset);
|
||||
|
||||
@override
|
||||
_i4.BorderRadius? normalizeBorderRadius(
|
||||
_i4.BorderRadius? borderRadius,
|
||||
double? width,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#normalizeBorderRadius, [borderRadius, width]),
|
||||
)
|
||||
as _i4.BorderRadius?);
|
||||
|
||||
@override
|
||||
_i4.BorderSide normalizeBorderSide(
|
||||
_i4.BorderSide? borderSide,
|
||||
double? width,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#normalizeBorderSide, [borderSide, width]),
|
||||
returnValue: _FakeBorderSide_5(
|
||||
this,
|
||||
Invocation.method(#normalizeBorderSide, [borderSide, width]),
|
||||
),
|
||||
)
|
||||
as _i4.BorderSide);
|
||||
|
||||
@override
|
||||
double getEfficientInterval(
|
||||
double? axisViewSize,
|
||||
double? diffInAxis, {
|
||||
double? pixelPerInterval = 40.0,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getEfficientInterval,
|
||||
[axisViewSize, diffInAxis],
|
||||
{#pixelPerInterval: pixelPerInterval},
|
||||
),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double roundInterval(double? input) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#roundInterval, [input]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
int getFractionDigits(double? value) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getFractionDigits, [value]),
|
||||
returnValue: 0,
|
||||
)
|
||||
as int);
|
||||
|
||||
@override
|
||||
String formatNumber(double? axisMin, double? axisMax, double? axisValue) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#formatNumber, [axisMin, axisMax, axisValue]),
|
||||
returnValue: _i7.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#formatNumber, [axisMin, axisMax, axisValue]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
_i4.TextStyle getThemeAwareTextStyle(
|
||||
_i4.BuildContext? context,
|
||||
_i4.TextStyle? providedStyle,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getThemeAwareTextStyle, [
|
||||
context,
|
||||
providedStyle,
|
||||
]),
|
||||
returnValue: _FakeTextStyle_6(
|
||||
this,
|
||||
Invocation.method(#getThemeAwareTextStyle, [
|
||||
context,
|
||||
providedStyle,
|
||||
]),
|
||||
),
|
||||
)
|
||||
as _i4.TextStyle);
|
||||
|
||||
@override
|
||||
double getBestInitialIntervalValue(
|
||||
double? min,
|
||||
double? max,
|
||||
double? interval, {
|
||||
double? baseline = 0.0,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getBestInitialIntervalValue,
|
||||
[min, max, interval],
|
||||
{#baseline: baseline},
|
||||
),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double convertRadiusToSigma(double? radius) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#convertRadiusToSigma, [radius]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
}
|
||||
598
test/utils/lerp_test.dart
Normal file
598
test/utils/lerp_test.dart
Normal file
@@ -0,0 +1,598 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:fl_chart/src/utils/lerp.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
import '../matchers.dart';
|
||||
|
||||
void main() {
|
||||
const tolerance = 0.001;
|
||||
|
||||
test('test lerpList', () {
|
||||
final list1 = <double>[1, 1, 2];
|
||||
final list2 = <double>[1, 2, 3, 5];
|
||||
expect(lerpList(list1, list2, 0, lerp: lerpDouble), [1.0, 1.0, 2.0, 5.0]);
|
||||
expect(lerpList(list1, list2, 0.5, lerp: lerpDouble), [1.0, 1.5, 2.5, 5.0]);
|
||||
expect(lerpList(list1, list1, 0.5, lerp: lerpDouble), list1);
|
||||
});
|
||||
|
||||
test('test lerpColorList', () {
|
||||
const list1 = <Color>[
|
||||
MockData.color1,
|
||||
MockData.color1,
|
||||
MockData.color2,
|
||||
];
|
||||
const list2 = <Color>[
|
||||
MockData.color1,
|
||||
MockData.color2,
|
||||
MockData.color3,
|
||||
MockData.color5,
|
||||
];
|
||||
expect(lerpColorList(list1, list2, 0), [
|
||||
isSameColorAs(MockData.color1),
|
||||
isSameColorAs(MockData.color1),
|
||||
isSameColorAs(MockData.color2),
|
||||
isSameColorAs(MockData.color5),
|
||||
]);
|
||||
expect(lerpColorList(list1, list2, 1), list2);
|
||||
expect(lerpColorList(list1, list2, 0.5), [
|
||||
isSameColorAs(MockData.color1),
|
||||
isSameColorAs(const Color(0x19191919)),
|
||||
isSameColorAs(const Color(0x2a2a2a2a)),
|
||||
isSameColorAs(MockData.color5),
|
||||
]);
|
||||
});
|
||||
|
||||
test('test lerpColor', () {
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color1, 0.5),
|
||||
isSameColorAs(MockData.color1),
|
||||
);
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color1, 0),
|
||||
isSameColorAs(MockData.color1),
|
||||
);
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color1, 1),
|
||||
isSameColorAs(MockData.color1),
|
||||
);
|
||||
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color2, 0),
|
||||
isSameColorAs(MockData.color1),
|
||||
);
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color2, 0.3),
|
||||
isSameColorAs(const Color(0x16161616)),
|
||||
);
|
||||
expect(
|
||||
lerpColor(MockData.color1, MockData.color2, 1),
|
||||
isSameColorAs(MockData.color2),
|
||||
);
|
||||
});
|
||||
|
||||
test('test lerpDoubleAllowInfinity', () {
|
||||
expect(lerpDoubleAllowInfinity(12, 12, 0), 12);
|
||||
expect(lerpDoubleAllowInfinity(12, 12, 0.2), 12);
|
||||
expect(lerpDoubleAllowInfinity(12, 12, 0.5), 12);
|
||||
expect(lerpDoubleAllowInfinity(12, 12, 1), 12);
|
||||
|
||||
expect(lerpDoubleAllowInfinity(12, double.infinity, 1), double.infinity);
|
||||
expect(lerpDoubleAllowInfinity(12, double.infinity, 0), double.infinity);
|
||||
expect(lerpDoubleAllowInfinity(12, double.infinity, 0.4), double.infinity);
|
||||
|
||||
expect(lerpDoubleAllowInfinity(double.infinity, 12, 1), 12);
|
||||
expect(lerpDoubleAllowInfinity(double.infinity, 12, 0), 12);
|
||||
expect(lerpDoubleAllowInfinity(double.infinity, 12, 0.4), 12);
|
||||
|
||||
expect(lerpDoubleAllowInfinity(0, 10, 0.4), 4);
|
||||
expect(lerpDoubleAllowInfinity(0, 10, 0.2), 2);
|
||||
expect(lerpDoubleAllowInfinity(0, 10, 0.8), 8);
|
||||
});
|
||||
|
||||
test('test lerpDoubleList', () {
|
||||
const list1 = <double>[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
const list2 = <double>[
|
||||
10,
|
||||
100,
|
||||
1000,
|
||||
10000,
|
||||
];
|
||||
expect(lerpDoubleList(list1, list2, 0), const [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
10000,
|
||||
]);
|
||||
expect(lerpDoubleList(list1, list2, 0.5), [
|
||||
5,
|
||||
50,
|
||||
500,
|
||||
10000,
|
||||
]);
|
||||
expect(lerpDoubleList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpIntList', () {
|
||||
const list1 = <int>[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
const list2 = <int>[
|
||||
10,
|
||||
100,
|
||||
1000,
|
||||
10000,
|
||||
];
|
||||
expect(lerpIntList(list1, list2, 0), const [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
10000,
|
||||
]);
|
||||
expect(lerpIntList(list1, list2, 0.5), [
|
||||
5,
|
||||
50,
|
||||
500,
|
||||
10000,
|
||||
]);
|
||||
expect(lerpIntList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpInt', () {
|
||||
expect(lerpInt(0, 10, 1), 10);
|
||||
expect(lerpInt(0, 10, 0.34), 3);
|
||||
expect(lerpInt(0, 10, 0.38), 4);
|
||||
});
|
||||
|
||||
test('test lerpNonNullDouble', () {
|
||||
expect(lerpNonNullDouble(0, 10, 1), 10);
|
||||
expect(lerpNonNullDouble(0, 10, 0.34), closeTo(3.4, tolerance));
|
||||
expect(lerpNonNullDouble(0, 10, 0.38), closeTo(3.8, tolerance));
|
||||
});
|
||||
|
||||
test('test lerpFlSpotList', () {
|
||||
final list1 = [
|
||||
MockData.flSpot0,
|
||||
MockData.flSpot0,
|
||||
MockData.flSpot0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.flSpot1,
|
||||
MockData.flSpot2,
|
||||
MockData.flSpot3,
|
||||
MockData.flSpot4,
|
||||
];
|
||||
expect(lerpFlSpotList(list1, list2, 0), [
|
||||
MockData.flSpot0,
|
||||
MockData.flSpot0,
|
||||
MockData.flSpot0,
|
||||
MockData.flSpot4,
|
||||
]);
|
||||
expect(lerpFlSpotList(list1, list2, 0.5), [
|
||||
const FlSpot(0.5, 0.5),
|
||||
MockData.flSpot1,
|
||||
const FlSpot(1.5, 1.5),
|
||||
MockData.flSpot4,
|
||||
]);
|
||||
expect(lerpFlSpotList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpHorizontalLineList', () {
|
||||
final list1 = [
|
||||
MockData.horizontalLine0,
|
||||
MockData.horizontalLine0,
|
||||
MockData.horizontalLine0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.horizontalLine1,
|
||||
MockData.horizontalLine2,
|
||||
MockData.horizontalLine3,
|
||||
MockData.horizontalLine4,
|
||||
];
|
||||
expect(lerpHorizontalLineList(list1, list2, 0), [
|
||||
MockData.horizontalLine0,
|
||||
MockData.horizontalLine0,
|
||||
MockData.horizontalLine0,
|
||||
MockData.horizontalLine4,
|
||||
]);
|
||||
expect(lerpHorizontalLineList(list1, list2, 0.5), [
|
||||
matchesHorizontalLine(
|
||||
HorizontalLine(y: 0.5, color: const Color(0x08080808)),
|
||||
),
|
||||
matchesHorizontalLine(MockData.horizontalLine1),
|
||||
matchesHorizontalLine(
|
||||
HorizontalLine(y: 1.5, color: const Color(0x19191919)),
|
||||
),
|
||||
matchesHorizontalLine(MockData.horizontalLine4),
|
||||
]);
|
||||
expect(lerpHorizontalLineList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpVerticalLineList', () {
|
||||
final list1 = [
|
||||
MockData.verticalLine0,
|
||||
MockData.verticalLine0,
|
||||
MockData.verticalLine0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.verticalLine1,
|
||||
MockData.verticalLine2,
|
||||
MockData.verticalLine3,
|
||||
MockData.verticalLine4,
|
||||
];
|
||||
expect(lerpVerticalLineList(list1, list2, 0), [
|
||||
MockData.verticalLine0,
|
||||
MockData.verticalLine0,
|
||||
MockData.verticalLine0,
|
||||
MockData.verticalLine4,
|
||||
]);
|
||||
expect(lerpVerticalLineList(list1, list2, 0.5), [
|
||||
matchesVerticalLine(
|
||||
VerticalLine(x: 0.5, color: const Color(0x08080808)),
|
||||
),
|
||||
matchesVerticalLine(MockData.verticalLine1),
|
||||
matchesVerticalLine(
|
||||
VerticalLine(x: 1.5, color: const Color(0x19191919)),
|
||||
),
|
||||
matchesVerticalLine(MockData.verticalLine4),
|
||||
]);
|
||||
expect(lerpVerticalLineList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpHorizontalRangeAnnotationList', () {
|
||||
final list1 = [
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.horizontalRangeAnnotation1,
|
||||
MockData.horizontalRangeAnnotation2,
|
||||
MockData.horizontalRangeAnnotation3,
|
||||
MockData.horizontalRangeAnnotation4,
|
||||
];
|
||||
expect(lerpHorizontalRangeAnnotationList(list1, list2, 0), [
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
MockData.horizontalRangeAnnotation0,
|
||||
MockData.horizontalRangeAnnotation4,
|
||||
]);
|
||||
expect(lerpHorizontalRangeAnnotationList(list1, list2, 0.5), [
|
||||
matchesHorizontalRangeAnnotation(
|
||||
HorizontalRangeAnnotation(
|
||||
y1: 0.5,
|
||||
y2: 1.5,
|
||||
color: const Color(0x08080808),
|
||||
),
|
||||
),
|
||||
matchesHorizontalRangeAnnotation(MockData.horizontalRangeAnnotation1),
|
||||
matchesHorizontalRangeAnnotation(
|
||||
HorizontalRangeAnnotation(
|
||||
y1: 1.5,
|
||||
y2: 2.5,
|
||||
color: const Color(0x19191919),
|
||||
),
|
||||
),
|
||||
matchesHorizontalRangeAnnotation(MockData.horizontalRangeAnnotation4),
|
||||
]);
|
||||
expect(lerpHorizontalRangeAnnotationList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpVerticalRangeAnnotationList', () {
|
||||
final list1 = [
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.verticalRangeAnnotation1,
|
||||
MockData.verticalRangeAnnotation2,
|
||||
MockData.verticalRangeAnnotation3,
|
||||
MockData.verticalRangeAnnotation4,
|
||||
];
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 0), [
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation4,
|
||||
]);
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 0.5), [
|
||||
matchesVerticalRangeAnnotation(
|
||||
VerticalRangeAnnotation(
|
||||
x1: 0.5,
|
||||
x2: 1.5,
|
||||
color: const Color(0x08080808),
|
||||
),
|
||||
),
|
||||
matchesVerticalRangeAnnotation(MockData.verticalRangeAnnotation1),
|
||||
matchesVerticalRangeAnnotation(
|
||||
VerticalRangeAnnotation(
|
||||
x1: 1.5,
|
||||
x2: 2.5,
|
||||
color: const Color(0x19191919),
|
||||
),
|
||||
),
|
||||
matchesVerticalRangeAnnotation(MockData.verticalRangeAnnotation4),
|
||||
]);
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpBetweenBarsDataList', () {
|
||||
final list1 = [
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.verticalRangeAnnotation1,
|
||||
MockData.verticalRangeAnnotation2,
|
||||
MockData.verticalRangeAnnotation3,
|
||||
MockData.verticalRangeAnnotation4,
|
||||
];
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 0), [
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation0,
|
||||
MockData.verticalRangeAnnotation4,
|
||||
]);
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 0.5), [
|
||||
matchesVerticalRangeAnnotation(
|
||||
VerticalRangeAnnotation(
|
||||
x1: 0.5,
|
||||
x2: 1.5,
|
||||
color: const Color(0x08080808),
|
||||
),
|
||||
),
|
||||
matchesVerticalRangeAnnotation(MockData.verticalRangeAnnotation1),
|
||||
matchesVerticalRangeAnnotation(
|
||||
VerticalRangeAnnotation(
|
||||
x1: 1.5,
|
||||
x2: 2.5,
|
||||
color: const Color(0x19191919),
|
||||
),
|
||||
),
|
||||
matchesVerticalRangeAnnotation(MockData.verticalRangeAnnotation4),
|
||||
]);
|
||||
expect(lerpVerticalRangeAnnotationList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpRadarEntryList', () {
|
||||
final list1 = [
|
||||
MockData.radarEntry0,
|
||||
MockData.radarEntry0,
|
||||
MockData.radarEntry0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.radarEntry1,
|
||||
MockData.radarEntry2,
|
||||
MockData.radarEntry3,
|
||||
MockData.radarEntry4,
|
||||
];
|
||||
expect(lerpRadarEntryList(list1, list2, 0), [
|
||||
MockData.radarEntry0,
|
||||
MockData.radarEntry0,
|
||||
MockData.radarEntry0,
|
||||
MockData.radarEntry4,
|
||||
]);
|
||||
expect(lerpRadarEntryList(list1, list2, 0.5), [
|
||||
const RadarEntry(value: 0.5),
|
||||
MockData.radarEntry1,
|
||||
const RadarEntry(value: 1.5),
|
||||
MockData.radarEntry4,
|
||||
]);
|
||||
expect(lerpRadarEntryList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpScatterSpotList', () {
|
||||
final list1 = [
|
||||
MockData.scatterSpot0,
|
||||
MockData.scatterSpot0,
|
||||
MockData.scatterSpot0,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.scatterSpot1,
|
||||
MockData.scatterSpot2,
|
||||
MockData.scatterSpot3,
|
||||
MockData.scatterSpot4,
|
||||
];
|
||||
expect(lerpScatterSpotList(list1, list2, 0), [
|
||||
MockData.scatterSpot0,
|
||||
MockData.scatterSpot0,
|
||||
MockData.scatterSpot0,
|
||||
MockData.scatterSpot4,
|
||||
]);
|
||||
expect(lerpScatterSpotList(list1, list2, 0.5), [
|
||||
matchesScatterSpotWithCirclePainter(
|
||||
ScatterSpot(
|
||||
0.5,
|
||||
0.5,
|
||||
dotPainter: FlDotCirclePainter(color: const Color(0x08080808)),
|
||||
),
|
||||
),
|
||||
matchesScatterSpotWithCirclePainter(MockData.scatterSpot1),
|
||||
matchesScatterSpotWithCirclePainter(
|
||||
ScatterSpot(
|
||||
1.5,
|
||||
1.5,
|
||||
dotPainter: FlDotCirclePainter(color: const Color(0x19191919)),
|
||||
),
|
||||
),
|
||||
matchesScatterSpotWithCirclePainter(MockData.scatterSpot4),
|
||||
]);
|
||||
expect(lerpScatterSpotList(list1, list2, 1), list2);
|
||||
});
|
||||
|
||||
test('test lerpGradient', () {
|
||||
final colors = [
|
||||
MockData.color0,
|
||||
MockData.color1,
|
||||
MockData.color2,
|
||||
MockData.color3,
|
||||
];
|
||||
expect(
|
||||
lerpGradient(colors, [], 0),
|
||||
isSameColorAs(const Color(0x00000000)),
|
||||
);
|
||||
expect(
|
||||
lerpGradient(colors, [], 0.2),
|
||||
isSameColorAs(const Color(0x00000000)),
|
||||
);
|
||||
expect(
|
||||
lerpGradient(colors, [], 0.4),
|
||||
isSameColorAs(const Color(0x0a0a0a0a)),
|
||||
);
|
||||
expect(
|
||||
lerpGradient(colors, [], 0.6),
|
||||
isSameColorAs(const Color(0x17171717)),
|
||||
);
|
||||
expect(
|
||||
lerpGradient(colors, [], 0.8),
|
||||
isSameColorAs(const Color(0x25252525)),
|
||||
);
|
||||
expect(
|
||||
lerpGradient(colors, [], 1),
|
||||
isSameColorAs(const Color(0x33333333)),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpLineChartBarDataList uses `LineChartBarData.lerp`', () {
|
||||
final list1 = [
|
||||
MockData.lineChartBarData1,
|
||||
MockData.lineChartBarData1,
|
||||
MockData.lineChartBarData1,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.lineChartBarData2,
|
||||
MockData.lineChartBarData2,
|
||||
MockData.lineChartBarData2,
|
||||
MockData.lineChartBarData2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpLineChartBarDataList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: LineChartBarData.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpBetweenBarsDataList uses `BetweenBarsData.lerp`', () {
|
||||
final list1 = [
|
||||
betweenBarsData1,
|
||||
betweenBarsData1,
|
||||
betweenBarsData1,
|
||||
];
|
||||
final list2 = [
|
||||
betweenBarsData2,
|
||||
betweenBarsData2,
|
||||
betweenBarsData2,
|
||||
betweenBarsData2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpBetweenBarsDataList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: BetweenBarsData.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpBarChartGroupDataList uses `BarChartGroupData.lerp`', () {
|
||||
final list1 = [
|
||||
barChartGroupData1,
|
||||
barChartGroupData1,
|
||||
barChartGroupData1,
|
||||
];
|
||||
final list2 = [
|
||||
barChartGroupData2,
|
||||
barChartGroupData2,
|
||||
barChartGroupData2,
|
||||
barChartGroupData2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpBarChartGroupDataList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: BarChartGroupData.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpBarChartRodDataList uses `BarChartRodData.lerp`', () {
|
||||
final list1 = [
|
||||
barChartRodData1,
|
||||
barChartRodData1,
|
||||
barChartRodData1,
|
||||
];
|
||||
final list2 = [
|
||||
barChartRodData2,
|
||||
barChartRodData2,
|
||||
barChartRodData2,
|
||||
barChartRodData2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpBarChartRodDataList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: BarChartRodData.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpPieChartSectionDataList uses `PieChartSectionData.lerp`', () {
|
||||
final list1 = [
|
||||
MockData.pieChartSectionData1,
|
||||
MockData.pieChartSectionData1,
|
||||
MockData.pieChartSectionData1,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.pieChartSectionData2,
|
||||
MockData.pieChartSectionData2,
|
||||
MockData.pieChartSectionData2,
|
||||
MockData.pieChartSectionData2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpPieChartSectionDataList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: PieChartSectionData.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpBarChartRodStackList uses `BarChartRodStackItem.lerp`', () {
|
||||
final list1 = [
|
||||
barChartRodStackItem1,
|
||||
barChartRodStackItem1,
|
||||
barChartRodStackItem1,
|
||||
];
|
||||
final list2 = [
|
||||
barChartRodStackItem2,
|
||||
barChartRodStackItem2,
|
||||
barChartRodStackItem2,
|
||||
barChartRodStackItem2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpBarChartRodStackList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: BarChartRodStackItem.lerp),
|
||||
);
|
||||
});
|
||||
|
||||
test('lerpRadarDataSetList uses `RadarDataSet.lerp`', () {
|
||||
final list1 = [
|
||||
MockData.radarDataSet1,
|
||||
MockData.radarDataSet1,
|
||||
MockData.radarDataSet1,
|
||||
];
|
||||
final list2 = [
|
||||
MockData.radarDataSet2,
|
||||
MockData.radarDataSet2,
|
||||
MockData.radarDataSet2,
|
||||
MockData.radarDataSet2,
|
||||
];
|
||||
|
||||
expect(
|
||||
lerpRadarDataSetList(list1, list2, 1),
|
||||
lerpList(list1, list2, 1, lerp: RadarDataSet.lerp),
|
||||
);
|
||||
});
|
||||
}
|
||||
355
test/utils/utils_test.dart
Normal file
355
test/utils/utils_test.dart
Normal file
@@ -0,0 +1,355 @@
|
||||
import 'package:fl_chart/src/utils/lerp.dart';
|
||||
import 'package:fl_chart/src/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
import 'utils_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([Utils, BuildContext])
|
||||
void main() {
|
||||
const tolerance = 0.001;
|
||||
|
||||
test('changeInstance', () {
|
||||
final Utils mockUtils = MockUtils();
|
||||
final realUtils = Utils();
|
||||
expect(Utils(), realUtils);
|
||||
Utils.changeInstance(mockUtils);
|
||||
expect(Utils(), mockUtils);
|
||||
expect(Utils() != realUtils, true);
|
||||
Utils.changeInstance(realUtils);
|
||||
expect(Utils(), realUtils);
|
||||
expect(Utils() != mockUtils, true);
|
||||
});
|
||||
|
||||
test('test degrees to radians', () {
|
||||
expect(Utils().radians(57.2958), closeTo(1, tolerance));
|
||||
expect(Utils().radians(120), closeTo(2.0944, tolerance));
|
||||
expect(Utils().radians(324), closeTo(5.65487, tolerance));
|
||||
expect(Utils().radians(180), closeTo(3.1415, tolerance));
|
||||
});
|
||||
|
||||
test('test radians to degree', () {
|
||||
expect(Utils().degrees(1.5), closeTo(85.9437, tolerance));
|
||||
expect(Utils().degrees(1.8), closeTo(103.132, tolerance));
|
||||
expect(Utils().degrees(1.2), closeTo(68.7549, tolerance));
|
||||
});
|
||||
|
||||
test('translate rotated position', () {
|
||||
expect(Utils().translateRotatedPosition(100, 90), 25);
|
||||
expect(Utils().translateRotatedPosition(100, 0), 0);
|
||||
});
|
||||
|
||||
test('calculateRotationOffset()', () {
|
||||
expect(Utils().calculateRotationOffset(MockData.size1, 90), Offset.zero);
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 45).dx,
|
||||
closeTo(-2.278, tolerance),
|
||||
);
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 45).dy,
|
||||
closeTo(-2.278, tolerance),
|
||||
);
|
||||
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 180).dx,
|
||||
closeTo(0.0, tolerance),
|
||||
);
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 180).dy,
|
||||
closeTo(0.0, tolerance),
|
||||
);
|
||||
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 220).dx,
|
||||
closeTo(-2.2485, tolerance),
|
||||
);
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 220).dy,
|
||||
closeTo(-2.2485, tolerance),
|
||||
);
|
||||
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 350).dx,
|
||||
closeTo(-0.87150, tolerance),
|
||||
);
|
||||
expect(
|
||||
Utils().calculateRotationOffset(MockData.size1, 350).dy,
|
||||
closeTo(-0.87150, tolerance),
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeBorderRadius()', () {
|
||||
const input1 = BorderRadius.only(
|
||||
topLeft: Radius.circular(18),
|
||||
topRight: Radius.circular(18),
|
||||
bottomRight: Radius.circular(18),
|
||||
bottomLeft: Radius.circular(18),
|
||||
);
|
||||
const output1 = input1;
|
||||
expect(Utils().normalizeBorderRadius(input1, 40), output1);
|
||||
|
||||
const input2 = BorderRadius.only(
|
||||
topLeft: Radius.circular(24),
|
||||
topRight: Radius.circular(24),
|
||||
bottomRight: Radius.circular(24),
|
||||
bottomLeft: Radius.circular(24),
|
||||
);
|
||||
const output2 = BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
bottomRight: Radius.circular(20),
|
||||
bottomLeft: Radius.circular(20),
|
||||
);
|
||||
expect(Utils().normalizeBorderRadius(input2, 40), output2);
|
||||
});
|
||||
|
||||
test('normalizeBorderSide()', () {
|
||||
const input1 = BorderSide(width: 4);
|
||||
const output1 = input1;
|
||||
expect(Utils().normalizeBorderSide(input1, 40), output1);
|
||||
|
||||
const input2 = BorderSide(width: 24);
|
||||
const output2 = BorderSide(width: 20);
|
||||
expect(Utils().normalizeBorderSide(input2, 40), output2);
|
||||
});
|
||||
|
||||
test('lerp gradient', () {
|
||||
expect(
|
||||
lerpGradient(
|
||||
[
|
||||
Colors.red,
|
||||
Colors.green,
|
||||
],
|
||||
[],
|
||||
0,
|
||||
),
|
||||
Colors.red,
|
||||
);
|
||||
|
||||
expect(
|
||||
lerpGradient(
|
||||
[
|
||||
Colors.red,
|
||||
Colors.green,
|
||||
],
|
||||
[],
|
||||
1,
|
||||
),
|
||||
Colors.green,
|
||||
);
|
||||
});
|
||||
|
||||
test('test roundInterval', () {
|
||||
expect(Utils().roundInterval(99), 100);
|
||||
expect(Utils().roundInterval(75), 50);
|
||||
expect(Utils().roundInterval(76), 100);
|
||||
expect(Utils().roundInterval(60), 50);
|
||||
expect(Utils().roundInterval(0.000123), 0.0001);
|
||||
expect(Utils().roundInterval(0.000190), 0.0002);
|
||||
expect(Utils().roundInterval(0.000200), 0.0002);
|
||||
expect(Utils().roundInterval(0.000390000000), 0.0005);
|
||||
expect(Utils().roundInterval(0.000990000000), 0.001);
|
||||
expect(Utils().roundInterval(0.00000990000), 0.00001000);
|
||||
expect(Utils().roundInterval(0.0000009), 0.0000009);
|
||||
expect(
|
||||
Utils().roundInterval(0.000000000000000000990000000),
|
||||
0.000000000000000000990000000,
|
||||
);
|
||||
expect(Utils().roundInterval(0.000004901960784313726), 0.000005);
|
||||
});
|
||||
|
||||
test('test Utils().getEfficientInterval', () {
|
||||
expect(Utils().getEfficientInterval(472, 340, pixelPerInterval: 10), 5);
|
||||
expect(Utils().getEfficientInterval(820, 10000, pixelPerInterval: 10), 100);
|
||||
expect(
|
||||
Utils().getEfficientInterval(1024, 412345234, pixelPerInterval: 10),
|
||||
5000000,
|
||||
);
|
||||
expect(
|
||||
Utils().getEfficientInterval(720, 812394712349, pixelPerInterval: 10),
|
||||
10000000000,
|
||||
);
|
||||
expect(
|
||||
Utils().getEfficientInterval(1024, 0.01, pixelPerInterval: 100),
|
||||
0.001,
|
||||
);
|
||||
expect(
|
||||
Utils().getEfficientInterval(1024, 0.0005, pixelPerInterval: 10),
|
||||
0.000005,
|
||||
);
|
||||
expect(Utils().getEfficientInterval(200, 0.5, pixelPerInterval: 20), 0.05);
|
||||
expect(Utils().getEfficientInterval(200, 1, pixelPerInterval: 20), 0.1);
|
||||
expect(Utils().getEfficientInterval(100, 0.5, pixelPerInterval: 20), 0.1);
|
||||
expect(Utils().getEfficientInterval(10, 10), 10);
|
||||
expect(Utils().getEfficientInterval(10, 0), 1);
|
||||
});
|
||||
|
||||
test('test getFractionDigits', () {
|
||||
expect(Utils().getFractionDigits(1), 1);
|
||||
expect(Utils().getFractionDigits(343), 1);
|
||||
expect(Utils().getFractionDigits(22), 1);
|
||||
expect(Utils().getFractionDigits(444444), 1);
|
||||
expect(Utils().getFractionDigits(0.9), 2);
|
||||
expect(Utils().getFractionDigits(0.1), 2);
|
||||
expect(Utils().getFractionDigits(0.01), 3);
|
||||
expect(Utils().getFractionDigits(0.001), 4);
|
||||
expect(Utils().getFractionDigits(0.009), 4);
|
||||
expect(Utils().getFractionDigits(0.008), 4);
|
||||
expect(Utils().getFractionDigits(0.0001), 5);
|
||||
expect(Utils().getFractionDigits(0.0009), 5);
|
||||
expect(Utils().getFractionDigits(0.00001), 6);
|
||||
expect(Utils().getFractionDigits(0.000001), 7);
|
||||
expect(Utils().getFractionDigits(0.0000001), 8);
|
||||
expect(Utils().getFractionDigits(0.00000001), 9);
|
||||
});
|
||||
|
||||
test('test formatNumber', () {
|
||||
expect(Utils().formatNumber(0, 10, 0), '0');
|
||||
expect(Utils().formatNumber(0, 10, -0), '0');
|
||||
expect(Utils().formatNumber(0, 10, -0.01), '0');
|
||||
expect(Utils().formatNumber(0, 10, 0.01), '0');
|
||||
expect(Utils().formatNumber(0, 10, -0.1), '-0.1');
|
||||
expect(Utils().formatNumber(0, 10, 423), '423');
|
||||
expect(Utils().formatNumber(0, 10, -423), '-423');
|
||||
expect(Utils().formatNumber(0, 10, 1000), '1K');
|
||||
expect(Utils().formatNumber(0, 10, 1234), '1.2K');
|
||||
expect(Utils().formatNumber(0, 10, 10000), '10K');
|
||||
expect(Utils().formatNumber(0, 10, 41234), '41.2K');
|
||||
expect(Utils().formatNumber(0, 10, 82349), '82.3K');
|
||||
expect(Utils().formatNumber(0, 10, 82350), '82.3K');
|
||||
expect(Utils().formatNumber(0, 10, 82351), '82.4K');
|
||||
expect(Utils().formatNumber(0, 10, -82351), '-82.4K');
|
||||
expect(Utils().formatNumber(0, 10, 100000), '100K');
|
||||
expect(Utils().formatNumber(0, 10, 101000), '101K');
|
||||
expect(Utils().formatNumber(0, 10, 2345123), '2.3M');
|
||||
expect(Utils().formatNumber(0, 10, 2352123), '2.4M');
|
||||
expect(Utils().formatNumber(0, 10, -2352123), '-2.4M');
|
||||
expect(Utils().formatNumber(0, 10, 521000000), '521M');
|
||||
expect(Utils().formatNumber(0, 10, 4324512345), '4.3B');
|
||||
expect(Utils().formatNumber(0, 10, 4000000000), '4B');
|
||||
expect(Utils().formatNumber(0, 10, -4000000000), '-4B');
|
||||
expect(Utils().formatNumber(0, 10, 823147521343), '823.1B');
|
||||
expect(Utils().formatNumber(0, 10, 8231475213435), '8231.5B');
|
||||
expect(Utils().formatNumber(0, 10, -8231475213435), '-8231.5B');
|
||||
});
|
||||
|
||||
group('test getThemeAwareTextStyle', () {
|
||||
testWidgets('test 1', (WidgetTester tester) async {
|
||||
const style = TextStyle(color: Colors.brown);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: DefaultTextStyle(
|
||||
style: style,
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final context = tester.element(find.byType(Container));
|
||||
|
||||
expect(
|
||||
Utils().getThemeAwareTextStyle(context, style),
|
||||
style,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('test 2', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(boldText: true),
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final context = tester.element(find.byType(Container));
|
||||
|
||||
expect(
|
||||
Utils()
|
||||
.getThemeAwareTextStyle(
|
||||
context,
|
||||
MockData.textStyle1,
|
||||
)
|
||||
.fontWeight,
|
||||
FontWeight.bold,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('test getInitialIntervalValue()', () {
|
||||
expect(Utils().getBestInitialIntervalValue(-3, 3, 2), -2);
|
||||
expect(Utils().getBestInitialIntervalValue(-3, 3, 1), -3);
|
||||
expect(Utils().getBestInitialIntervalValue(-30, -20, 13), -26);
|
||||
expect(Utils().getBestInitialIntervalValue(0, 13, 8), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(1, 13, 7), 7);
|
||||
expect(Utils().getBestInitialIntervalValue(1, 13, 3), 3);
|
||||
expect(Utils().getBestInitialIntervalValue(-1, 13, 3), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(-2, 13, 3), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(-3, 13, 3), -3);
|
||||
expect(Utils().getBestInitialIntervalValue(-4, 13, 3), -3);
|
||||
expect(Utils().getBestInitialIntervalValue(-5, 13, 3), -3);
|
||||
expect(Utils().getBestInitialIntervalValue(-6, 13, 3), -6);
|
||||
expect(Utils().getBestInitialIntervalValue(-6.5, 13, 3), -6);
|
||||
expect(Utils().getBestInitialIntervalValue(-1, 1, 2), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(-1, 2, 2), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(-2, 0, 2), -2);
|
||||
expect(Utils().getBestInitialIntervalValue(-3, 0, 2), -2);
|
||||
expect(Utils().getBestInitialIntervalValue(-4, 0, 2), -4);
|
||||
expect(Utils().getBestInitialIntervalValue(-0.5, 0.5, 2), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(35, 130, 50), 50);
|
||||
expect(Utils().getBestInitialIntervalValue(49, 130, 50), 50);
|
||||
expect(Utils().getBestInitialIntervalValue(50, 130, 50), 50);
|
||||
expect(Utils().getBestInitialIntervalValue(60, 130, 50), 100);
|
||||
expect(Utils().getBestInitialIntervalValue(110, 130, 50), 110);
|
||||
expect(Utils().getBestInitialIntervalValue(90, 180, 50), 100);
|
||||
expect(Utils().getBestInitialIntervalValue(100, 180, 50), 100);
|
||||
expect(Utils().getBestInitialIntervalValue(110, 180, 50), 150);
|
||||
expect(Utils().getBestInitialIntervalValue(170, 180, 50), 170);
|
||||
expect(Utils().getBestInitialIntervalValue(-120, -10, 50), -100);
|
||||
expect(Utils().getBestInitialIntervalValue(-110, -10, 50), -100);
|
||||
expect(Utils().getBestInitialIntervalValue(-100, -10, 50), -100);
|
||||
expect(Utils().getBestInitialIntervalValue(-90, -10, 50), -50);
|
||||
expect(Utils().getBestInitialIntervalValue(-80, -10, 50), -50);
|
||||
expect(Utils().getBestInitialIntervalValue(-150, -10, 50), -150);
|
||||
expect(Utils().getBestInitialIntervalValue(-10, 10, 2, baseline: -1), -9);
|
||||
expect(Utils().getBestInitialIntervalValue(-10, 10, 2, baseline: -20), -10);
|
||||
expect(Utils().getBestInitialIntervalValue(-10, 10, 15, baseline: -30), 0);
|
||||
expect(Utils().getBestInitialIntervalValue(0, 20, 8, baseline: 28), 4);
|
||||
expect(Utils().getBestInitialIntervalValue(130, 140, 50), 130);
|
||||
expect(Utils().getBestInitialIntervalValue(145, 155, 50), 150);
|
||||
expect(
|
||||
Utils().getBestInitialIntervalValue(-200, -180, 30),
|
||||
-200,
|
||||
);
|
||||
expect(
|
||||
Utils().getBestInitialIntervalValue(-190, -170, 30),
|
||||
-180,
|
||||
);
|
||||
expect(
|
||||
Utils().getBestInitialIntervalValue(-2000, 2000, 100, baseline: -10000),
|
||||
-2000,
|
||||
);
|
||||
expect(
|
||||
Utils().getBestInitialIntervalValue(-120, 120, 33, baseline: -200),
|
||||
-101,
|
||||
);
|
||||
expect(
|
||||
Utils().getBestInitialIntervalValue(120, 180, 60, baseline: 2000),
|
||||
140,
|
||||
);
|
||||
expect(Utils().getBestInitialIntervalValue(-10, 10, 4, baseline: 3), -9);
|
||||
});
|
||||
|
||||
test('test convertRadiusToSigma()', () {
|
||||
expect(Utils().convertRadiusToSigma(10), closeTo(6.2735, tolerance));
|
||||
expect(Utils().convertRadiusToSigma(42), closeTo(24.7487, tolerance));
|
||||
expect(Utils().convertRadiusToSigma(26), closeTo(15.5111, tolerance));
|
||||
});
|
||||
}
|
||||
359
test/utils/utils_test.mocks.dart
Normal file
359
test/utils/utils_test.mocks.dart
Normal file
@@ -0,0 +1,359 @@
|
||||
// Mocks generated by Mockito 5.4.5 from annotations
|
||||
// in fl_chart/test/utils/utils_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:ui' as _i2;
|
||||
|
||||
import 'package:fl_chart/src/utils/utils.dart' as _i5;
|
||||
import 'package:flutter/foundation.dart' as _i4;
|
||||
import 'package:flutter/material.dart' as _i3;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i6;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: must_be_immutable
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeOffset_0 extends _i1.SmartFake implements _i2.Offset {
|
||||
_FakeOffset_0(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeBorderSide_1 extends _i1.SmartFake implements _i3.BorderSide {
|
||||
_FakeBorderSide_1(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
class _FakeTextStyle_2 extends _i1.SmartFake implements _i3.TextStyle {
|
||||
_FakeTextStyle_2(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
class _FakeWidget_3 extends _i1.SmartFake implements _i3.Widget {
|
||||
_FakeWidget_3(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
class _FakeInheritedWidget_4 extends _i1.SmartFake
|
||||
implements _i3.InheritedWidget {
|
||||
_FakeInheritedWidget_4(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) =>
|
||||
super.toString();
|
||||
}
|
||||
|
||||
class _FakeDiagnosticsNode_5 extends _i1.SmartFake
|
||||
implements _i3.DiagnosticsNode {
|
||||
_FakeDiagnosticsNode_5(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
|
||||
@override
|
||||
String toString({
|
||||
_i4.TextTreeConfiguration? parentConfiguration,
|
||||
_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info,
|
||||
}) => super.toString();
|
||||
}
|
||||
|
||||
/// A class which mocks [Utils].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUtils extends _i1.Mock implements _i5.Utils {
|
||||
MockUtils() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
double radians(double? degrees) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#radians, [degrees]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double degrees(double? radians) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#degrees, [radians]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double translateRotatedPosition(double? size, double? degree) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#translateRotatedPosition, [size, degree]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
_i2.Offset calculateRotationOffset(_i2.Size? size, double? degree) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#calculateRotationOffset, [size, degree]),
|
||||
returnValue: _FakeOffset_0(
|
||||
this,
|
||||
Invocation.method(#calculateRotationOffset, [size, degree]),
|
||||
),
|
||||
)
|
||||
as _i2.Offset);
|
||||
|
||||
@override
|
||||
_i3.BorderRadius? normalizeBorderRadius(
|
||||
_i3.BorderRadius? borderRadius,
|
||||
double? width,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#normalizeBorderRadius, [borderRadius, width]),
|
||||
)
|
||||
as _i3.BorderRadius?);
|
||||
|
||||
@override
|
||||
_i3.BorderSide normalizeBorderSide(
|
||||
_i3.BorderSide? borderSide,
|
||||
double? width,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#normalizeBorderSide, [borderSide, width]),
|
||||
returnValue: _FakeBorderSide_1(
|
||||
this,
|
||||
Invocation.method(#normalizeBorderSide, [borderSide, width]),
|
||||
),
|
||||
)
|
||||
as _i3.BorderSide);
|
||||
|
||||
@override
|
||||
double getEfficientInterval(
|
||||
double? axisViewSize,
|
||||
double? diffInAxis, {
|
||||
double? pixelPerInterval = 40.0,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getEfficientInterval,
|
||||
[axisViewSize, diffInAxis],
|
||||
{#pixelPerInterval: pixelPerInterval},
|
||||
),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double roundInterval(double? input) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#roundInterval, [input]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
int getFractionDigits(double? value) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getFractionDigits, [value]),
|
||||
returnValue: 0,
|
||||
)
|
||||
as int);
|
||||
|
||||
@override
|
||||
String formatNumber(double? axisMin, double? axisMax, double? axisValue) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#formatNumber, [axisMin, axisMax, axisValue]),
|
||||
returnValue: _i6.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#formatNumber, [axisMin, axisMax, axisValue]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
_i3.TextStyle getThemeAwareTextStyle(
|
||||
_i3.BuildContext? context,
|
||||
_i3.TextStyle? providedStyle,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getThemeAwareTextStyle, [
|
||||
context,
|
||||
providedStyle,
|
||||
]),
|
||||
returnValue: _FakeTextStyle_2(
|
||||
this,
|
||||
Invocation.method(#getThemeAwareTextStyle, [
|
||||
context,
|
||||
providedStyle,
|
||||
]),
|
||||
),
|
||||
)
|
||||
as _i3.TextStyle);
|
||||
|
||||
@override
|
||||
double getBestInitialIntervalValue(
|
||||
double? min,
|
||||
double? max,
|
||||
double? interval, {
|
||||
double? baseline = 0.0,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getBestInitialIntervalValue,
|
||||
[min, max, interval],
|
||||
{#baseline: baseline},
|
||||
),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
|
||||
@override
|
||||
double convertRadiusToSigma(double? radius) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#convertRadiusToSigma, [radius]),
|
||||
returnValue: 0.0,
|
||||
)
|
||||
as double);
|
||||
}
|
||||
|
||||
/// A class which mocks [BuildContext].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockBuildContext extends _i1.Mock implements _i3.BuildContext {
|
||||
MockBuildContext() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Widget get widget =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#widget),
|
||||
returnValue: _FakeWidget_3(this, Invocation.getter(#widget)),
|
||||
)
|
||||
as _i3.Widget);
|
||||
|
||||
@override
|
||||
bool get mounted =>
|
||||
(super.noSuchMethod(Invocation.getter(#mounted), returnValue: false)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
bool get debugDoingBuild =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#debugDoingBuild),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
_i3.InheritedWidget dependOnInheritedElement(
|
||||
_i3.InheritedElement? ancestor, {
|
||||
Object? aspect,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dependOnInheritedElement,
|
||||
[ancestor],
|
||||
{#aspect: aspect},
|
||||
),
|
||||
returnValue: _FakeInheritedWidget_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#dependOnInheritedElement,
|
||||
[ancestor],
|
||||
{#aspect: aspect},
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.InheritedWidget);
|
||||
|
||||
@override
|
||||
void visitAncestorElements(_i3.ConditionalElementVisitor? visitor) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#visitAncestorElements, [visitor]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void visitChildElements(_i3.ElementVisitor? visitor) => super.noSuchMethod(
|
||||
Invocation.method(#visitChildElements, [visitor]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispatchNotification(_i3.Notification? notification) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#dispatchNotification, [notification]),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i3.DiagnosticsNode describeElement(
|
||||
String? name, {
|
||||
_i4.DiagnosticsTreeStyle? style = _i4.DiagnosticsTreeStyle.errorProperty,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#describeElement, [name], {#style: style}),
|
||||
returnValue: _FakeDiagnosticsNode_5(
|
||||
this,
|
||||
Invocation.method(#describeElement, [name], {#style: style}),
|
||||
),
|
||||
)
|
||||
as _i3.DiagnosticsNode);
|
||||
|
||||
@override
|
||||
_i3.DiagnosticsNode describeWidget(
|
||||
String? name, {
|
||||
_i4.DiagnosticsTreeStyle? style = _i4.DiagnosticsTreeStyle.errorProperty,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#describeWidget, [name], {#style: style}),
|
||||
returnValue: _FakeDiagnosticsNode_5(
|
||||
this,
|
||||
Invocation.method(#describeWidget, [name], {#style: style}),
|
||||
),
|
||||
)
|
||||
as _i3.DiagnosticsNode);
|
||||
|
||||
@override
|
||||
List<_i3.DiagnosticsNode> describeMissingAncestor({
|
||||
required Type? expectedAncestorType,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#describeMissingAncestor, [], {
|
||||
#expectedAncestorType: expectedAncestorType,
|
||||
}),
|
||||
returnValue: <_i3.DiagnosticsNode>[],
|
||||
)
|
||||
as List<_i3.DiagnosticsNode>);
|
||||
|
||||
@override
|
||||
_i3.DiagnosticsNode describeOwnershipChain(String? name) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#describeOwnershipChain, [name]),
|
||||
returnValue: _FakeDiagnosticsNode_5(
|
||||
this,
|
||||
Invocation.method(#describeOwnershipChain, [name]),
|
||||
),
|
||||
)
|
||||
as _i3.DiagnosticsNode);
|
||||
}
|
||||
Reference in New Issue
Block a user