fix: generate numbers

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-25 22:09:17 +01:00
parent fe305581e8
commit c015425838
6 changed files with 120 additions and 113 deletions

87
.idea/workspace.xml generated
View File

@@ -5,11 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: ToolFileInput.tsx"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: ToolFileInput.tsx">
<change afterPath="$PROJECT_DIR$/src/components/ToolBreadcrumb.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/ToolHeader.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolHeader.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/Loading.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Loading.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/ToolLayout.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolLayout.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/number/generate/generate.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/generate.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tools/defineTool.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/tools/defineTool.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/number/generate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/generate/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/generate/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/service.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -19,10 +20,13 @@
<component name="FormatOnSaveOptions"> <component name="FormatOnSaveOptions">
<option name="myRunOnSave" value="true" /> <option name="myRunOnSave" value="true" />
</component> </component>
<component name="Git.Merge.Settings">
<option name="BRANCH" value="origin/chesterking" />
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="string-join" /> <entry key="$PROJECT_DIR$" value="chesterking" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -43,39 +47,40 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;Vitest.compute function (1).executor&quot;: &quot;Run&quot;, "Vitest.compute function (1).executor": "Run",
&quot;Vitest.compute function.executor&quot;: &quot;Run&quot;, "Vitest.compute function.executor": "Run",
&quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.executor": "Run",
&quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
&quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Users/HP/IdeaProjects/omni-tools/src/assets&quot;, "last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/assets",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;npm.dev.executor&quot;: &quot;Run&quot;, "npm.dev.executor": "Run",
&quot;npm.prebuild.executor&quot;: &quot;Run&quot;, "npm.lint.executor": "Run",
&quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;, "npm.prebuild.executor": "Run",
&quot;npm.test.executor&quot;: &quot;Run&quot;, "npm.script:create:tool.executor": "Run",
&quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;, "npm.test.executor": "Run",
&quot;project.structure.last.edited&quot;: &quot;Problems&quot;, "prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
&quot;project.structure.proportion&quot;: &quot;0.0&quot;, "project.structure.last.edited": "Problems",
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;, "project.structure.proportion": "0.0",
&quot;settings.editor.selected.configurable&quot;: &quot;settings.typescriptcompiler&quot;, "project.structure.side.proportion": "0.2",
&quot;ts.external.directory.path&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;, "settings.editor.selected.configurable": "settings.typescriptcompiler",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="ReactDesignerToolWindowState"> <component name="ReactDesignerToolWindowState">
<option name="myId2Visible"> <option name="myId2Visible">
<map> <map>
@@ -136,11 +141,11 @@
<envs /> <envs />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="script:create:tool" type="js.build_tools.npm" temporary="true" nameIsGenerated="true"> <configuration name="lint" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" /> <package-json value="$PROJECT_DIR$/package.json" />
<command value="run" /> <command value="run" />
<scripts> <scripts>
<script value="script:create:tool" /> <script value="lint" />
</scripts> </scripts>
<node-interpreter value="project" /> <node-interpreter value="project" />
<envs /> <envs />
@@ -159,10 +164,10 @@
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="npm.dev" /> <item itemvalue="npm.dev" />
<item itemvalue="npm.test" />
<item itemvalue="npm.lint" />
<item itemvalue="Vitest.compute function (1)" /> <item itemvalue="Vitest.compute function (1)" />
<item itemvalue="Vitest.compute function" /> <item itemvalue="Vitest.compute function" />
<item itemvalue="npm.test" />
<item itemvalue="npm.script:create:tool" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>

View File

@@ -22,7 +22,7 @@ function FuseLoading(props: FuseLoadingProps) {
return ( return (
<div> <div>
<Typography <Typography
className="-mb-16 text-13 font-medium sm:text-20" className="text-13 sm:text-20 -mb-16 font-medium"
color="text.secondary" color="text.secondary"
> >
Loading Loading

View File

@@ -1,76 +1,76 @@
// Import necessary modules and functions // Import necessary modules and functions
import { describe, it, expect } from 'vitest'; import { describe, it, expect } from 'vitest';
import { listOfIntegers} from './service'; import { listOfIntegers } from './service';
// Define test cases for the listOfIntegers function // Define test cases for the listOfIntegers function
describe('listOfIntegers function', () => { describe('listOfIntegers function', () => {
it('should generate a list of integers with comma separator', () => { it('should generate a list of integers with comma separator', () => {
const initialValue = 1; const initialValue = 1;
const step = 2; const step = 2;
const count = 5; const count = 5;
const separator = ', '; const separator = ', ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('1, 3, 5, 7, 9'); expect(result).toBe('1, 3, 5, 7, 9');
}); });
it('should generate a list of integers with dash separator', () => { it('should generate a list of integers with dash separator', () => {
const initialValue = 0; const initialValue = 0;
const step = 3; const step = 3;
const count = 4; const count = 4;
const separator = ' - '; const separator = ' - ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('0 - 3 - 6 - 9'); expect(result).toBe('0 - 3 - 6 - 9');
}); });
it('should handle negative initial value and step', () => { it('should handle negative initial value and step', () => {
const initialValue = -10; const initialValue = -10;
const step = -2; const step = -2;
const count = 5; const count = 5;
const separator = ' '; const separator = ' ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('-10 -12 -14 -16 -18'); expect(result).toBe('-10 -12 -14 -16 -18');
}); });
it('should handle negative initial value and positive step', () => { it('should handle negative initial value and positive step', () => {
const initialValue = -10; const initialValue = -10;
const step = 2; const step = 2;
const count = 5; const count = 5;
const separator = ' '; const separator = ' ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('-10 -8 -6 -4 -2'); expect(result).toBe('-10 -8 -6 -4 -2');
}); });
it('should float value', () => { it('should float value', () => {
const initialValue = -10; const initialValue = -10;
const step = 2.5; const step = 2.5;
const count = 5; const count = 5;
const separator = ' '; const separator = ' ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('-10 -7.5 -5 -2.5 0'); expect(result).toBe('-10 -7.5 -5 -2.5 0');
}); });
it('should generate a constant sequence if the step is 0', () => { it('should generate a constant sequence if the step is 0', () => {
const initialValue = 1; const initialValue = 1;
const step = 0; const step = 0;
const count = 5; const count = 5;
const separator = ' '; const separator = ' ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('1 1 1 1 1'); expect(result).toBe('1 1 1 1 1');
}); });
it('should generate a constant sequence if the step is 0', () => { it('should generate a constant sequence if the step is 0', () => {
const initialValue = 1; const initialValue = 1;
const step = 0; const step = 0;
const count = 5; const count = 5;
const separator = ' '; const separator = ' ';
const result = listOfIntegers(initialValue, count, step, separator); const result = listOfIntegers(initialValue, count, step, separator);
expect(result).toBe('1 1 1 1 1'); expect(result).toBe('1 1 1 1 1');
}); });
}); });

View File

@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
}); });
export default function Generate() { export default function Generate() {
return <Box>Lorem ipsum</Box>; return <Box>Lorem ipsum</Box>;
} }

View File

@@ -6,7 +6,8 @@ export const tool = defineTool('number', {
name: 'Generate', name: 'Generate',
path: 'generate', path: 'generate',
// image, // image,
description: '', description:
'Quickly calculate a list of integers in your browser. To get your list, just specify the first integer, change value and total count in the options below, and this utility will generate that many integers',
keywords: ['generate'], keywords: ['generate'],
component: lazy(() => import('./index')) component: lazy(() => import('./index'))
}); });

View File

@@ -1,12 +1,13 @@
export function listOfIntegers( export function listOfIntegers(
first_value: number, first_value: number,
number_of_numbers: number, number_of_numbers: number,
step: number, step: number,
separator: string) { separator: string
const result: number[] = []; ) {
for (let i: number = 0; i < number_of_numbers; i++) { const result: number[] = [];
const value: number = first_value + i * step; for (let i: number = 0; i < number_of_numbers; i++) {
result.push(value); const value: number = first_value + i * step;
} result.push(value);
return result.join(separator); }
} return result.join(separator);
}