Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: lucaminudel/TDDwithMockObjectsAndDesignPrinciples
base: master
...
head fork: marciol/TDDwithMockObjectsAndDesignPrinciples
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
BIN  Paper/mockobjects_emergingproperties.pdf
Binary file not shown
View
BIN  Paper/mockobjects_emergingproperties_finaldraft.pdf
Binary file not shown
View
17 Questionnaire/README.md
@@ -1,17 +0,0 @@
-# Questionnaire
-
-## [ENG]
-
-To start the questionnaire in English, [click here] (http://tool.surveypirate.com/Survey.aspx?surveyid=25731&sp.mac=DomDcdUgTB8gwbR5uWLCIg%3d%3d)
-
-But first send your solution of the [TDD micro-exercises] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises).
-
-
-
-
-## [ITA]
-
-Per iniziare il questionario in Italiano, [clicca qui] (http://tool.surveypirate.com/Survey.aspx?surveyid=25808&sp.mac=yMAXSLB8yJuht8rRsJCdoA%3d%3d)
-
-Ma prima invia la tua soluzione dei [micro-esercizi di TDD] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises).
-
View
13 README.md
@@ -1,11 +1,10 @@
# TDD with Mock Objects: Design Principles and Emerging Properties
-Here you can find:
+This is a fork of Luca Minudel's original repo. He was using it for a study of TDD and Design principles. I am using it as a repository for storing four exercises useful for people wishing to improve their skills with TDD and SOLID principles. Please look at my blog post ["SOLID principles and TDD"](http://emilybache.blogspot.com/2012/09/solid-principles-and-tdd.html) for background reading, or my book ["The Coding Dojo Handbook"](http://leanpub.com/codingdojohandbook).
-- the [paper] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/blob/master/Paper/mockobjects_emergingproperties.pdf?raw=true)
-- the [presentation] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/blob/master/Slides/TDD-SOLID.pdf?raw=true)
-- the code of [TDD micro-exercises] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises) (C#, JavaScript)
-- a [proposed solution] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises.ProposedSolution)
-- share [your solution] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises.YoursSolutions)
+- If you just want to do the exercises, copy the starting code of the [TDD micro-exercises] (https://github.com/emilybache/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises) in C#, Java, Javascript or Python. It's the same exercises, just translated into the various languages.
+
+- When you've had a go yourself, you could look at [proposed solutions] (https://github.com/emilybache/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises.ProposedSolution) in C#, Java, Javascript. If you've done the exercises in Python, you might be interested in my blog post ["SOLID exercises in Python"](http://emilybache.blogspot.fi/2012/09/solid-exercises-in-python.html).
+
+- For background reading about Luca's study, see the [paper] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/blob/master/Paper/mockobjects_emergingproperties.pdf?raw=true) and the [presentation] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/blob/master/Slides/TDD-SOLID.pdf?raw=true) from Luca's own repo.
-The complete Java version of the TDD micro-exercises and of the proposed solution soon available, porting underway by [peterrhysthomas] (https://github.com/peterrhysthomas).
View
BIN  Slides/TDD-SOLID.pdf
Binary file not shown
View
10 TDDMicroExercises.YoursSolutions/README.md
@@ -1,10 +0,0 @@
-# TDD micro-exercises
-
-## Your solution
-
-1. Fork the repository
-1. Add a folder with your name here
-1. Pull your solution
-1. Be social, comment and discuss it
-
-
View
148 TDDMicroExercises/CSharp/TelemetrySystem/TelemetryClient.cs
@@ -2,92 +2,92 @@
namespace TDDMicroExercises.TelemetrySystem
{
- public class TelemetryClient
- {
- public const string DiagnosticMessage = "AT#UD";
+ public class TelemetryClient
+ {
+ public const string DiagnosticMessage = "AT#UD";
- private bool _onlineStatus;
- private string _diagnosticMessageResult = string.Empty;
+ private bool _onlineStatus;
+ private string _diagnosticMessageResult = string.Empty;
- private readonly Random _connectionEventsSimulator = new Random(42);
+ private readonly Random _connectionEventsSimulator = new Random(42);
- public bool OnlineStatus
- {
- get { return _onlineStatus; }
- }
+ public bool OnlineStatus
+ {
+ get { return _onlineStatus; }
+ }
- public void Connect(string telemetryServerConnectionString)
- {
- if (string.IsNullOrEmpty(telemetryServerConnectionString))
- {
- throw new ArgumentNullException();
- }
+ public void Connect(string telemetryServerConnectionString)
+ {
+ if (string.IsNullOrEmpty(telemetryServerConnectionString))
+ {
+ throw new ArgumentNullException();
+ }
- // simulate the operation on a real modem
- bool success = _connectionEventsSimulator.Next(1, 10) <= 8;
+ // simulate the operation on a real modem
+ bool success = _connectionEventsSimulator.Next(1, 10) <= 8;
- _onlineStatus = success;
+ _onlineStatus = success;
- }
+ }
- public void Disconnect()
- {
- _onlineStatus = false;
- }
+ public void Disconnect()
+ {
+ _onlineStatus = false;
+ }
- public void Send(string message)
- {
- if (string.IsNullOrEmpty(message))
- {
- throw new ArgumentNullException();
- }
+ public void Send(string message)
+ {
+ if (string.IsNullOrEmpty(message))
+ {
+ throw new ArgumentNullException();
+ }
- if (message == DiagnosticMessage)
- {
- // simulate a status report
- _diagnosticMessageResult =
- "LAST TX rate................ 100 MBPS\r\n"
- + "HIGHEST TX rate............. 100 MBPS\r\n"
- + "LAST RX rate................ 100 MBPS\r\n"
- + "HIGHEST RX rate............. 100 MBPS\r\n"
- + "BIT RATE.................... 100000000\r\n"
- + "WORD LEN.................... 16\r\n"
- + "WORD/FRAME.................. 511\r\n"
- + "BITS/FRAME.................. 8192\r\n"
- + "MODULATION TYPE............. PCM/FM\r\n"
- + "TX Digital Los.............. 0.75\r\n"
- + "RX Digital Los.............. 0.10\r\n"
- + "BEP Test.................... -5\r\n"
- + "Local Rtrn Count............ 00\r\n"
- + "Remote Rtrn Count........... 00";
+ if (message == DiagnosticMessage)
+ {
+ // simulate a status report
+ _diagnosticMessageResult =
+ "LAST TX rate................ 100 MBPS\r\n"
+ + "HIGHEST TX rate............. 100 MBPS\r\n"
+ + "LAST RX rate................ 100 MBPS\r\n"
+ + "HIGHEST RX rate............. 100 MBPS\r\n"
+ + "BIT RATE.................... 100000000\r\n"
+ + "WORD LEN.................... 16\r\n"
+ + "WORD/FRAME.................. 511\r\n"
+ + "BITS/FRAME.................. 8192\r\n"
+ + "MODULATION TYPE............. PCM/FM\r\n"
+ + "TX Digital Los.............. 0.75\r\n"
+ + "RX Digital Los.............. 0.10\r\n"
+ + "BEP Test.................... -5\r\n"
+ + "Local Rtrn Count............ 00\r\n"
+ + "Remote Rtrn Count........... 00";
- return;
- }
-
- // here should go the real Send operation
- }
+ return;
+ }
+
+ // here should go the real Send operation
+ }
- public string Receive()
- {
- string message;
+ public string Receive()
+ {
+ string message;
- if (string.IsNullOrEmpty(_diagnosticMessageResult) == false)
- {
- message = _diagnosticMessageResult;
- _diagnosticMessageResult = string.Empty;
- }
- else
- {
- // simulate a received message
- message = string.Empty;
- int messageLenght = _connectionEventsSimulator.Next(50, 110);
- for(int i = messageLenght; i >=0; --i)
- {
- message += (char)_connectionEventsSimulator.Next(40, 126);
- }
- }
+ if (string.IsNullOrEmpty(_diagnosticMessageResult) == false)
+ {
+ message = _diagnosticMessageResult;
+ _diagnosticMessageResult = string.Empty;
+ }
+ else
+ {
+ // simulate a received message
+ message = string.Empty;
+ int messageLenght = _connectionEventsSimulator.Next(50, 110);
+ for(int i = messageLenght; i >=0; --i)
+ {
+ message += (char)_connectionEventsSimulator.Next(40, 126);
+ }
+ }
- return message;
- }
- }
+ return message;
+ }
+ }
}
View
4 ...Java/TelemetrySystem/src/main/java/tddmicroexercises/telemetrysystem/TelemetryClient.java
@@ -63,7 +63,7 @@ public void send(String message)
return;
}
- // here should go the real Send operation
+ // here should go the real Send operation (not needed for this exercise)
}
public String receive()
@@ -72,7 +72,7 @@ public String receive()
if (diagnosticMessageResult == null || "".equals(diagnosticMessageResult))
{
- // simulate a received message
+ // simulate a received message (just for illustration - not needed for this exercise)
message = "";
int messageLength = connectionEventsSimulator.nextInt(50) + 60;
for(int i = messageLength; i >=0; --i)
View
2  ...eMonitoringSystem/src/main/java/tddmicroexercises/tirepressuremonitoringsystem/Alarm.java
@@ -8,7 +8,6 @@
Sensor sensor = new Sensor();
boolean alarmOn = false;
- private long alarmCount = 0;
public void check()
{
@@ -17,7 +16,6 @@ public void check()
if (psiPressureValue < LowPressureTreshold || HighPressureTreshold < psiPressureValue)
{
alarmOn = true;
- alarmCount += 1;
}
}
View
4 TDDMicroExercises/Javascript/telemetry-system/telemetry-client.js
@@ -63,7 +63,7 @@ TelemetryClient.prototype = {
return;
}
- // here should go the real Send operation
+ // here should go the real Send operation (not needed for this exercise)
},
receive: function () {
@@ -71,7 +71,7 @@ TelemetryClient.prototype = {
if (typeof (this._diagnosticMessageResult) === 'undefined' || this._diagnosticMessageResult === '') {
- // simulate a received message
+ // simulate a received message (just for illustration - not needed for this exercise)
message = '';
var messageLenght = this._connectionEventsSimulator(50, 110);
for(var i = messageLenght; i >=0; --i) {
View
2  TDDMicroExercises/Javascript/tire-pressure-monitoring-system/alarm.js
@@ -5,7 +5,6 @@ Alarm = function() {
this._highPressureTreshold = 21;
this._sensor = new Sensor();
this._alarmOn = false;
- this._alarmCount = 0;
};
Alarm.prototype = {
@@ -17,7 +16,6 @@ Alarm.prototype = {
if (psiPressureValue < this._lowPressureTreshold || this._highPressureTreshold < psiPressureValue)
{
this._alarmOn = true;
- this._alarmCount += 1;
}
},
View
33 TDDMicroExercises/README.md
@@ -2,27 +2,42 @@
## Instructions
-Here follow 4 distinct problems. They could be code you inherited from a legacy code-base. Now you want to write unit tests for them, and to do so you will need to do some refactoring. Take care when refactoring not to change interfaces which client code may rely on. 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.
+Here follow 4 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.
-1. **TirePressureMonitoringSystem exercise**: write the unit tests for the Alarm class, refactor the code as much as you need to make the class testable
+For each exercise, 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. Identify why the class is hard to write tests for, and which SOLID principles are not being followed.
-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.
+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. Add more tests to cover the functionality of the particular class you've been asked to get under test.
-2. **UnicodeFileToHtmTextConverter exercise**: write the unit tests for the UnicodeFileToHtmTextConverter class, refactor the code as much as you need to make the class testable.
+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. Note that there is a MockAlarm and a StubAlarm class provided in the "tests" folder. The purpose of these is purely to demonstrate how a mock and a stub look, you won't need them to complete the exercise.
+
+2. **UnicodeFileToHtmTextConverter exercise**: write the unit tests for the UnicodeFileToHtmTextConverter class.
The UnicodeFileToHtmTextConverter class is designed to reformat a plain text file for display in a browser.
-3. **TelemetrySystem exercise**: write the unit tests for the TelemetryDiagnosticControls class, refactor the code as much as you need to make the class testable.
+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 behavior 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.
-4. **TicketDispenser exercise**: write the unit tests for the TicketDispenser, refactor the code as much as you need to make the class testable
+## Get going quickly with Cyber-Dojo
-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.
+You can quickly and easily get going with these problems using the cyber-dojo tool. Click on the relevant link below
+to create a new cyber-dojo practice id with the problem set up ready for your dojo.
+1. TirePressureMonitoringSystem in [C#](http://cyber-dojo.com/forker/fork/634DA0F51B?avatar=zebra&tag=12)
+2. UnicodeFileToHtmlTextConverter in [C#](http://cyber-dojo.com/forker/fork/D98B8E5B4B?avatar=moose&tag=8)
+3. TurnTicketDispenser in [C#](http://cyber-dojo.com/forker/fork/BBC507B3D9?avatar=koala&tag=3)
+4. TelemetrySystem in [C#](http://cyber-dojo.com/forker/fork/5566B141D6?avatar=elephant&tag=3)
-## A possible solution
+## After you've had a go yourself
-Here you find one of the possible solutions for the exercise: [proposed solution.] (https://github.com/lucaminudel/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises.ProposedSolution)
+Here you find possible solutions for the exercises: [proposed solution.] (https://github.com/emilybache/TDDwithMockObjectsAndDesignPrinciples/tree/master/TDDMicroExercises.ProposedSolution)
Feel free to send your comments and questions.
View
39 TDDMicroExercises/python/TelemetrySystem/telemetry.py
@@ -5,30 +5,26 @@ class TelemetryClient(object):
def __init__(self):
self.online_status = False
- self.diagnostic_message_result = ""
-
- def get_online_status(self):
- return self.online_status
+ self._diagnostic_message_result = ""
def connect(self, telemetry_server_connection_string):
- if (telemetry_server_connection_string is None or telemetry_server_connection_string == ""):
+ if not telemetry_server_connection_string:
raise Exception()
# simulate the operation on a real modem
success = random.randint(0, 10) <= 8
-
self.online_status = success
def disconnect(self):
self.online_status = False
def send(self, message):
- if (message is None or message == ""):
+ if not message:
raise Exception()
- if (message == TelemetryClient.DIAGNOSTIC_MESSAGE):
+ if message == TelemetryClient.DIAGNOSTIC_MESSAGE:
# simulate a status report
- self.diagnostic_message_result = """\
+ self._diagnostic_message_result = """\
LAST TX rate................ 100 MBPS\r\n
HIGHEST TX rate............. 100 MBPS\r\n
LAST RX rate................ 100 MBPS\r\n
@@ -45,11 +41,11 @@ def send(self, message):
Remote Rtrn Count........... 00"""
return
- # here should go the real Send operation
+ # here should go the real Send operation (not needed for this exercise)
def receive(self):
- if (self.diagnostic_message_result is None or self.diagnostic_message_result == ""):
- # simulate a received message
+ if not self._diagnostic_message_result:
+ # simulate a received message (just for illustration - not needed for this exercise)
message = ""
messageLength = random.randint(0, 50) + 60
i = messageLength
@@ -57,8 +53,8 @@ def receive(self):
message += chr((random.randint(0, 40) + 86))
i -= 1
else:
- message = self.diagnostic_message_result
- self.diagnostic_message_result = ""
+ message = self._diagnostic_message_result
+ self._diagnostic_message_result = ""
return message
@@ -66,23 +62,22 @@ class TelemetryDiagnosticControls:
DiagnosticChannelConnectionString = "*111#"
def __init__(self):
- self.telemetry_client = TelemetryClient()
+ self._telemetry_client = TelemetryClient()
self.diagnostic_info = ""
def check_transmission(self):
self.diagnostic_info = ""
-
- self.telemetry_client.disconnect()
+ self._telemetry_client.disconnect()
retryLeft = 3
- while (self.telemetry_client.get_online_status() == False and retryLeft > 0):
- self.telemetry_client.connect(TelemetryDiagnosticControls.DiagnosticChannelConnectionString)
+ while ((not self._telemetry_client.online_status) and retryLeft > 0):
+ self._telemetry_client.connect(TelemetryDiagnosticControls.DiagnosticChannelConnectionString)
retryLeft -= 1
- if telemetry_client.get_online_status() == False:
+ if not self._telemetry_client.online_status:
raise Exception("Unable to connect.")
- self.telemetry_client.send(TelemetryClient.DIAGNOSTIC_MESSAGE)
- self.diagnostic_info = self.telemetry_client.receive()
+ self._telemetry_client.send(TelemetryClient.DIAGNOSTIC_MESSAGE)
+ self.diagnostic_info = self._telemetry_client.receive()
View
12 TDDMicroExercises/python/TirePressureMonitoringSystem/tire_pressure_monitoring.py
@@ -21,11 +21,13 @@ def __init__(self):
self._low_pressure_threshold = 17
self._high_pressure_threshold = 21
self._sensor = Sensor()
- self.is_alarm_on = False
- self._alarm_count = 0
-
+ self._is_alarm_on = False
+
def check(self):
psi_pressure_value = self._sensor.pop_next_pressure_psi_value()
if psi_pressure_value < self._low_pressure_threshold or self._high_pressure_threshold < psi_pressure_value:
- self.is_alarm_on = True
- self._alarm_count += 1
+ self._is_alarm_on = True
+
+ @property
+ def is_alarm_on(self):
+ return self._is_alarm_on

No commit comments for this range

Something went wrong with that request. Please try again.