From 8fad06546019f2da8285585ca938c33284d2b07b Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Fri, 25 Mar 2022 09:31:41 +0100 Subject: [PATCH] test: added removed ellipse tests --- .../components/shapes/ellipse_shape_test.dart | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart b/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart index ff525c1d..53960b36 100644 --- a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart +++ b/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart @@ -28,5 +28,91 @@ void main() { } }); }); + + group('copyWith', () { + test('returns same shape when no properties are passed', () { + final ellipseShape = EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + ); + final ellipseShapeCopied = ellipseShape.copyWith(); + + for (var index = 0; index < ellipseShape.vertices.length; index++) { + expect( + ellipseShape.vertices[index], + equals(ellipseShapeCopied.vertices[index]), + ); + } + }); + + test('returns object with updated center when center is passed', () { + final ellipseShapeExpected = EllipseShape( + center: Vector2.all(10), + majorRadius: 10, + minorRadius: 8, + ); + final ellipseShapeCopied = EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + ).copyWith(center: Vector2.all(10)); + + for (var index = 0; + index < ellipseShapeCopied.vertices.length; + index++) { + expect( + ellipseShapeCopied.vertices[index], + equals(ellipseShapeExpected.vertices[index]), + ); + } + }); + + test('returns object with updated majorRadius when majorRadius is passed', + () { + final ellipseShapeExpected = EllipseShape( + center: Vector2.zero(), + majorRadius: 12, + minorRadius: 8, + ); + final ellipseShapeCopied = EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + ).copyWith(majorRadius: 12); + + for (var index = 0; + index < ellipseShapeCopied.vertices.length; + index++) { + expect( + ellipseShapeCopied.vertices[index], + equals(ellipseShapeExpected.vertices[index]), + ); + } + }); + + test('returns object with updated minorRadius when minorRadius is passed', + () { + final ellipseShapeExpected = EllipseShape( + center: Vector2.zero(), + majorRadius: 12, + minorRadius: 5, + ); + final ellipseShapeCopied = EllipseShape( + center: Vector2.zero(), + majorRadius: 12, + minorRadius: 8, + ).copyWith(minorRadius: 5); + + for (var index = 0; + index < ellipseShapeCopied.vertices.length; + index++) { + expect( + ellipseShapeCopied.vertices[index], + equals(ellipseShapeExpected.vertices[index]), + ); + } + }); + }); }); }