Git Product home page Git Product logo

av2-gildedrose-kata's Introduction

check-code-coverage

Gilded Rose Refactoring Kata - Alison Vandromme

Bordeaux Ynov M1 - Architecture Logicielle

Kata: here

Clarifications:

"Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class or Items property as those belong to the goblin in the corner who will insta-rage and one-shot you as he doesn't believe in shared code ownership (you can make the UpdateQuality method and Items property static if you like, we'll cover for you).

Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters."

Refactoring : Steps

Step 1: Setup

Modifications

I modified the original ES5 syntax to use ES6. To do so, I installed and configured Babel.

Workflow

Added Github Action workflow to open PR on dev branch push.

Sanity test

Wrote and ran a sanity test to make sure Jest is working properly.

Step 2: Write tests based on the requirements

System:

  • All items have a SellIn value which denotes the number of days we have to sell the item
  • All items have a Quality value which denotes how valuable the item is
  • At the end of each day our system lowers both values for every item

Requirements: Full Specifications

Split requirements in smaller chunks

  • Once the sell by date has passed, quality degrades twice as fast
  • The quality of an item is never negative
  • Aged Brie increases in quality the older it gets
  • The quality of an item is never more than 50
  • Sulfuras never has to be sold or decreases in quality
  • "Backstage passes":
    • Like Aged Brie, increases in quality as its SellIn value approaches
    • Quality increases by 2 when there are 10 days or less
    • Quality increases by 3 when there are 5 days or less
    • But quality drops to 0 after the concert

Text-based tests

The goal is to capture the existing output of the code and use it to check against everytime we make a change. The first test compares the original items passed down to the original code agaisnt the results we expect the code to give. This way, we are always able to verify that the existing behavior is not altered.

Step 3: Generate code coverage

Generated code coverage for the original code. The goal is to make sure all the statements and functions are covered. A badge is generated using check-code-coverage

Step 4: Refactor

Instead of modifying the existing code, I entirely rewrote the code. I started from the tests, and made them pass one by one.

Step 5: Generate code coverage

I regenerated code coverage to make sure the tests still cover the whole code.

Step 5: Add the required feature

Requirement: "Conjured items degrade in Quality twice as fast as normal items".

First, I wrote the test for the Conjured items requirement. Then, I added a new method to make this test pass. I reran tests and checked that code coverage is still 100%.

Comments

All the methods are related to the Item class and not the Shop one. Thus, if I had the freedom to modify the Item class, I would have put most of the methods there.

av2-gildedrose-kata's People

Contributors

alisonv2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.