Skip to content

Commit

Permalink
Arrow turn into circle when new dest is origin square
Browse files Browse the repository at this point in the history
Fixes #44
  • Loading branch information
veloce committed Aug 2, 2024
1 parent 26c3612 commit 363d9d7
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ class Arrow implements Shape {

@override
Shape newDest(Square newDest) {
return Arrow(color: color, orig: orig, dest: newDest, scale: scale);
return newDest == orig
? Circle(color: color, orig: orig, scale: scale)
: Arrow(color: color, orig: orig, dest: newDest, scale: scale);
}

@override
Expand Down
91 changes: 91 additions & 0 deletions test/models_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,55 @@ void main() {
);
});

test('Circle.newDest', () {
const circle = Circle(
color: Color(0xFF000000),
orig: Square.a1,
);

expect(
circle.newDest(Square.a2),
const Arrow(
color: Color(0xFF000000),
orig: Square.a1,
dest: Square.a2,
),
);

expect(
circle.newDest(Square.a1),
const Circle(
color: Color(0xFF000000),
orig: Square.a1,
),
);
});

test('Arrow.newDest', () {
const arrow = Arrow(
color: Color(0xFF000000),
orig: Square.a1,
dest: Square.a2,
);

expect(
arrow.newDest(Square.a3),
const Arrow(
color: Color(0xFF000000),
orig: Square.a1,
dest: Square.a3,
),
);

expect(
arrow.newDest(Square.a1),
const Circle(
color: Color(0xFF000000),
orig: Square.a1,
),
);
});

test('copyWith', () {
const arrow = Arrow(
color: Color(0xFF000000),
Expand Down Expand Up @@ -181,4 +230,46 @@ void main() {
);
});
});

group('Annotation', () {
test('implements hashCode/==', () {
expect(
const Annotation(symbol: '!', color: Color(0xFF000000)),
const Annotation(symbol: '!', color: Color(0xFF000000)),
);

expect(
const Annotation(symbol: '!', color: Color(0xFF000000)).hashCode,
const Annotation(symbol: '!', color: Color(0xFF000000)).hashCode,
);

expect(
const Annotation(symbol: '!', color: Color(0xFF000000)),
isNot(
const Annotation(symbol: '?', color: Color(0xFF000000)),
),
);

expect(
const Annotation(symbol: '!', color: Color(0xFF000000)).hashCode,
isNot(
const Annotation(symbol: '?', color: Color(0xFF000000)).hashCode,
),
);

expect(
const Annotation(symbol: '!', color: Color(0xFF000000)),
isNot(
const Annotation(symbol: '!', color: Color(0xFF000001)),
),
);

expect(
const Annotation(symbol: '!', color: Color(0xFF000000)).hashCode,
isNot(
const Annotation(symbol: '!', color: Color(0xFF000001)).hashCode,
),
);
});
});
}

0 comments on commit 363d9d7

Please sign in to comment.