Giter Site home page Giter Site logo

emilybache / racing-car-katas Goto Github PK

View Code? Open in Web Editor NEW
275.0 23.0 330.0 5.12 MB

The starting code for several code katas on a racing car theme

License: MIT License

C# 9.18% C++ 9.17% Java 10.91% JavaScript 4.82% Python 6.21% Ruby 4.88% Scala 4.57% CMake 6.67% Swift 5.35% Shell 0.21% Kotlin 8.40% Meson 2.96% PHP 10.23% Batchfile 0.04% Go 2.03% TypeScript 4.56% C 0.42% Makefile 0.73% Rust 8.65%

racing-car-katas's Introduction

Racing Car Katas

In this repository you'll find starting code for five distinct problems. They could be code you inherited from a legacy code-base. Now you want to write unit tests for them, and that is harder than it needs to be. All of the code snippets fail to follow one or more of the SOLID principles.

For each exercise, you should identify which SOLID principles are not being followed by the code. There is only one class you are interested in writing tests for right now. As a first step, try to get some kind of test in place before you change the class at all. If the tests are hard to write, is that because of the problems with SOLID principles?

When you have some kind of test to lean on, refactor the code and make it testable. Take care when refactoring not to alter the functionality, or change interfaces which other client code may rely on. (Imagine there is client code in another repository that you can't see right now). Add more tests to cover the functionality of the particular class you've been asked to get under test.

Apply the unit testing style and framework you are most comfortable with. You can choose to use stubs or mocks or none at all. If you do, you are free to use the mocking tool that you prefer.

  1. TirePressureMonitoringSystem exercise: write the unit tests for the Alarm class. The Alarm class is designed to monitor tire pressure and set an alarm if the pressure falls outside of the expected range. The Sensor class provided for the exercise fakes the behaviour of a real tire sensor, providing random but realistic values.

  2. HtmlTextConverter exercise: write the unit tests for the HtmlTextConverter class. The ToHtmlTextConverter class is designed to reformat a plain text file for display in a browser. For the Python and Java versions, there is an additional class "HtmlPagesConverter" which is slightly harder to get under test. It not only converts text in a file to html, it also supports pagination. It's meant as a follow up exercise.

  3. TicketDispenser exercise: write the unit tests for the TicketDispenser. The TicketDispenser class is designed to be used to manage a queuing system in a shop. There may be more than one ticket dispenser but the same ticket should not be issued to two different customers.

  4. TelemetrySystem exercise: write the unit tests for the TelemetryDiagnosticControls class. The responsibility of the TelemetryDiagnosticControls class is to establish a connection to the telemetry server (through the TelemetryClient), send a diagnostic request and successfully receive the response that contains the diagnostic info. The TelemetryClient class provided for the exercise fakes the behaviour of the real TelemetryClient class, and can respond with either the diagnostic information or a random sequence. The real TelemetryClient class would connect and communicate with the telemetry server via tcp/ip.

  5. Leaderboard exercise: (note this exercise is still being developed) Write the unit tests for the Leaderboard class, including races with self driving cars. The Leaderboard calculates driver points and rankings based on results from a number of races.

TDD with Mock Objects: Design Principles and Emerging Properties

This was originally a fork of Luca Minudel's repo. He was using it for a study of TDD and Design principles. I am using it as a repository for storing exercises useful for people wishing to improve their skills with TDD and SOLID principles. Please look at my blog post "SOLID principles and TDD" for background reading, or my book "The Coding Dojo Handbook".

  • When you've had a go at these exercises yourself, you could look at the proposed solutions in C#, Java, Javascript. If you've done the exercises in Python, you might be interested in my blog post "SOLID exercises in Python".

  • For background reading about Luca's study, see the paper and the presentation from Luca's own repo.

racing-car-katas's People

Contributors

a3dho3yn avatar agebhar1 avatar aortizpimentel avatar balp avatar boucardbruno avatar codecop avatar emilybache avatar endless8 avatar gimlet2 avatar hemalvarambhia avatar jbruggem avatar jobeylev avatar karlheinzkurt avatar kylemcmaster avatar lucaminudel avatar makomi avatar pen-y-fan avatar peterrhysthomas avatar pfichtner avatar pmiossec avatar pmiron avatar raget avatar seankilleen avatar selavy avatar tiagomartinho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

racing-car-katas's Issues

Update code

Hi Emily, I updated the Python porting of the exercises you provided.

If you like, take a look and let me know your feedback.

Soon will present this coding dojo at a conference, after that I will make available the slides for the exercises.

Luca

Different class name in Java project

Hi,
in the Java project "UnicodeFileToHtmlTextConverter" the class that should be tested it has been renamed to "HtmlTextConverter", maybe it's better to name it back to "UnicodeFileToHtmlTextConverter" to be coincise with the documentation.

TirePressureMonitoringSystem: case to reset the alarm.

Hello,

I did the Kata Car TirePressureMonitoringSystem in "java" version.

I think the case to reset the alarm is missing when you call 2 times the check function:

Alarm alarm = new Alarm()
alarm.check();
=> alarm is set to true
alarm.check();
=> Here the alarm is always on event if the sensor return false.

public void check()
    {
        double psiPressureValue = sensor.popNextPressurePsiValue();

        if (psiPressureValue < LowPressureThreshold || HighPressureThreshold < psiPressureValue)
        {
            alarmOn = true;
        }
    }

So, the code could be:

public void check()
    {
        double psiPressureValue = sensor.popNextPressurePsiValue();

        alarmOn = (psiPressureValue < LowPressureThreshold || HighPressureThreshold < psiPressureValue);
    }

Thank you.
Jérôme.

ruby code and require

Hi,

how do you expect the ruby test to be run?
I tried them but I had tho fix some require to require_relative in order to let them pass.

Am I doing something wrong?
Do you want a PR?

Pressure Monitoring Systems errors in golang version

Hi everyone,

In the Go version of the pressure monitoring systems exist an error in the 25 line of the sensor.go file because pressureTelemetryValue always will be the same value and is because s (in line 23) takes the same seed all the time, then, the value that assume is the same all the time.

In another hand, this kata doesn't is useful like a mocks exercise and is because to test the check function of the alarm, all that is needed is to create an instant of the alarm with different threshold, in the same way, is possible to create an instance of the sensor using anonymous functions to change the offset and samplePressure values, in that way is not needed to make a mock of anything.

Incorrect comparation operator

Comparing the two string like showed in the snippet of code below it's not a good way, unless you're comparing the instance of the string, but I don't think this is the case since String class is immutable.

public void send(String message)
{
    // ...
    if (message == DIAGNOSTIC_MESSAGE)
    // ...
}

It should be:

public void send(String message)
{
    // ...
    if (message.equals(DIAGNOSTIC_MESSAGE))
    // ...
}

The target class is TelemetryClient of project TelemetrySystem (Java version), line 44

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.