import 'dart:math'; import 'package:flutter_test/flutter_test.dart'; import 'package:sd_kovinar/utils/target_scoring.dart'; void main() { group('TargetScoring', () { test('a hand-entered shot scores what was entered, in every direction', () { for (int score = 0; score <= 10; score++) { for (int deg = 0; deg < 360; deg += 5) { final p = TargetScoring.positionFor(score, deg * pi / 180); expect(TargetScoring.scoreAt(p), score, reason: 'score $score placed at $deg°'); } } }); test('hand-entered shots are not placed on a ring line', () { // Moving a dot by a couple of pixels (rounding, editing) must not // change its score for (int score = 0; score <= 10; score++) { final p = TargetScoring.positionFor(score, 0.7); for (final d in [const Offset(2, 0), const Offset(-2, 0), const Offset(0, 2), const Offset(0, -2)]) { expect(TargetScoring.scoreAt(p + d), score, reason: 'score $score nudged by $d'); } } }); test('ring edges count the bullet radius', () { const c = TargetScoring.center; // Bullet edge exactly on the outer edge of ring 10 expect(TargetScoring.scoreAt(c + const Offset(15 + 25, 0)), 10); expect(TargetScoring.scoreAt(c + const Offset(15 + 25 + 0.5, 0)), 9); // Touching a line counts the higher value: the edge is the line's outer edge expect(TargetScoring.scoreAt(c + const Offset(70 + 2.5 + 25, 0)), 9); // 5 px line expect(TargetScoring.scoreAt(c + const Offset(70 + 2.5 + 25 + 0.5, 0)), 8); expect(TargetScoring.scoreAt(c + const Offset(235 + 1.5 + 25, 0)), 6); // 3 px line expect(TargetScoring.scoreAt(c + const Offset(235 + 1.5 + 25 + 0.5, 0)), 5); // Outside the last ring expect(TargetScoring.scoreAt(c + const Offset(510 + 1.5 + 25, 0)), 1); expect(TargetScoring.scoreAt(c + const Offset(510 + 1.5 + 25 + 0.5, 0)), 0); }); // The dot is wholly inside the target's 1200 square bool onSquare(Offset p) { const r = TargetScoring.bulletDiameter / 2; return p.dx >= r && p.dy >= r && p.dx <= TargetScoring.size - r && p.dy <= TargetScoring.size - r; } test('a hand-entered 0 lands towards a corner, clear of ring 1', () { for (int deg = 0; deg < 360; deg += 5) { final p = TargetScoring.positionFor(0, deg * pi / 180); expect(onSquare(p), isTrue, reason: '$deg°: $p'); // Past ring 1's decoration (r 510–590), not just past the ring expect((p - TargetScoring.center).distance - TargetScoring.bulletDiameter / 2, greaterThan(590), reason: '$deg°: $p'); } }); test('a shot far off is kept in the square and still scores 0', () { for (final far in [const Offset(0, 0), const Offset(1200, 1200), const Offset(-500, 600), const Offset(600, 2000), const Offset(1190, 20)]) { final p = TargetScoring.shown(far); expect(onSquare(p), isTrue, reason: '$far -> $p'); expect(TargetScoring.scoreAt(p), 0); } const inside = Offset(700, 650); expect(TargetScoring.shown(inside), inside); // inside: unchanged }); }); }