import 'package:flutter_test/flutter_test.dart'; import 'package:friendly_map/modules/keys/keys.dart'; const phrase = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'; void main() { test('5조각 중 3조각이면 단어 12개가 돌아온다 (어느 3조각이든)', () async { final codes = await RecoveryShares.split(phrase, n: 5, k: 3); expect(codes.length, 5); expect(codes.every(RecoveryShares.looksLikeShare), true); expect(await RecoveryShares.combine([codes[0], codes[2], codes[4]]), phrase); expect(await RecoveryShares.combine([codes[3], codes[1], codes[0]]), phrase); expect(await RecoveryShares.combine(codes), phrase); }); test('2조각이면 되살리지 못한다', () async { final codes = await RecoveryShares.split(phrase, n: 5, k: 3); expect(await RecoveryShares.combine([codes[0], codes[1]]), null); }); test('같은 조각을 두 번 넣어도 한 장으로 센다', () async { final codes = await RecoveryShares.split(phrase, n: 5, k: 3); expect(await RecoveryShares.combine([codes[0], codes[0], codes[1]]), null); }); test('다른 때 나눈 조각이 섞이면 되살리지 못한다', () async { final a = await RecoveryShares.split(phrase, n: 5, k: 3); final b = await RecoveryShares.split(phrase, n: 5, k: 3); expect(await RecoveryShares.combine([a[0], a[1], b[2]]), null); }); test('공백·줄바꿈이 섞여도 읽고, 엉뚱한 글자는 무시', () async { final codes = await RecoveryShares.split(phrase, n: 3, k: 2); expect(await RecoveryShares.combine([' ${codes[0]}\n', codes[2], '아무 글자', 'fmr1.깨짐']), phrase); expect(await RecoveryShares.combine(['아무 글자']), null); }); test('필요한 수가 2 미만이면 만들 수 없다', () async { expect(() => RecoveryShares.split(phrase, n: 3, k: 1), throwsArgumentError); }); }