mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-18 05:29:33 +02:00
Merge remote-tracking branch 'origin/chesterking'
# Conflicts: # src/pages/number/index.ts
This commit is contained in:
76
src/pages/number/generate/generate.service.test.ts
Normal file
76
src/pages/number/generate/generate.service.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
// Import necessary modules and functions
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { listOfIntegers} from './service';
|
||||
|
||||
// Define test cases for the listOfIntegers function
|
||||
describe('listOfIntegers function', () => {
|
||||
it('should generate a list of integers with comma separator', () => {
|
||||
const initialValue = 1;
|
||||
const step = 2;
|
||||
const count = 5;
|
||||
const separator = ', ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('1, 3, 5, 7, 9');
|
||||
});
|
||||
|
||||
it('should generate a list of integers with dash separator', () => {
|
||||
const initialValue = 0;
|
||||
const step = 3;
|
||||
const count = 4;
|
||||
const separator = ' - ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('0 - 3 - 6 - 9');
|
||||
});
|
||||
|
||||
it('should handle negative initial value and step', () => {
|
||||
const initialValue = -10;
|
||||
const step = -2;
|
||||
const count = 5;
|
||||
const separator = ' ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('-10 -12 -14 -16 -18');
|
||||
});
|
||||
|
||||
it('should handle negative initial value and positive step', () => {
|
||||
const initialValue = -10;
|
||||
const step = 2;
|
||||
const count = 5;
|
||||
const separator = ' ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('-10 -8 -6 -4 -2');
|
||||
});
|
||||
|
||||
it('should float value', () => {
|
||||
const initialValue = -10;
|
||||
const step = 2.5;
|
||||
const count = 5;
|
||||
const separator = ' ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('-10 -7.5 -5 -2.5 0');
|
||||
});
|
||||
|
||||
it('should generate a constant sequence if the step is 0', () => {
|
||||
const initialValue = 1;
|
||||
const step = 0;
|
||||
const count = 5;
|
||||
const separator = ' ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('1 1 1 1 1');
|
||||
});
|
||||
|
||||
it('should generate a constant sequence if the step is 0', () => {
|
||||
const initialValue = 1;
|
||||
const step = 0;
|
||||
const count = 5;
|
||||
const separator = ' ';
|
||||
|
||||
const result = listOfIntegers(initialValue, count, step, separator);
|
||||
expect(result).toBe('1 1 1 1 1');
|
||||
});
|
||||
});
|
11
src/pages/number/generate/index.tsx
Normal file
11
src/pages/number/generate/index.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Box } from '@mui/material';
|
||||
import React from 'react';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
const initialValues = {};
|
||||
const validationSchema = Yup.object({
|
||||
// splitSeparator: Yup.string().required('The separator is required')
|
||||
});
|
||||
export default function Generate() {
|
||||
return <Box>Lorem ipsum</Box>;
|
||||
}
|
12
src/pages/number/generate/meta.ts
Normal file
12
src/pages/number/generate/meta.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineTool } from '@tools/defineTool';
|
||||
import { lazy } from 'react';
|
||||
// import image from '@assets/text.png';
|
||||
|
||||
export const tool = defineTool('number', {
|
||||
name: 'Generate',
|
||||
path: 'generate',
|
||||
// image,
|
||||
description: '',
|
||||
keywords: ['generate'],
|
||||
component: lazy(() => import('./index'))
|
||||
});
|
12
src/pages/number/generate/service.ts
Normal file
12
src/pages/number/generate/service.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function listOfIntegers(
|
||||
first_value: number,
|
||||
number_of_numbers: number,
|
||||
step: number,
|
||||
separator: string) {
|
||||
const result: number[] = [];
|
||||
for (let i: number = 0; i < number_of_numbers; i++) {
|
||||
const value: number = first_value + i * step;
|
||||
result.push(value);
|
||||
}
|
||||
return result.join(separator);
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
import { tool as numberSum } from './sum/meta';
|
||||
import { tool as numberGenerate } from './generate/meta';
|
||||
|
||||
export const numberTools = [numberSum];
|
||||
export const numberTools = [numberSum, numberGenerate];
|
||||
|
Reference in New Issue
Block a user