frindlymap/test/circles_test.dart

46 lines
1.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:friendly_map/modules/circles/circles.dart';
void main() {
test('가까움: 통화는 대화의 3배, 같은 점수는 id 순', () {
final r = rankByCloseness(const [Closeness('a', messages: 5), Closeness('b', calls: 2), Closeness('c', messages: 6), Closeness('d')]);
expect(r.map((c) => c.id), ['b', 'c', 'a', 'd']);
expect(const Closeness('b', calls: 2).score, 6);
});
test('고리 나누기: 6명, 12명, 18명 …', () {
final g = rings(List.generate(20, (i) => i));
expect(g.map((x) => x.length), [6, 12, 2]);
expect(rings(<int>[]), isEmpty);
});
test('선배·동기·후배와 연도 읽기', () {
expect(cohortLabel(yearsApart(2006, 2004)), '2년 선배');
expect(cohortLabel(yearsApart(2006, 2006)), '동기');
expect(cohortLabel(yearsApart(2006, 2007)), '1년 후배');
expect(cohortLabel(yearsApart(null, 2007)), '연도 모름');
expect(parseYear('2009년 입학'), 2009);
expect(parseYear('09학번'), 2009);
expect(parseYear('98학번'), 1998);
expect(parseYear('27회'), isNull);
expect([3, null, -2, 0].map(cohortOrder).toList()..sort(), [-2, 0, 3, 1 << 20]);
});
test('직급: 글자에서 찾고 윗사람·아래 직원 가르기', () {
expect(rankOf('결제팀 과장'), 4);
expect(rankOf('팀장 겸 부장'), 6);
expect(rankOf('개발자'), isNull);
expect(compareRank(4, 6), RankRelation.above);
expect(compareRank(4, 3), RankRelation.below);
expect(compareRank(4, 4), RankRelation.same);
expect(compareRank(null, 4), RankRelation.unknown);
});
test('원 위 자리: 12시부터 시계 방향', () {
final p = ringPositions(4, 10);
expect(p[0].$1, closeTo(0, 1e-9));
expect(p[0].$2, closeTo(-10, 1e-9));
expect(p[1].$1, closeTo(10, 1e-9));
});
}