From fee46220444a37eff6ddc2a9086ac9c7e3aae6b6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:44:24 +0200 Subject: [PATCH] Fixed ROT13Converter file name, changed its ID and added tests. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/rot13-converter.spec.ts | 24 +++++++++++++++++++ .../{rot13converter.ts => rot13-converter.ts} | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/rot13-converter.spec.ts rename src/app/converter/{rot13converter.ts => rot13-converter.ts} (96%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index a4721c6..d6f6714 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -13,7 +13,7 @@ import {PunycodeDecoder} from './converter/punycode-decoder'; import {PunycodeEncoder} from './converter/punycode-encoder'; import {QuotedPrintableDecoder} from './converter/quoted-printable-decoder'; import {QuotedPrintableEncoder} from './converter/quoted-printable-encoder'; -import {ROT13Converter} from './converter/rot13converter'; +import {ROT13Converter} from './converter/rot13-converter'; import {URIComponentDecoder} from './converter/uricomponentdecoder'; import {URIComponentEncoder} from './converter/uricomponentencoder'; import {URIDecoder} from './converter/uridecoder'; diff --git a/src/app/converter/rot13-converter.spec.ts b/src/app/converter/rot13-converter.spec.ts new file mode 100644 index 0000000..76e472d --- /dev/null +++ b/src/app/converter/rot13-converter.spec.ts @@ -0,0 +1,24 @@ +import {ROT13Converter} from './rot13-converter'; + +describe('ROT13Converter', () => { + let sut: ROT13Converter; + + beforeEach(() => sut = new ROT13Converter()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "rot13"', () => { + expect(sut.getId()).toEqual('rot13'); + }); + + it('should encode "Hello, World!" to "Uryyb, Jbeyq!"', () => { + expect(sut.convert('Hello, World!')).toEqual('Uryyb, Jbeyq!'); + }); + + it('should return the original input after being applied twice', () => { + const input = 'Ok, so this string is just a bunch of letters. And numbers: 1, 2, 3. Ans others: /&%. Kthxbye!'; + expect(sut.convert(sut.convert(input))).toEqual(input); + }); +}); diff --git a/src/app/converter/rot13converter.ts b/src/app/converter/rot13-converter.ts similarity index 96% rename from src/app/converter/rot13converter.ts rename to src/app/converter/rot13-converter.ts index ed51b5d..0bc9df5 100644 --- a/src/app/converter/rot13converter.ts +++ b/src/app/converter/rot13-converter.ts @@ -6,7 +6,7 @@ export class ROT13Converter implements Converter { } getId(): string { - return 'rot13convert'; + return 'rot13'; } convert(input: string): string {