diff --git a/kata/8 kyu/color-ghost/__mocks__/index.ts b/kata/8 kyu/color-ghost/__mocks__/index.ts new file mode 100644 index 00000000..4cf60c16 --- /dev/null +++ b/kata/8 kyu/color-ghost/__mocks__/index.ts @@ -0,0 +1,9 @@ +/* eslint-disable class-methods-use-this */ + +class Ghost { + get color(): string { + return 'white'; + } +} + +export default Ghost; diff --git a/kata/8 kyu/color-ghost/index.test.ts b/kata/8 kyu/color-ghost/index.test.ts new file mode 100644 index 00000000..7b67767f --- /dev/null +++ b/kata/8 kyu/color-ghost/index.test.ts @@ -0,0 +1,13 @@ +import Ghost from '.'; + +jest.mock('.'); + +describe('ghost', () => { + it('should', () => { + expect.assertions(1); + + const ghost = new Ghost(); + + expect(ghost.color).toBe('white'); + }); +}); diff --git a/kata/8 kyu/color-ghost/index.ts b/kata/8 kyu/color-ghost/index.ts new file mode 100644 index 00000000..f302fccc --- /dev/null +++ b/kata/8 kyu/color-ghost/index.ts @@ -0,0 +1,17 @@ +function randomInteger(max: number, min = 0): number { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +class Ghost { + colors: string[]; + + constructor() { + this.colors = ['white', 'yellow', 'purple', 'red']; + } + + get color(): string { + return this.colors[randomInteger(this.colors.length) + 1]; + } +} + +export default Ghost; diff --git a/kata/8 kyu/color-ghost/readme.md b/kata/8 kyu/color-ghost/readme.md new file mode 100644 index 00000000..5fa8b08d --- /dev/null +++ b/kata/8 kyu/color-ghost/readme.md @@ -0,0 +1,47 @@ +# [Color Ghost](https://www.codewars.com/kata/53f1015fa9fe02cbda00111a) + +### Color Ghost + +Create a class Ghost + +Ghost objects are instantiated without any arguments. + +Ghost objects are given a random color attribute of white" or "yellow" or "purple" or "red" when instantiated + +```javascript +ghost = new Ghost(); +ghost.color; //=> "white" or "yellow" or "purple" or "red" +``` + +```coffeescript +ghost = new Ghost() +ghost.color #=> "white" or "yellow" or "purple" or "red" +``` + +```ruby +ghost = Ghost.new +ghost.color #=> "white" or "yellow" or "purple" or "red" +``` + +```python +ghost = Ghost() +ghost.color #=> "white" or "yellow" or "purple" or "red" +``` + +```java +Ghost ghost = new Ghost(); +ghost.getColor(); //=> "white" or "yellow" or "purple" or "red" +``` + +```c# +Ghost ghost = new Gost(); +ghost.GetColor(); // => "white" or "yellow" or "purple" or "red" +``` + +--- + +## Tags + +- Fundamentals +- Object-oriented Programming +- Programming Paradigms