chore: sum tests

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-25 03:22:10 +01:00
parent aa64f04d69
commit 01e0b04c8a
2 changed files with 78 additions and 20 deletions

28
.idea/workspace.xml generated
View File

@@ -4,9 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: compilation">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: printRunningSum">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/sum/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/sum/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/sum/sum.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/sum/sum.service.test.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -176,15 +176,7 @@
<workItem from="1719166718305" duration="1783000" />
<workItem from="1719168519203" duration="17675000" />
<workItem from="1719197816332" duration="1453000" />
<workItem from="1719273044735" duration="8860000" />
</task>
<task id="LOCAL-00004" summary="feat: example tools">
<option name="closed" value="true" />
<created>1718822309352</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1718822309352</updated>
<workItem from="1719273044735" duration="9001000" />
</task>
<task id="LOCAL-00005" summary="feat: Split string">
<option name="closed" value="true" />
@@ -570,7 +562,15 @@
<option name="project" value="LOCAL" />
<updated>1719281605999</updated>
</task>
<option name="localTasksCounter" value="53" />
<task id="LOCAL-00053" summary="chore: printRunningSum">
<option name="closed" value="true" />
<created>1719282009150</created>
<option name="number" value="00053" />
<option name="presentableId" value="LOCAL-00053" />
<option name="project" value="LOCAL" />
<updated>1719282009150</updated>
</task>
<option name="localTasksCounter" value="54" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -591,7 +591,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="feat: tools normalized" />
<MESSAGE value="feat: search tools" />
<MESSAGE value="fix: deploy message" />
<MESSAGE value="chore: tools by category" />
@@ -616,7 +615,8 @@
<MESSAGE value="feat: string to morse" />
<MESSAGE value="feat: sum numbers init" />
<MESSAGE value="fix: compilation" />
<option name="LAST_COMMIT_MESSAGE" value="fix: compilation" />
<MESSAGE value="chore: printRunningSum" />
<option name="LAST_COMMIT_MESSAGE" value="chore: printRunningSum" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

View File

@@ -1,6 +1,64 @@
import { expect, describe, it } from 'vitest';
// import { } from './service';
//
// describe('sum', () => {
//
// })
import { describe, it, expect } from 'vitest';
import { compute } from './service';
describe('compute function', () => {
it('should correctly sum numbers in smart extraction mode', () => {
const input = 'The 2 cats have 4 and 7 kittens';
const result = compute(input, 'smart', false, ',');
expect(result).toBe('13');
});
it('should correctly sum numbers with custom delimiter', () => {
const input = '2,4,7';
const result = compute(input, 'delimiter', false, ',');
expect(result).toBe('13');
});
it('should return running sum in smart extraction mode', () => {
const input = 'The 2 cats have 4 and 7 kittens';
const result = compute(input, 'smart', true, ',');
expect(result).toBe('2\n6\n13\n');
});
it('should return running sum with custom delimiter', () => {
const input = '2,4,7';
const result = compute(input, 'delimiter', true, ',');
expect(result).toBe('2\n6\n13\n');
});
it('should handle empty input gracefully in smart mode', () => {
const input = '';
const result = compute(input, 'smart', false, ',');
expect(result).toBe('0');
});
it('should handle empty input gracefully in delimiter mode', () => {
const input = '';
const result = compute(input, 'delimiter', false, ',');
expect(result).toBe('0');
});
it('should handle input with no numbers in smart mode', () => {
const input = 'There are no numbers here';
const result = compute(input, 'smart', false, ',');
expect(result).toBe('0');
});
it('should handle input with no numbers in delimiter mode', () => {
const input = 'a,b,c';
const result = compute(input, 'delimiter', false, ',');
expect(result).toBe('0');
});
it('should ignore non-numeric parts in delimiter mode', () => {
const input = '2,a,4,b,7';
const result = compute(input, 'delimiter', false, ',');
expect(result).toBe('13');
});
it('should handle different separators', () => {
const input = '2;4;7';
const result = compute(input, 'delimiter', false, ';');
expect(result).toBe('13');
});
});