optimization of the detection algorithem.
BOOK update.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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(14 + 25, 0)), 10);
|
||||
expect(TargetScoring.scoreAt(c + const Offset(14 + 25 + 0.5, 0)), 9);
|
||||
// Outside the last ring
|
||||
expect(TargetScoring.scoreAt(c + const Offset(510 + 25 + 0.5, 0)), 0);
|
||||
});
|
||||
|
||||
test('hand-entered shots stay on the 1200x1200 target', () {
|
||||
for (int deg = 0; deg < 360; deg += 15) {
|
||||
final p = TargetScoring.positionFor(0, deg * pi / 180);
|
||||
expect(p.dx, inInclusiveRange(0, 1200));
|
||||
expect(p.dy, inInclusiveRange(0, 1200));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user