This repository contains a collection of utility functions written in JavaScript, along with comprehensive unit tests using Jest. The functions handle mathematical operations, string manipulations, and temperature conversion.
This file includes various utility functions:
potencia(x, y)
: Returns the result of raisingx
to the power ofy
. Throws an error for invalid inputs.inverterString(texto)
: Reverses the given string. Throws an error if the input is not a string.ehPalindromo(texto)
: Checks if a given string is a palindrome. Throws an error if the input is not a string.funcaoFatorial(num)
: Recursively calculates the factorial of a number. Throws an error for negative or non-numeric inputs.celsiusParaFahrenheit(num)
: Converts a temperature from Celsius to Fahrenheit. Throws an error for non-numeric inputs.
This file contains unit tests for each of the above functions using the Jest framework. These tests ensure that the functions perform correctly across different input scenarios, including edge cases and error handling.
- Make sure you have Node.js installed on your machine.
- Clone this repository.
- Install the dependencies (Jest) by running:
npm install
- To run the tests, use the command:
npm test
test("Should return the first number raised to the power of the second", () => {
expect(potencia(2, 3)).toBe(8);
});
test("Should throw an error for invalid string input in potencia function", () => {
expect(() => potencia("a", 2)).toThrow("Entrada inválida");
});
This project is licensed under the MIT License. See the LICENSE file for details.