Skip to content

Commit

Permalink
TirePressureMonitoring/Cpp Added Cpp porting from Emily racing kata repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaminudel committed Nov 16, 2014
1 parent 82c60f0 commit 4abda94
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
18 changes: 18 additions & 0 deletions TDDMicroExercises/Cpp/TirePressureMonitoring/Alarm.hpp
@@ -0,0 +1,18 @@
#include "sensor.hpp"

using namespace std;

class Alarm
{
public:
Alarm();
void check();
bool isAlarmOn();

protected:
Sensor sensor;
double lowPressureTreshold;
double highPressureTreshold;
bool alarmOn;
};

27 changes: 27 additions & 0 deletions TDDMicroExercises/Cpp/TirePressureMonitoring/alarm.cpp
@@ -0,0 +1,27 @@
#include "alarm.hpp"
#include "sensor.hpp"

Alarm::Alarm()
{
sensor = Sensor();
lowPressureTreshold = 17;
highPressureTreshold = 21;
alarmOn = false;
}

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

if (psiPressureValue < lowPressureTreshold || highPressureTreshold < psiPressureValue)
{
alarmOn = true;
}
}

bool Alarm::isAlarmOn()
{
return alarmOn;
}


18 changes: 18 additions & 0 deletions TDDMicroExercises/Cpp/TirePressureMonitoring/sensor.cpp
@@ -0,0 +1,18 @@
#include "sensor.hpp"

#include <cstdlib>
#include <time.h>

using namespace std;

Sensor::Sensor()
{
srand((unsigned)time(0));
}

double Sensor::popNextPressurePsiValue()
{
// placeholder implementation that simulates a real sensor in a real tire
double pressure = 16 + (float)rand()/((float)RAND_MAX/(6));
return pressure;
}
10 changes: 10 additions & 0 deletions TDDMicroExercises/Cpp/TirePressureMonitoring/sensor.hpp
@@ -0,0 +1,10 @@

using namespace std;

class Sensor
{
public:
Sensor();
double popNextPressurePsiValue();

};

0 comments on commit 4abda94

Please sign in to comment.