From f14ee2321d85a2be807b127cc12e8ce4c3efaccf Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 9 Aug 2020 16:32:27 -0400 Subject: [PATCH] More unittests for cardlist merging --- app/db/src/app/common/card-operations.spec.ts | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/app/db/src/app/common/card-operations.spec.ts b/app/db/src/app/common/card-operations.spec.ts index f05f67fc..bdcbdcb2 100644 --- a/app/db/src/app/common/card-operations.spec.ts +++ b/app/db/src/app/common/card-operations.spec.ts @@ -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'); + } + }); });