first commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:sign_checker/data/catalog/bundled_sign_catalog.dart';
|
||||
import 'package:sign_checker/presentation/catalog/catalog_page.dart';
|
||||
import 'package:sign_checker/presentation/catalog/sign_detail_page.dart';
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
GoogleFonts.config.allowRuntimeFetching = false;
|
||||
});
|
||||
|
||||
testWidgets('catalog opens the sign and shows the driver action', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const CupertinoApp(home: CatalogPage()));
|
||||
await tester.enterText(find.byType(CupertinoTextField), '3.27');
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Остановка запрещена'), findsOneWidget);
|
||||
await tester.tap(find.text('Остановка запрещена'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('ЧТО ДЕЛАТЬ'), findsOneWidget);
|
||||
expect(find.textContaining('Не останавливайтесь'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('detail page warns when the sign face carries the number', (
|
||||
tester,
|
||||
) async {
|
||||
final sign = bundledSignCatalog.findByCode('3.24')!;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(home: SignDetailPage(sign: sign)),
|
||||
);
|
||||
expect(find.textContaining('цифру и схему'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sign_checker/domain/detection_stabilizer.dart';
|
||||
import 'package:sign_checker/domain/norm_rect.dart';
|
||||
|
||||
void main() {
|
||||
SignDetection hit(String label) {
|
||||
return SignDetection(
|
||||
rawLabel: label,
|
||||
confidence: 0.9,
|
||||
box: const NormRect(0.1, 0.1, 0.2, 0.2),
|
||||
);
|
||||
}
|
||||
|
||||
test('a sign is shown only after a second hit and dropped after misses', () {
|
||||
final stabilizer = DetectionStabilizer();
|
||||
expect(stabilizer.update([hit('3.27')]), isEmpty);
|
||||
final visible = stabilizer.update([hit('3.27')]);
|
||||
expect(visible, hasLength(1));
|
||||
expect(visible.single.rawLabel, '3.27');
|
||||
|
||||
expect(stabilizer.update(const []), hasLength(1));
|
||||
expect(stabilizer.update(const []), isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sign_checker/domain/letterbox.dart';
|
||||
import 'package:sign_checker/domain/rotation.dart';
|
||||
|
||||
void main() {
|
||||
test('letterbox centers a wide frame in the square', () {
|
||||
final box = Letterbox.fit(srcWidth: 200, srcHeight: 100, inputSize: 100);
|
||||
expect(box.scale, 0.5);
|
||||
expect(box.padX, 0);
|
||||
expect(box.padY, 25);
|
||||
final source = box.uprightFromModel(50, 25);
|
||||
expect(source.$1, 100);
|
||||
expect(source.$2, 0);
|
||||
});
|
||||
|
||||
test('portrait compensation rotates the back-camera buffer', () {
|
||||
expect(
|
||||
uprightClockwiseDegrees(
|
||||
sensorOrientation: 90,
|
||||
deviceDegrees: 0,
|
||||
frontCamera: false,
|
||||
),
|
||||
90,
|
||||
);
|
||||
final raw = rawPixelFromUpright(
|
||||
ux: 1,
|
||||
uy: 0,
|
||||
rawWidth: 4,
|
||||
rawHeight: 2,
|
||||
clockwiseDegrees: 90,
|
||||
);
|
||||
expect(raw, (0, 0));
|
||||
expect(uprightSize(rawWidth: 4, rawHeight: 2, clockwiseDegrees: 90), (
|
||||
2,
|
||||
4,
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sign_checker/data/catalog/bundled_sign_catalog.dart';
|
||||
import 'package:sign_checker/domain/sign_code.dart';
|
||||
|
||||
void main() {
|
||||
test('labels with a sign number resolve, free text does not', () {
|
||||
final catalog = bundledSignCatalog;
|
||||
expect(catalog.findByLabel('3_27')?.name, 'Остановка запрещена');
|
||||
expect(catalog.findByLabel('sign-2.5')?.code, '2.5');
|
||||
expect(catalog.findByLabel('speed_limit'), isNull);
|
||||
expect(catalog.findByLabel('3.13.35'), isNull);
|
||||
expect(catalog.findByLabel('2.3'), isNull);
|
||||
expect(normalizeSignCode('8.13'), '8.13');
|
||||
});
|
||||
|
||||
test('dataset speed variants and traffic lights resolve without guessing', () {
|
||||
final catalog = bundledSignCatalog;
|
||||
expect(catalog.findByLabel('3.24.7')?.code, '3.24');
|
||||
expect(catalog.findByLabel('3.24')?.code, '3.24');
|
||||
expect(catalog.findByLabel('redTrafficLights')?.code, 'signal.red');
|
||||
expect(catalog.findByLabel('TrafficLights')?.name, 'Светофор');
|
||||
expect(
|
||||
catalog.findByLabel('redyellowTrafficLights')?.action,
|
||||
contains('зелёный'),
|
||||
);
|
||||
});
|
||||
|
||||
test('critical signs keep the distinctions drivers mix up', () {
|
||||
final catalog = bundledSignCatalog;
|
||||
final stop = catalog.findByCode('3.27')!;
|
||||
expect(stop.summary, contains('остановка'));
|
||||
expect(stop.summary, contains('стоянка'));
|
||||
|
||||
final parking = catalog.findByCode('3.28')!;
|
||||
expect(parking.summary, contains('не запрещена'));
|
||||
|
||||
final halt = catalog.findByCode('2.5')!;
|
||||
expect(halt.action, contains('Остановитесь'));
|
||||
|
||||
final yieldSign = catalog.findByCode('2.4')!;
|
||||
expect(yieldSign.action, contains('уступите'));
|
||||
|
||||
final speed = catalog.findByCode('3.24')!;
|
||||
expect(speed.requiresReadingTheSign, isTrue);
|
||||
expect(speed.action, contains('цифру'));
|
||||
});
|
||||
|
||||
test('every code is unique and sortable', () {
|
||||
final codes = bundledSignCatalog.signs.map((sign) => sign.code).toList();
|
||||
expect(codes.toSet(), hasLength(codes.length));
|
||||
expect(codes.first, '1.1');
|
||||
expect(codes.indexOf('1.4.2'), lessThan(codes.indexOf('1.20.1')));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sign_checker/domain/yolo_decoder.dart';
|
||||
|
||||
void main() {
|
||||
const decoder = YoloDecoder();
|
||||
|
||||
test('raw head keeps the stronger box and suppresses the overlap', () {
|
||||
const channels = 6;
|
||||
const anchors = 8;
|
||||
final data = Float32List(channels * anchors);
|
||||
void set(int channel, int anchor, double value) {
|
||||
data[channel * anchors + anchor] = value;
|
||||
}
|
||||
|
||||
set(0, 3, 100);
|
||||
set(1, 3, 80);
|
||||
set(2, 3, 40);
|
||||
set(3, 3, 20);
|
||||
set(4, 3, 0.05);
|
||||
set(5, 3, 0.91);
|
||||
|
||||
set(0, 4, 104);
|
||||
set(1, 4, 82);
|
||||
set(2, 4, 40);
|
||||
set(3, 4, 20);
|
||||
set(4, 4, 0.02);
|
||||
set(5, 4, 0.62);
|
||||
|
||||
final boxes = decoder.decode(
|
||||
data: data,
|
||||
shape: const [1, channels, anchors],
|
||||
inputSize: 320,
|
||||
confidenceThreshold: 0.4,
|
||||
iouThreshold: 0.45,
|
||||
);
|
||||
|
||||
expect(boxes, hasLength(1));
|
||||
expect(boxes.single.classIndex, 1);
|
||||
expect(boxes.single.score, closeTo(0.91, 1e-6));
|
||||
expect(boxes.single.left, closeTo(80, 1e-6));
|
||||
expect(boxes.single.top, closeTo(70, 1e-6));
|
||||
expect(boxes.single.right, closeTo(120, 1e-6));
|
||||
expect(boxes.single.bottom, closeTo(90, 1e-6));
|
||||
});
|
||||
|
||||
test('nms head reads xyxy, score and class', () {
|
||||
final data = Float32List.fromList([
|
||||
10, 12, 40, 50, 0.8, 3, //
|
||||
0, 0, 0, 0, 0.1, 0,
|
||||
]);
|
||||
final boxes = decoder.decode(
|
||||
data: data,
|
||||
shape: const [1, 2, 6],
|
||||
inputSize: 320,
|
||||
confidenceThreshold: 0.4,
|
||||
iouThreshold: 0.45,
|
||||
);
|
||||
expect(boxes, hasLength(1));
|
||||
expect(boxes.single.classIndex, 3);
|
||||
expect(boxes.single.left, 10);
|
||||
expect(boxes.single.bottom, 50);
|
||||
});
|
||||
|
||||
test('normalized coordinates are scaled into the input square', () {
|
||||
const channels = 6;
|
||||
const anchors = 8;
|
||||
final data = Float32List(channels * anchors);
|
||||
data[0 * anchors + 1] = 0.5;
|
||||
data[1 * anchors + 1] = 0.5;
|
||||
data[2 * anchors + 1] = 0.25;
|
||||
data[3 * anchors + 1] = 0.25;
|
||||
data[5 * anchors + 1] = 0.95;
|
||||
|
||||
final boxes = decoder.decode(
|
||||
data: data,
|
||||
shape: const [1, channels, anchors],
|
||||
inputSize: 320,
|
||||
confidenceThreshold: 0.4,
|
||||
iouThreshold: 0.45,
|
||||
);
|
||||
expect(boxes.single.left, closeTo(120, 1e-6));
|
||||
expect(boxes.single.width, closeTo(80, 1e-6));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sign_checker/data/frame/yuv_sampler.dart';
|
||||
|
||||
void main() {
|
||||
test('neutral chroma and full luma become white, padding stays gray', () {
|
||||
final frame = YuvFrame(
|
||||
width: 2,
|
||||
height: 1,
|
||||
y: Uint8List.fromList([255, 255]),
|
||||
u: Uint8List.fromList([128]),
|
||||
v: Uint8List.fromList([128]),
|
||||
yRowStride: 2,
|
||||
yPixelStride: 1,
|
||||
uvRowStride: 1,
|
||||
uvPixelStride: 1,
|
||||
);
|
||||
final tensor = YuvSampler().sample(
|
||||
frame: frame,
|
||||
clockwiseDegrees: 0,
|
||||
inputSize: 4,
|
||||
);
|
||||
expect(tensor[0], closeTo(114 / 255, 0.02));
|
||||
final mid = (1 * 4 + 1) * 3;
|
||||
expect(tensor[mid], greaterThan(0.9));
|
||||
expect(tensor[mid + 1], greaterThan(0.9));
|
||||
expect(tensor[mid + 2], greaterThan(0.9));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user