This is refactoring coding challenge that I developed to show you my coding and design skills:
Coding Example
- The programming language is Java.
- The code is to be tested.
- Please submit code as well tests.
- Please describe shortly the advantages and disadvantages of your design.
- The IDE is free to choose
- The build tool should be Maven or Gradle, but can be different.
- Please solve this task according to the standards like you would in your normal work.
Task: Rock-Paper-Scissors
Build a game in which two players compete in a game of Rock-Paper-Scissors with different strategies. Who will win more rounds? The rules:
-
Scissors beats Paper
-
Rock beat Scissors
-
Paper beats Rock
-
If both players choose the same, the round is counted as a tie.
Implement two players:
-
Player A always chooses Paper
-
Player B chooses randomly
The game consists of 100 rounds of above two players competing. The output of the program
should be like the following:
"Player A wins 31 of 100 games"
"Player B wins 37 of 100 games"
"Tie: 32 of 100 games"
Coding Example Task: Rock-Paper-Scissors
Build system: maven Test system: TestNG
Pattern: Strategy, Dependency injection
Run:
- Build project using maven
- Run main method of Application.class (package com.github.vedenin.testtask)
Testing:
- StrategiesTest - test all Strategies
- RulesTest - test rule of Rock-Paper-Scissors
- GamesTest - integration test of all project
Advantages of my design:
- Using single responsibility principle (every class have only one task)
- Using open/closed principle (easy for extension, almost all class has interface)
- Dependency inversion principle (using Dependency injection framework - Guice)
- Possible to extensions for any Two-player games (chess, checkers, go and so on)
- Only some class has specific Rock-Paper-Scissors details (in package rockpaperscissors), other classes can be using in any Two-player games
Disadvantages of my design:
- Many class/interface for extensions for any Two-player games