frindlymap/test/inference_test.dart

74 lines
3.4 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:friendly_map/modules/inference/inference.dart';
CardSnapshot school(String name, String year) => CardSnapshot('school', {'school': name, 'year': year});
CardSnapshot company(String name, {bool former = false}) =>
CardSnapshot('company', {'company': name, if (former) 'former': 'true'});
void main() {
const inf = Inferer();
test('이름을 다듬어 비교 (초등학교=초, 띄어쓰기, (주))', () {
expect(Inferer.normalize('가람 초등학교'), Inferer.normalize('가람초'));
expect(Inferer.normalize('(주)한빛소프트'), Inferer.normalize('한빛소프트'));
expect(Inferer.normalize('한국대학교') == Inferer.normalize('서울대학교'), false);
});
test('같은 학교, 같은 연도면 동창', () {
final g = inf.infer(mine: [school('가람초', '2007')], theirs: [school('가람 초등학교', '2007')]);
expect(g.first.relation, '동창');
expect(g.first.confidence, 95);
});
test('같은 학교, 다른 연도면 동문, 연도를 모르면 낮은 신뢰도', () {
final a = inf.infer(mine: [school('한국대', '2008')], theirs: [school('한국대학교', '2012')]);
expect(a.single.relation, '동문');
expect(a.single.confidence, 70);
final b = inf.infer(mine: [CardSnapshot('school', {'school': '한국대'})], theirs: [school('한국대', '2012')]);
expect(b.single.confidence, 60);
});
test('같은 회사는 직장 동료, 한쪽이 퇴사했으면 전 직장 동료', () {
expect(inf.infer(mine: [company('한빛소프트')], theirs: [company('(주)한빛소프트')]).single.relation, '직장 동료');
final former = inf.infer(mine: [company('한빛', former: true)], theirs: [company('한빛')]);
expect(former.single.relation, '전 직장 동료');
});
test('같은 모임·같은 여행, 가족 명함', () {
final g = inf.infer(
mine: [CardSnapshot('group', {'group': '북한산 산악회', 'trip': '2024 제주'})],
theirs: [
CardSnapshot('group', {'group': '북한산산악회', 'trip': '2024 제주'}),
CardSnapshot('family', {'relation': '이모'}),
],
);
expect(g.map((e) => e.relation).toSet(), {'같은 모임', '같은 여행', '가족'});
expect(g.first.relation, '가족');
});
test('겹치는 게 없으면 빈 목록, 신뢰도 순서, 같은 근거는 한 번만', () {
expect(inf.infer(mine: [school('가람초', '2007')], theirs: [company('한빛')]), isEmpty);
final g = inf.infer(
mine: [school('가람초', '2007'), company('한빛')],
theirs: [school('가람초', '2007'), school('가람초', '2007'), company('한빛')],
);
expect(g.length, 2);
expect(g.first.confidence >= g.last.confidence, true);
});
test('추천: 사람마다 가장 그럴듯한 하나, 기준보다 낮으면 빠짐', () {
final r = inf.recommend(
mine: [school('가람초', '2007'), company('한빛')],
others: {
'p1': [school('가람초', '2007')],
'p2': [company('한빛')],
'p3': [CardSnapshot('school', {'school': '가람초'})].map((c) => c).toList(),
'p4': [company('다른회사')],
},
);
expect(r.map((e) => e.personId).toList(), ['p1', 'p2', 'p3']);
expect(r.first.guess.relation, '동창');
expect(inf.recommend(mine: [school('가람초', '2007')], others: {'p': [CardSnapshot('school', {'school': '가람초'})]}, minConfidence: 80), isEmpty);
});
}