Skip to content

Commit 20a9751

Browse files
committed
the whole thing
0 parents  commit 20a9751

File tree

15 files changed

+866
-0
lines changed

15 files changed

+866
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.DS_Store

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Lift pass pricing
2+
3+
![Image logo](./mountain-snow.jpg)
4+
5+
This application solves the problem of calculating the pricing for ski lift passes.
6+
There's some intricate logic linked to what kind of lift pass you want, your age
7+
and the specific date at which you'd like to ski. There's a new feature request,
8+
be able to get the price for several lift passes, not just one. Currently the pricing
9+
for a single lift pass is implemented, unfortunately the code as it is designed
10+
is ***not reusable***.
11+
You could put some high level tests in place in order to do ***preparatory refactoring***
12+
so that the new feature requires minimum effort to implement.
13+
14+
This kata models a common problem - code that makes no sense to unit test due to bad design.
15+
16+
You can find a [video pitch here](http://youtube.com/watch?v=-gSyD60WAvc)
17+
18+
19+
20+
## When am I done?
21+
22+
There are a few steps, you could do any of them.
23+
24+
1. Cover with high level tests.
25+
1. Refactor the code to maximize unit testability and reuse for the new feature
26+
1. Pull down most of the high level tests
27+
1. Implement the new feature using unit tests and 1 or 2 high level tests.
28+
29+
## Installation
30+
31+
Set up a MySQL database on localhost 3306 with user `root` and password `mysql`.
32+
If you have Docker installed the easiest thing is to use this script, that will initialize a [MariaDB](https://mariadb.org/).
33+
34+
./runLocalDatabase.sh
35+
36+
Inject the data with
37+
38+
mysql -u root -p mysql < ./database/initDatabase.sql
39+
40+
Then head on to the language of your choice and follow the Readme in there.
41+
Some of the languages have a failing test that you could finish writing.
42+
43+
## Tips
44+
45+
There's a good chance you could find a design that is both easier to test, faster to
46+
work with and that solves the problem with minimum amount of code. One such design
47+
would be to rid the bulk of the logic from it's adherence to the http/rest framework
48+
and from the sql specificities. This is sometimes called **hexagonal architecture**
49+
and it facilitates respecting the ***Testing Pyramid*** which is not currently
50+
possible - there can be only top-level tests
51+
52+
The typical workflow would be
53+
54+
1. Cover everything from the http layer, use a real DB
55+
1. Separate request data extraction and sending the response from the logic
56+
1. Extract a method with the pure logic, move that method to an object (ex PricingLogic)
57+
1. Now extract the sql stuff from PricingLogic, first to some method with a signature that has nothing to do with sql, then move these methods to a new class (ex PricingDao)
58+
1. There should be ~3/4 elements, the http layer should have the PricingLogic as an injected dependency and the PricingLogic should have the PricingDao as an injected dependency.
59+
1. Move the bulk of the high level tests down onto PricingLogic using a fake dao, write some focused integration tests for the PricingDao using a real DB, there should be only a handful.
60+
61+
Now the HTTP layer and the integration of the parts can be tested with very few (one or two) high-level tests.
62+
63+
64+
## CONTRIBUTING
65+
66+
There are two branches, the master branch and the with_tests branch. The master is always merged into the with_tests branch.
67+
So typically if you want to contribute a new language or a *simple* version of a language you typically change the master branch,
68+
then switch to the with_tests branch and merge with master, then add tests.
69+
70+
Note that there are github actions for most of the with_tests versions, please do provide one if you add a language. This allows
71+
anyone having trouble running the tests with a baseline for getting the tests to work
72+
73+
When you're ready please submit one pull request for each branch
74+
75+
Thanks for contributing!

0 commit comments

Comments
 (0)