More unittests for cardlist merging

This commit is contained in:
Jeremy Wall 2020-08-09 16:32:27 -04:00
parent c12e803cfd
commit f14ee2321d

View File

@ -3,7 +3,7 @@ import { BibleReference, Overlap } from './bible-reference';
import { CardType } from '../models/app-state';
describe('Card Merging', () => {
it('Should merge two equal cards', () => {
it('Should merge two equal reference cards', () => {
const cardList = [
{ type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' },
{ type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' },
@ -15,6 +15,58 @@ describe('Card Merging', () => {
}
});
it('Should merge two equal word cards', () => {
const cardList = [
{ type: CardType.Word, qry: 'sin', data: null, dict: '' },
{ type: CardType.Word, qry: 'sin', data: null, dict: '' },
];
for (const strat of [Overlap.Equal]) {
const merged = mergeCardList(cardList, strat);
expect(merged.length).toBe(1);
expect(merged[0].qry).toEqual('sin');
}
});
it('Should merge two equal word cards with one in the middle', () => {
const cardList = [
{ type: CardType.Word, qry: 'sin', data: null, dict: '' },
{ type: CardType.Word, qry: 'love', data: null, dict: '' },
{ type: CardType.Word, qry: 'sin', data: null, dict: '' },
];
for (const strat of [Overlap.Equal]) {
const merged = mergeCardList(cardList, strat);
expect(merged.length).toBe(2);
expect(merged[0].qry).toEqual('sin');
expect(merged[1].qry).toEqual('love');
}
});
it('Should merge two equal strongs cards', () => {
const cardList = [
{ type: CardType.Strongs, qry: 'G123', data: null, dict: '' },
{ type: CardType.Strongs, qry: 'G123', data: null, dict: '' },
];
for (const strat of [Overlap.Equal]) {
const merged = mergeCardList(cardList, strat);
expect(merged.length).toBe(1);
expect(merged[0].qry).toEqual('G123');
}
});
it('Should merge two equal strongs cards with one in the middle', () => {
const cardList = [
{ type: CardType.Strongs, qry: 'G123', data: null, dict: '' },
{ type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' },
{ type: CardType.Strongs, qry: 'G123', data: null, dict: '' },
];
for (const strat of [Overlap.Equal]) {
const merged = mergeCardList(cardList, strat);
expect(merged.length).toBe(2);
expect(merged[0].qry).toEqual('G123');
expect(merged[1].qry).toEqual(new BibleReference('Genesis 1:1').toString());
}
});
it('Should merge two equal cards with one in the middle', () => {
const cardList = [
{ type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' },
@ -54,4 +106,17 @@ describe('Card Merging', () => {
expect(merged[1].qry).toEqual(new BibleReference('Genesis 1:4').toString());
}
});
it('Should not merge two cards of different card types', () => {
const cardList = [
{ type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' },
{ type: CardType.Word, qry: 'sin', data: null, dict: '' },
];
for (const strat of [Overlap.Equal, Overlap.Subset, Overlap.Intersect, Overlap.None]) {
const merged = mergeCardList(cardList, strat);
expect(merged.length).toBe(2);
expect(merged[0].qry).toEqual(new BibleReference('Genesis 1:1').toString());
expect(merged[1].qry).toEqual('sin');
}
});
});