-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uplift logic from WaterPumpController to AdjustedWaterPump
- Loading branch information
1 parent
68fe43a
commit 632f423
Showing
9 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef ADJUSTEDWATERPUMP_H | ||
#define ADJUSTEDWATERPUMP_H | ||
#include <IWaterPump.h> | ||
#include <math.h> | ||
|
||
// lightweight wrapper around IWaterPump | ||
// its purpose is to adjust power value to the range of 0..255, for now | ||
class AdjustedWaterPump: public IWaterPump { | ||
private: | ||
const IWaterPumpPtr _pump; | ||
public: | ||
AdjustedWaterPump(IWaterPumpPtr pump) : _pump(pump) {} | ||
virtual ~AdjustedWaterPump() override {} | ||
|
||
virtual void setup() override { _pump->setup(); } | ||
virtual void stop() override { _pump->stop(); } | ||
virtual bool isRunning() const override { return _pump->isRunning(); } | ||
|
||
virtual void start(int powerInPercents) override { | ||
// convert percents to 0..255 range, using float | ||
const float power = (255.0f / 100.0f) * (float)powerInPercents; | ||
_pump->start(floor(power)); | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
controller/tea_poor/test/test_native/tests/AdjustedWaterPump_test.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <gtest/gtest.h> | ||
#include "mocks/FakeWaterPump.h" | ||
#include <AdjustedWaterPump.h> | ||
|
||
// test that pumps power passed as percents is converted to 0..255 range | ||
TEST(AdjustedWaterPump, test_pumps_power_passed_as_percents_is_converted_to_0_255_range) { | ||
const auto fakeWaterPump = std::make_shared<FakeWaterPump>(); | ||
AdjustedWaterPump adjustedWaterPump(fakeWaterPump); | ||
// list of pairs: (powerInPercents, expectedPower) | ||
const std::vector<std::pair<int, int>> tests = { | ||
{0, 0}, {1, 2}, {2, 5}, | ||
{50, 127}, {100, 255} | ||
}; | ||
for(const auto& test: tests) { | ||
adjustedWaterPump.start(test.first); | ||
ASSERT_EQ(fakeWaterPump->power(), test.second); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters