OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/battor_agent/battor_sample_converter.h" | 5 #include "tools/battor_agent/battor_sample_converter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/battor_agent/battor_protocol_types.h" | 10 #include "tools/battor_agent/battor_protocol_types.h" |
11 | 11 |
12 using namespace testing; | 12 using namespace testing; |
13 | 13 |
14 namespace battor { | 14 namespace battor { |
15 | 15 |
16 TEST(BattOrSampleConverterTest, ToSampleSimple) { | 16 TEST(BattOrSampleConverterTest, ToSampleSimple) { |
17 BattOrEEPROM eeprom; | 17 BattOrEEPROM eeprom; |
18 eeprom.r1 = 1.0f; | 18 eeprom.r1 = 1.0f; |
19 eeprom.r2 = 1.0f; | 19 eeprom.r2 = 1.0f; |
20 eeprom.r3 = 1.0f; | 20 eeprom.r3 = 1.0f; |
21 eeprom.low_gain = 1.0f; | 21 eeprom.low_gain = 1.0f; |
22 eeprom.low_gain_correction_offset = 0.0f; | 22 eeprom.low_gain_correction_offset = 0.0f; |
23 eeprom.low_gain_correction_factor = 1.0f; | 23 eeprom.low_gain_correction_factor = 1.0f; |
24 eeprom.sd_sample_rate = 1000; | 24 eeprom.sd_sample_rate = 1000; |
25 | 25 |
26 // Create a calibration frame with a baseline voltage and current of zero. | 26 // Create a calibration frame with a baseline voltage and current of zero. |
27 std::vector<RawBattOrSample> calibration_frame; | 27 std::vector<RawBattOrSample> calibration_frame; |
28 calibration_frame.push_back(RawBattOrSample{0.0, 0.0}); | 28 calibration_frame.push_back(RawBattOrSample{0, 0}); |
29 BattOrSampleConverter converter(eeprom, calibration_frame); | 29 BattOrSampleConverter converter(eeprom, calibration_frame); |
30 | 30 |
31 // Set both the voltage and current to their max values. | 31 // Set both the voltage and current to their max values. |
32 RawBattOrSample raw_one{2048, 2048}; | 32 RawBattOrSample raw_one{2048, 2048}; |
33 BattOrSample one = converter.ToSample(raw_one, 0); | 33 BattOrSample one = converter.ToSample(raw_one, 0); |
34 | 34 |
35 ASSERT_DOUBLE_EQ(0, one.time_ms); | 35 ASSERT_DOUBLE_EQ(0, one.time_ms); |
36 ASSERT_DOUBLE_EQ(2401.172447484123, one.voltage_mV); | 36 ASSERT_DOUBLE_EQ(2401.172447484123, one.voltage_mV); |
37 ASSERT_DOUBLE_EQ(1200.5862237420615, one.current_mA); | 37 ASSERT_DOUBLE_EQ(1200.5862237420615, one.current_mA); |
38 } | 38 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 BattOrSample one = converter.ToSample(RawBattOrSample{0, 0}, 0); | 152 BattOrSample one = converter.ToSample(RawBattOrSample{0, 0}, 0); |
153 BattOrSample two = converter.ToSample(RawBattOrSample{0, 0}, 1); | 153 BattOrSample two = converter.ToSample(RawBattOrSample{0, 0}, 1); |
154 BattOrSample three = converter.ToSample(RawBattOrSample{0, 0}, 2); | 154 BattOrSample three = converter.ToSample(RawBattOrSample{0, 0}, 2); |
155 | 155 |
156 ASSERT_DOUBLE_EQ(0, one.time_ms); | 156 ASSERT_DOUBLE_EQ(0, one.time_ms); |
157 ASSERT_DOUBLE_EQ(20, two.time_ms); | 157 ASSERT_DOUBLE_EQ(20, two.time_ms); |
158 ASSERT_DOUBLE_EQ(40, three.time_ms); | 158 ASSERT_DOUBLE_EQ(40, three.time_ms); |
159 } | 159 } |
160 | 160 |
161 } // namespace battor | 161 } // namespace battor |
OLD | NEW |