Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: tools/battor_agent/battor_sample_converter_unittest.cc

Issue 1586173002: tools/battor_agent: Prints real BattOr samples instead of raw ones (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_eeprom
Patch Set: Fixed size_t build error Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/battor_agent/battor_sample_converter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 18 eeprom.r1 = 1;
19 eeprom.r2 = 1; 19 eeprom.r2 = 1;
20 eeprom.r3 = 1; 20 eeprom.r3 = 1;
21 eeprom.low_gain = 1; 21 eeprom.low_gain = 1;
22 eeprom.low_gain_correction_offset = 0; 22 eeprom.low_gain_correction_offset = 0;
23 eeprom.low_gain_correction_factor = 1; 23 eeprom.low_gain_correction_factor = 1;
24 eeprom.sd_sample_rate = 1000;
24 25
25 // 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.
26 std::vector<RawBattOrSample> calibration_frame; 27 std::vector<RawBattOrSample> calibration_frame;
27 calibration_frame.push_back(RawBattOrSample{0.0, 0.0}); 28 calibration_frame.push_back(RawBattOrSample{0.0, 0.0});
28 BattOrSampleConverter converter(eeprom, calibration_frame); 29 BattOrSampleConverter converter(eeprom, calibration_frame);
29 30
30 // Set both the voltage and current to their max values. 31 // Set both the voltage and current to their max values.
31 RawBattOrSample raw_one{2048, 2048}; 32 RawBattOrSample raw_one{2048, 2048};
32 BattOrSample one = converter.ToSample(raw_one); 33 BattOrSample one = converter.ToSample(raw_one, 0);
33 34
35 ASSERT_DOUBLE_EQ(0, one.time_ms);
34 ASSERT_DOUBLE_EQ(2401.172447484123, one.voltage_mV); 36 ASSERT_DOUBLE_EQ(2401.172447484123, one.voltage_mV);
35 ASSERT_DOUBLE_EQ(1200.5862237420615, one.current_mA); 37 ASSERT_DOUBLE_EQ(1200.5862237420615, one.current_mA);
36 } 38 }
37 39
38 TEST(BattOrSampleConverterTest, ToSampleNonZeroBaseline) { 40 TEST(BattOrSampleConverterTest, ToSampleNonZeroBaseline) {
39 BattOrEEPROM eeprom; 41 BattOrEEPROM eeprom;
40 eeprom.r1 = 1; 42 eeprom.r1 = 1;
41 eeprom.r2 = 1; 43 eeprom.r2 = 1;
42 eeprom.r3 = 1; 44 eeprom.r3 = 1;
43 eeprom.low_gain = 1; 45 eeprom.low_gain = 1;
44 eeprom.low_gain_correction_offset = 0; 46 eeprom.low_gain_correction_offset = 0;
45 eeprom.low_gain_correction_factor = 1; 47 eeprom.low_gain_correction_factor = 1;
48 eeprom.sd_sample_rate = 1000;
46 49
47 // Create a calibration frame with a baseline voltage and current of zero. 50 // Create a calibration frame with a baseline voltage and current of zero.
48 std::vector<RawBattOrSample> calibration_frame; 51 std::vector<RawBattOrSample> calibration_frame;
49 calibration_frame.push_back(RawBattOrSample{1024, 1024}); 52 calibration_frame.push_back(RawBattOrSample{1024, 1024});
50 BattOrSampleConverter converter(eeprom, calibration_frame); 53 BattOrSampleConverter converter(eeprom, calibration_frame);
51 54
52 // Set both the voltage and current to their max values. 55 // Set both the voltage and current to their max values.
53 RawBattOrSample raw_one{2048, 2048}; 56 RawBattOrSample raw_one{2048, 2048};
54 BattOrSample one = converter.ToSample(raw_one); 57 BattOrSample one = converter.ToSample(raw_one, 0);
55 58
59 ASSERT_DOUBLE_EQ(0, one.time_ms);
56 ASSERT_DOUBLE_EQ(1200.586223742061, one.voltage_mV); 60 ASSERT_DOUBLE_EQ(1200.586223742061, one.voltage_mV);
57 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA); 61 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA);
58 } 62 }
59 63
60 TEST(BattOrSampleConverterTest, ToSampleNonZeroMultiSampleBaseline) { 64 TEST(BattOrSampleConverterTest, ToSampleNonZeroMultiSampleBaseline) {
61 BattOrEEPROM eeprom; 65 BattOrEEPROM eeprom;
62 eeprom.r1 = 1; 66 eeprom.r1 = 1;
63 eeprom.r2 = 1; 67 eeprom.r2 = 1;
64 eeprom.r3 = 1; 68 eeprom.r3 = 1;
65 eeprom.low_gain = 1; 69 eeprom.low_gain = 1;
66 eeprom.low_gain_correction_offset = 0; 70 eeprom.low_gain_correction_offset = 0;
67 eeprom.low_gain_correction_factor = 1; 71 eeprom.low_gain_correction_factor = 1;
72 eeprom.sd_sample_rate = 1000;
68 73
69 // Create a calibration frame with a baseline voltage and current of zero. 74 // Create a calibration frame with a baseline voltage and current of zero.
70 std::vector<RawBattOrSample> calibration_frame; 75 std::vector<RawBattOrSample> calibration_frame;
71 calibration_frame.push_back(RawBattOrSample{1000, 1000}); 76 calibration_frame.push_back(RawBattOrSample{1000, 1000});
72 calibration_frame.push_back(RawBattOrSample{1048, 1048}); 77 calibration_frame.push_back(RawBattOrSample{1048, 1048});
73 BattOrSampleConverter converter(eeprom, calibration_frame); 78 BattOrSampleConverter converter(eeprom, calibration_frame);
74 79
75 // Set both the voltage and current to their max values. 80 // Set both the voltage and current to their max values.
76 RawBattOrSample raw_one{2048, 2048}; 81 RawBattOrSample raw_one{2048, 2048};
77 BattOrSample one = converter.ToSample(raw_one); 82 BattOrSample one = converter.ToSample(raw_one, 0);
78 83
84 ASSERT_DOUBLE_EQ(0, one.time_ms);
79 ASSERT_DOUBLE_EQ(1200.5862237420615, one.voltage_mV); 85 ASSERT_DOUBLE_EQ(1200.5862237420615, one.voltage_mV);
80 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA); 86 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA);
81 } 87 }
82 88
83 TEST(BattOrSampleConverterTest, ToSampleRealValues) { 89 TEST(BattOrSampleConverterTest, ToSampleRealValues) {
84 BattOrEEPROM eeprom; 90 BattOrEEPROM eeprom;
85 eeprom.r1 = 10; 91 eeprom.r1 = 10;
86 eeprom.r2 = 14; 92 eeprom.r2 = 14;
87 eeprom.r3 = 17; 93 eeprom.r3 = 17;
88 eeprom.low_gain = 1.5; 94 eeprom.low_gain = 1.5;
89 eeprom.low_gain_correction_offset = 0.03; 95 eeprom.low_gain_correction_offset = 0.03;
90 eeprom.low_gain_correction_factor = 4; 96 eeprom.low_gain_correction_factor = 4;
97 eeprom.sd_sample_rate = 1000;
91 98
92 // Create a calibration frame with a baseline voltage and current of zero. 99 // Create a calibration frame with a baseline voltage and current of zero.
93 std::vector<RawBattOrSample> calibration_frame; 100 std::vector<RawBattOrSample> calibration_frame;
94 calibration_frame.push_back(RawBattOrSample{800, 900}); 101 calibration_frame.push_back(RawBattOrSample{800, 900});
95 calibration_frame.push_back(RawBattOrSample{1000, 1100}); 102 calibration_frame.push_back(RawBattOrSample{1000, 1100});
96 BattOrSampleConverter converter(eeprom, calibration_frame); 103 BattOrSampleConverter converter(eeprom, calibration_frame);
97 104
98 // Set both the voltage and current to their max values. 105 // Set both the voltage and current to their max values.
99 RawBattOrSample raw_one{1900, 2000}; 106 RawBattOrSample raw_one{1900, 2000};
100 BattOrSample one = converter.ToSample(raw_one); 107 BattOrSample one = converter.ToSample(raw_one, 0);
101 108
109 ASSERT_DOUBLE_EQ(0, one.time_ms);
102 ASSERT_DOUBLE_EQ(1068.996209287540, one.voltage_mV); 110 ASSERT_DOUBLE_EQ(1068.996209287540, one.voltage_mV);
103 ASSERT_DOUBLE_EQ(9.7628957011935285, one.current_mA); 111 ASSERT_DOUBLE_EQ(9.7628957011935285, one.current_mA);
104 } 112 }
105 113
106 TEST(BattOrSampleConverterTest, ToSampleRealNegativeValues) { 114 TEST(BattOrSampleConverterTest, ToSampleRealNegativeValues) {
107 BattOrEEPROM eeprom; 115 BattOrEEPROM eeprom;
108 eeprom.r1 = 10; 116 eeprom.r1 = 10;
109 eeprom.r2 = 14; 117 eeprom.r2 = 14;
110 eeprom.r3 = 17; 118 eeprom.r3 = 17;
111 eeprom.low_gain = 1.5; 119 eeprom.low_gain = 1.5;
112 eeprom.low_gain_correction_offset = 0.03; 120 eeprom.low_gain_correction_offset = 0.03;
113 eeprom.low_gain_correction_factor = 4; 121 eeprom.low_gain_correction_factor = 4;
122 eeprom.sd_sample_rate = 1000;
114 123
115 // Create a calibration frame with a baseline voltage and current of zero. 124 // Create a calibration frame with a baseline voltage and current of zero.
116 std::vector<RawBattOrSample> calibration_frame; 125 std::vector<RawBattOrSample> calibration_frame;
117 calibration_frame.push_back(RawBattOrSample{800, 900}); 126 calibration_frame.push_back(RawBattOrSample{800, 900});
118 BattOrSampleConverter converter(eeprom, calibration_frame); 127 BattOrSampleConverter converter(eeprom, calibration_frame);
119 128
120 // Set both the voltage and current to their max values. 129 // Set both the voltage and current to their max values.
121 RawBattOrSample raw_one{-1900, -2000}; 130 RawBattOrSample raw_one{-1900, -2000};
122 BattOrSample one = converter.ToSample(raw_one); 131 BattOrSample one = converter.ToSample(raw_one, 0);
123 132
133 ASSERT_DOUBLE_EQ(0, one.time_ms);
124 ASSERT_DOUBLE_EQ(-2885.2980205462577, one.voltage_mV); 134 ASSERT_DOUBLE_EQ(-2885.2980205462577, one.voltage_mV);
125 ASSERT_DOUBLE_EQ(-28.332106130755665, one.current_mA); 135 ASSERT_DOUBLE_EQ(-28.332106130755665, one.current_mA);
126 } 136 }
127 137
138 TEST(BattOrSampleConverterTest, ToSampleMultipleSamples) {
139 BattOrEEPROM eeprom;
140 eeprom.r1 = 1;
141 eeprom.r2 = 1;
142 eeprom.r3 = 1;
143 eeprom.low_gain = 1;
144 eeprom.low_gain_correction_offset = 0;
145 eeprom.low_gain_correction_factor = 1;
146 eeprom.sd_sample_rate = 50;
147
148 std::vector<RawBattOrSample> calibration_frame;
149 calibration_frame.push_back(RawBattOrSample{0, 0});
150 BattOrSampleConverter converter(eeprom, calibration_frame);
151
152 BattOrSample one = converter.ToSample(RawBattOrSample{0, 0}, 0);
153 BattOrSample two = converter.ToSample(RawBattOrSample{0, 0}, 1);
154 BattOrSample three = converter.ToSample(RawBattOrSample{0, 0}, 2);
155
156 ASSERT_DOUBLE_EQ(0, one.time_ms);
157 ASSERT_DOUBLE_EQ(20, two.time_ms);
158 ASSERT_DOUBLE_EQ(40, three.time_ms);
159 }
160
128 } // namespace battor 161 } // namespace battor
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_sample_converter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698