From 912d376e8e4afe93643e3c0a399a8da78fdd3302 Mon Sep 17 00:00:00 2001 From: Cool-Katt Date: Wed, 15 Jan 2025 14:52:21 +0200 Subject: [PATCH 1/4] Update anagram.test.ts --- exercises/practice/anagram/anagram.test.ts | 59 +++++++++++++++------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/exercises/practice/anagram/anagram.test.ts b/exercises/practice/anagram/anagram.test.ts index 1e7c09364..b68a8f262 100644 --- a/exercises/practice/anagram/anagram.test.ts +++ b/exercises/practice/anagram/anagram.test.ts @@ -1,33 +1,40 @@ import { describe, it, expect, xit } from '@jest/globals' import { Anagram } from './anagram.ts' +let areSetsEqual = (setA, setB) => + setA.size === setB.size && [...setA].every((val) => setB.has(val)); + describe('Anagram', () => { it('no matches', () => { const subject = new Anagram('diaper') const matches = subject.matches('hello', 'world', 'zombies', 'pants') - - expect(matches).toEqual([]) + const expected = [] + + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects two anagrams', () => { const subject = new Anagram('solemn') const matches = subject.matches('lemons', 'cherry', 'melons') + const expected = ['lemons', 'melons'] - expect(matches).toEqual(['lemons', 'melons']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('does not detect anagram subsets', () => { const subject = new Anagram('good') const matches = subject.matches('dog', 'goody') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects anagram', () => { const subject = new Anagram('listen') const matches = subject.matches('enlists', 'google', 'inlets', 'banana') + const expected = ['inlets'] - expect(matches).toEqual(['inlets']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects three anagrams', () => { @@ -40,98 +47,112 @@ describe('Anagram', () => { 'largely', 'leading' ) + const expected = ['gallery', 'regally', 'largely'] - expect(matches).toEqual(['gallery', 'regally', 'largely']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects multiple anagrams with different case', () => { const subject = new Anagram('nose') const matches = subject.matches('Eons', 'ONES') + const expected = ['Eons', 'ONES'] - expect(matches).toEqual(['Eons', 'ONES']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('does not detect non-anagrams with identical checksum', () => { const subject = new Anagram('mass') const matches = subject.matches('last') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects anagrams case-insensitively', () => { const subject = new Anagram('Orchestra') const matches = subject.matches('cashregister', 'Carthorse', 'radishes') + const expected = ['Carthorse'] - expect(matches).toEqual(['Carthorse']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects anagrams using case-insensitive subject', () => { const subject = new Anagram('Orchestra') const matches = subject.matches('cashregister', 'carthorse', 'radishes') + const expected = ['carthorse'] - expect(matches).toEqual(['carthorse']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('detects anagrams using case-insensitive possible matches', () => { const subject = new Anagram('orchestra') const matches = subject.matches('cashregister', 'Carthorse', 'radishes') + const expected = ['Carthorse'] - expect(matches).toEqual(['Carthorse']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('does not detect an anagram if the original word is repeated', () => { const subject = new Anagram('go') const matches = subject.matches('go Go GO') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('anagrams must use all letters exactly once', () => { const subject = new Anagram('tapper') const matches = subject.matches('patter') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('words are not anagrams of themselves', () => { const subject = new Anagram('BANANA') const matches = subject.matches('BANANA') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('words are not anagrams of themselves even if letter case is partially different', () => { const subject = new Anagram('BANANA') const matches = subject.matches('Banana') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('words are not anagrams of themselves even if letter case is completely different', () => { const subject = new Anagram('BANANA') const matches = subject.matches('Banana') + const expected = [] - expect(matches).toEqual([]) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('words other than themselves can be anagrams', () => { const subject = new Anagram('LISTEN') const matches = subject.matches('LISTEN', 'Silent') + const expected = ['Silent'] - expect(matches).toEqual(['Silent']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('matches() accepts string arguments', () => { const subject = new Anagram('ant') const matches = subject.matches('stand', 'tan', 'at') + const expected = ['tan'] - expect(matches).toEqual(['tan']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) xit('matches() accepts single string argument', () => { const subject = new Anagram('ant') const matches = subject.matches('tan') + const expected = ['tan'] - expect(matches).toEqual(['tan']) + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) }) From 82729baa7bb538060141d0b255bf4ddd6577ab56 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 Jan 2025 12:54:34 +0000 Subject: [PATCH 2/4] [CI] Format code --- exercises/practice/anagram/anagram.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/anagram/anagram.test.ts b/exercises/practice/anagram/anagram.test.ts index b68a8f262..239ceeede 100644 --- a/exercises/practice/anagram/anagram.test.ts +++ b/exercises/practice/anagram/anagram.test.ts @@ -2,14 +2,14 @@ import { describe, it, expect, xit } from '@jest/globals' import { Anagram } from './anagram.ts' let areSetsEqual = (setA, setB) => - setA.size === setB.size && [...setA].every((val) => setB.has(val)); + setA.size === setB.size && [...setA].every((val) => setB.has(val)) describe('Anagram', () => { it('no matches', () => { const subject = new Anagram('diaper') const matches = subject.matches('hello', 'world', 'zombies', 'pants') const expected = [] - + expect(areSetsEqual(new Set(expected), new Set(matches))).toEqual(true) }) From a5676c99bcf0c67c1238e29cf4e606b14adf1145 Mon Sep 17 00:00:00 2001 From: Cool-Katt Date: Wed, 15 Jan 2025 14:55:26 +0200 Subject: [PATCH 3/4] Fixing copy/paste error --- exercises/practice/anagram/anagram.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/anagram/anagram.test.ts b/exercises/practice/anagram/anagram.test.ts index 239ceeede..a075dbe9c 100644 --- a/exercises/practice/anagram/anagram.test.ts +++ b/exercises/practice/anagram/anagram.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, xit } from '@jest/globals' import { Anagram } from './anagram.ts' -let areSetsEqual = (setA, setB) => +const areSetsEqual = (setA, setB) => setA.size === setB.size && [...setA].every((val) => setB.has(val)) describe('Anagram', () => { From f8d99305afaabd6d044ddfbed89e5e7c0f9b1e18 Mon Sep 17 00:00:00 2001 From: Cool-Katt Date: Wed, 15 Jan 2025 15:00:19 +0200 Subject: [PATCH 4/4] more dumb mistakes --- exercises/practice/anagram/anagram.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/anagram/anagram.test.ts b/exercises/practice/anagram/anagram.test.ts index a075dbe9c..6bbbf8ee9 100644 --- a/exercises/practice/anagram/anagram.test.ts +++ b/exercises/practice/anagram/anagram.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, xit } from '@jest/globals' import { Anagram } from './anagram.ts' -const areSetsEqual = (setA, setB) => +const areSetsEqual = (setA: Set, setB: Set): boolean => setA.size === setB.size && [...setA].every((val) => setB.has(val)) describe('Anagram', () => {