rot13 tool, testCases then updated index file

This commit is contained in:
Chesterkxng
2024-07-12 00:09:21 +00:00
parent 350061d79e
commit a83af6a82e
5 changed files with 90 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import { tool as stringRot13 } from './rot13/meta';
import { tool as stringReverse } from './reverse/meta';
import { tool as stringRandomizeCase } from './randomize-case/meta';
import { tool as stringUppercase } from './uppercase/meta';

View 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 Rot13() {
return <Box>Lorem ipsum</Box>;
}

View File

@@ -0,0 +1,13 @@
import { defineTool } from '@tools/defineTool';
import { lazy } from 'react';
// import image from '@assets/text.png';
export const tool = defineTool('string', {
name: 'Rot13',
path: 'rot13',
// image,
description: '',
shortDescription: '',
keywords: ['rot13'],
component: lazy(() => import('./index'))
});

View File

@@ -0,0 +1,58 @@
import { expect, describe, it } from 'vitest';
import { rot13 } from './service';
describe('rot13', () => {
it('should encode a simple string using ROT13', () => {
const input = 'hello';
const result = rot13(input);
expect(result).toBe('uryyb');
});
it('should decode a ROT13 encoded string', () => {
const input = 'uryyb';
const result = rot13(input);
expect(result).toBe('hello');
});
it('should handle uppercase letters correctly', () => {
const input = 'HELLO';
const result = rot13(input);
expect(result).toBe('URYYB');
});
it('should handle mixed case letters correctly', () => {
const input = 'HelloWorld';
const result = rot13(input);
expect(result).toBe('UryybJbeyq');
});
it('should handle non-alphabetic characters correctly', () => {
const input = 'Hello, World!';
const result = rot13(input);
expect(result).toBe('Uryyb, Jbeyq!');
});
it('should handle an empty string', () => {
const input = '';
const result = rot13(input);
expect(result).toBe('');
});
it('should handle a string with numbers correctly', () => {
const input = '1234';
const result = rot13(input);
expect(result).toBe('1234');
});
it('should handle a string with symbols correctly', () => {
const input = '!@#$%^&*()_+-=';
const result = rot13(input);
expect(result).toBe('!@#$%^&*()_+-=');
});
it('should handle a string with mixed characters correctly', () => {
const input = 'Hello, World! 123';
const result = rot13(input);
expect(result).toBe('Uryyb, Jbeyq! 123');
});
});

View File

@@ -0,0 +1,7 @@
export function rot13(input: string): string {
return input.replace(/[a-zA-Z]/g, (char) => {
const charCode = char.charCodeAt(0);
const baseCode = charCode >= 97 ? 97 : 65; // 'a' or 'A'
return String.fromCharCode(((charCode - baseCode + 13) % 26) + baseCode);
});
}