2021-10-07 09:03:38 +02:00
|
|
|
import { ReverseStringIterative, ReverseStringIterativeInplace } from '../ReverseString'
|
2020-10-04 14:38:48 -03:00
|
|
|
|
|
|
|
|
describe('ReverseStringIterative', () => {
|
|
|
|
|
it('expects to reverse a simple string', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterative('reverse')).toEqual('esrever')
|
|
|
|
|
expect(ReverseStringIterative('some')).toEqual('emos')
|
|
|
|
|
expect(ReverseStringIterative('string')).toEqual('gnirts')
|
|
|
|
|
expect(ReverseStringIterative('The Algorithms Javascript')).toEqual('tpircsavaJ smhtiroglA ehT')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it('expects to reverse a string with spaces in between', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterative('reverse me')).toEqual('em esrever')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it('expects to reverse a simple string without capitalizing the first letter', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterative('Javascript')).toEqual('tpircsavaJ')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it.each`
|
|
|
|
|
input
|
|
|
|
|
${123456}
|
|
|
|
|
${[1, 2, 3, 4, 5, 6]}
|
|
|
|
|
${{ test: 'test' }}
|
2021-10-07 09:03:38 +02:00
|
|
|
${null}
|
2020-10-04 14:38:48 -03:00
|
|
|
`(
|
|
|
|
|
'expects to throw a type error given a value that is $input',
|
|
|
|
|
({ input }) => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(() => ReverseStringIterative(input)).toThrow('The given value is not a string')
|
2020-10-04 14:38:48 -03:00
|
|
|
}
|
|
|
|
|
)
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it('expects to return a empty string with an empty string is given', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterative('')).toEqual('')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
|
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
describe('ReverseStringIterativeInplace', () => {
|
|
|
|
|
it('expects to reverse a simple string', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterativeInplace('reverse')).toEqual('esrever')
|
|
|
|
|
expect(ReverseStringIterativeInplace('some')).toEqual('emos')
|
|
|
|
|
expect(ReverseStringIterativeInplace('string')).toEqual('gnirts')
|
|
|
|
|
expect(ReverseStringIterativeInplace('The Algorithms Javascript')).toEqual('tpircsavaJ smhtiroglA ehT')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it('expects to reverse a simple string without capitalizing the first letter', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterativeInplace('Javascript')).toEqual('tpircsavaJ')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it('expects to return an empty string given an empty string', () => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(ReverseStringIterativeInplace('Javascript')).toEqual('tpircsavaJ')
|
2020-10-04 14:38:48 -03:00
|
|
|
})
|
2021-10-07 09:03:38 +02:00
|
|
|
|
2020-10-04 14:38:48 -03:00
|
|
|
it.each`
|
|
|
|
|
input
|
|
|
|
|
${123456}
|
|
|
|
|
${[1, 2, 3, 4, 5, 6]}
|
|
|
|
|
${{ test: 'test' }}
|
2021-10-07 09:03:38 +02:00
|
|
|
${null}
|
2020-10-04 14:38:48 -03:00
|
|
|
`(
|
|
|
|
|
'expects to throw a type error given a value that is $input',
|
|
|
|
|
({ input }) => {
|
2021-10-07 09:03:38 +02:00
|
|
|
expect(() => ReverseStringIterativeInplace(input)).toThrow('The given value is not a string')
|
2020-10-04 14:38:48 -03:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|