Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 1 | #include "pid/buildjson.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | TEST(ZoneFromJson, emptyZone) |
| 7 | { |
| 8 | // There is a zone key, but it's empty. |
| 9 | // This is technically invalid. |
| 10 | |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 11 | std::map<int64_t, conf::PIDConf> pidConfig; |
| 12 | std::map<int64_t, struct conf::ZoneConfig> zoneConfig; |
Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 13 | |
| 14 | auto j2 = R"( |
| 15 | { |
| 16 | "zones": [] |
| 17 | } |
| 18 | )"_json; |
| 19 | |
| 20 | std::tie(pidConfig, zoneConfig) = buildPIDsFromJson(j2); |
| 21 | |
| 22 | EXPECT_TRUE(pidConfig.empty()); |
| 23 | EXPECT_TRUE(zoneConfig.empty()); |
| 24 | } |
| 25 | |
| 26 | TEST(ZoneFromJson, oneZoneOnePid) |
| 27 | { |
| 28 | // Parse a valid configuration with one zone and one PID. |
| 29 | |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 30 | std::map<int64_t, conf::PIDConf> pidConfig; |
| 31 | std::map<int64_t, struct conf::ZoneConfig> zoneConfig; |
Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 32 | |
| 33 | auto j2 = R"( |
| 34 | { |
| 35 | "zones" : [{ |
| 36 | "id": 1, |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 37 | "minThermalOutput": 3000.0, |
Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 38 | "failsafePercent": 75.0, |
| 39 | "pids": [{ |
| 40 | "name": "fan1-5", |
| 41 | "type": "fan", |
| 42 | "inputs": ["fan1", "fan5"], |
| 43 | "setpoint": 90.0, |
| 44 | "pid": { |
| 45 | "samplePeriod": 0.1, |
| 46 | "proportionalCoeff": 0.0, |
| 47 | "integralCoeff": 0.0, |
Patrick Venture | 903b042 | 2019-02-20 07:35:48 -0800 | [diff] [blame] | 48 | "feedFwdOffsetCoeff": 0.0, |
Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 49 | "feedFwdGainCoeff": 0.010, |
| 50 | "integralLimit_min": 0.0, |
| 51 | "integralLimit_max": 0.0, |
| 52 | "outLim_min": 30.0, |
| 53 | "outLim_max": 100.0, |
| 54 | "slewNeg": 0.0, |
| 55 | "slewPos": 0.0 |
| 56 | } |
| 57 | }] |
| 58 | }] |
| 59 | } |
| 60 | )"_json; |
| 61 | |
| 62 | std::tie(pidConfig, zoneConfig) = buildPIDsFromJson(j2); |
| 63 | EXPECT_EQ(pidConfig.size(), 1); |
| 64 | EXPECT_EQ(zoneConfig.size(), 1); |
| 65 | |
| 66 | EXPECT_EQ(pidConfig[1]["fan1-5"].type, "fan"); |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 67 | EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0); |
Patrick Venture | d149172 | 2019-02-08 14:37:45 -0800 | [diff] [blame] | 68 | } |