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

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

Issue 1634933005: tools/battor_agent: Fix unit test compile warnings on other platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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_agent_unittest.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.0f;
19 eeprom.r2 = 1; 19 eeprom.r2 = 1.0f;
20 eeprom.r3 = 1; 20 eeprom.r3 = 1.0f;
21 eeprom.low_gain = 1; 21 eeprom.low_gain = 1.0f;
22 eeprom.low_gain_correction_offset = 0; 22 eeprom.low_gain_correction_offset = 0.0f;
23 eeprom.low_gain_correction_factor = 1; 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, 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 }
39 39
40 TEST(BattOrSampleConverterTest, ToSampleNonZeroBaseline) { 40 TEST(BattOrSampleConverterTest, ToSampleNonZeroBaseline) {
41 BattOrEEPROM eeprom; 41 BattOrEEPROM eeprom;
42 eeprom.r1 = 1; 42 eeprom.r1 = 1.0f;
43 eeprom.r2 = 1; 43 eeprom.r2 = 1.0f;
44 eeprom.r3 = 1; 44 eeprom.r3 = 1.0f;
45 eeprom.low_gain = 1; 45 eeprom.low_gain = 1.0f;
46 eeprom.low_gain_correction_offset = 0; 46 eeprom.low_gain_correction_offset = 0.0f;
47 eeprom.low_gain_correction_factor = 1; 47 eeprom.low_gain_correction_factor = 1.0f;
48 eeprom.sd_sample_rate = 1000; 48 eeprom.sd_sample_rate = 1000;
49 49
50 // 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.
51 std::vector<RawBattOrSample> calibration_frame; 51 std::vector<RawBattOrSample> calibration_frame;
52 calibration_frame.push_back(RawBattOrSample{1024, 1024}); 52 calibration_frame.push_back(RawBattOrSample{1024, 1024});
53 BattOrSampleConverter converter(eeprom, calibration_frame); 53 BattOrSampleConverter converter(eeprom, calibration_frame);
54 54
55 // Set both the voltage and current to their max values. 55 // Set both the voltage and current to their max values.
56 RawBattOrSample raw_one{2048, 2048}; 56 RawBattOrSample raw_one{2048, 2048};
57 BattOrSample one = converter.ToSample(raw_one, 0); 57 BattOrSample one = converter.ToSample(raw_one, 0);
58 58
59 ASSERT_DOUBLE_EQ(0, one.time_ms); 59 ASSERT_DOUBLE_EQ(0, one.time_ms);
60 ASSERT_DOUBLE_EQ(1200.586223742061, one.voltage_mV); 60 ASSERT_DOUBLE_EQ(1200.586223742061, one.voltage_mV);
61 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA); 61 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA);
62 } 62 }
63 63
64 TEST(BattOrSampleConverterTest, ToSampleNonZeroMultiSampleBaseline) { 64 TEST(BattOrSampleConverterTest, ToSampleNonZeroMultiSampleBaseline) {
65 BattOrEEPROM eeprom; 65 BattOrEEPROM eeprom;
66 eeprom.r1 = 1; 66 eeprom.r1 = 1.0f;
67 eeprom.r2 = 1; 67 eeprom.r2 = 1.0f;
68 eeprom.r3 = 1; 68 eeprom.r3 = 1.0f;
69 eeprom.low_gain = 1; 69 eeprom.low_gain = 1.0f;
70 eeprom.low_gain_correction_offset = 0; 70 eeprom.low_gain_correction_offset = 0.0f;
71 eeprom.low_gain_correction_factor = 1; 71 eeprom.low_gain_correction_factor = 1.0f;
72 eeprom.sd_sample_rate = 1000; 72 eeprom.sd_sample_rate = 1000;
73 73
74 // 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.
75 std::vector<RawBattOrSample> calibration_frame; 75 std::vector<RawBattOrSample> calibration_frame;
76 calibration_frame.push_back(RawBattOrSample{1000, 1000}); 76 calibration_frame.push_back(RawBattOrSample{1000, 1000});
77 calibration_frame.push_back(RawBattOrSample{1048, 1048}); 77 calibration_frame.push_back(RawBattOrSample{1048, 1048});
78 BattOrSampleConverter converter(eeprom, calibration_frame); 78 BattOrSampleConverter converter(eeprom, calibration_frame);
79 79
80 // Set both the voltage and current to their max values. 80 // Set both the voltage and current to their max values.
81 RawBattOrSample raw_one{2048, 2048}; 81 RawBattOrSample raw_one{2048, 2048};
82 BattOrSample one = converter.ToSample(raw_one, 0); 82 BattOrSample one = converter.ToSample(raw_one, 0);
83 83
84 ASSERT_DOUBLE_EQ(0, one.time_ms); 84 ASSERT_DOUBLE_EQ(0, one.time_ms);
85 ASSERT_DOUBLE_EQ(1200.5862237420615, one.voltage_mV); 85 ASSERT_DOUBLE_EQ(1200.5862237420615, one.voltage_mV);
86 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA); 86 ASSERT_DOUBLE_EQ(600.29311187103076, one.current_mA);
87 } 87 }
88 88
89 TEST(BattOrSampleConverterTest, ToSampleRealValues) { 89 TEST(BattOrSampleConverterTest, ToSampleRealValues) {
90 BattOrEEPROM eeprom; 90 BattOrEEPROM eeprom;
91 eeprom.r1 = 10; 91 eeprom.r1 = 10.0f;
92 eeprom.r2 = 14; 92 eeprom.r2 = 14.0f;
93 eeprom.r3 = 17; 93 eeprom.r3 = 17.0f;
94 eeprom.low_gain = 1.5; 94 eeprom.low_gain = 1.5;
95 eeprom.low_gain_correction_offset = 0.03; 95 eeprom.low_gain_correction_offset = 0.03f;
96 eeprom.low_gain_correction_factor = 4; 96 eeprom.low_gain_correction_factor = 4.0f;
97 eeprom.sd_sample_rate = 1000; 97 eeprom.sd_sample_rate = 1000;
98 98
99 // 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.
100 std::vector<RawBattOrSample> calibration_frame; 100 std::vector<RawBattOrSample> calibration_frame;
101 calibration_frame.push_back(RawBattOrSample{800, 900}); 101 calibration_frame.push_back(RawBattOrSample{800, 900});
102 calibration_frame.push_back(RawBattOrSample{1000, 1100}); 102 calibration_frame.push_back(RawBattOrSample{1000, 1100});
103 BattOrSampleConverter converter(eeprom, calibration_frame); 103 BattOrSampleConverter converter(eeprom, calibration_frame);
104 104
105 // Set both the voltage and current to their max values. 105 // Set both the voltage and current to their max values.
106 RawBattOrSample raw_one{1900, 2000}; 106 RawBattOrSample raw_one{1900, 2000};
107 BattOrSample one = converter.ToSample(raw_one, 0); 107 BattOrSample one = converter.ToSample(raw_one, 0);
108 108
109 ASSERT_DOUBLE_EQ(0, one.time_ms); 109 ASSERT_DOUBLE_EQ(0, one.time_ms);
110 ASSERT_DOUBLE_EQ(1068.996209287540, one.voltage_mV); 110 ASSERT_DOUBLE_EQ(1068.996209287540, one.voltage_mV);
111 ASSERT_DOUBLE_EQ(9.7628957011935285, one.current_mA); 111 ASSERT_DOUBLE_EQ(9.7628957011935285, one.current_mA);
112 } 112 }
113 113
114 TEST(BattOrSampleConverterTest, ToSampleRealNegativeValues) { 114 TEST(BattOrSampleConverterTest, ToSampleRealNegativeValues) {
115 BattOrEEPROM eeprom; 115 BattOrEEPROM eeprom;
116 eeprom.r1 = 10; 116 eeprom.r1 = 10.0f;
117 eeprom.r2 = 14; 117 eeprom.r2 = 14.0f;
118 eeprom.r3 = 17; 118 eeprom.r3 = 17.0f;
119 eeprom.low_gain = 1.5; 119 eeprom.low_gain = 1.5;
120 eeprom.low_gain_correction_offset = 0.03; 120 eeprom.low_gain_correction_offset = 0.03f;
121 eeprom.low_gain_correction_factor = 4; 121 eeprom.low_gain_correction_factor = 4.0f;
122 eeprom.sd_sample_rate = 1000; 122 eeprom.sd_sample_rate = 1000;
123 123
124 // 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.
125 std::vector<RawBattOrSample> calibration_frame; 125 std::vector<RawBattOrSample> calibration_frame;
126 calibration_frame.push_back(RawBattOrSample{800, 900}); 126 calibration_frame.push_back(RawBattOrSample{800, 900});
127 BattOrSampleConverter converter(eeprom, calibration_frame); 127 BattOrSampleConverter converter(eeprom, calibration_frame);
128 128
129 // Set both the voltage and current to their max values. 129 // Set both the voltage and current to their max values.
130 RawBattOrSample raw_one{-1900, -2000}; 130 RawBattOrSample raw_one{-1900, -2000};
131 BattOrSample one = converter.ToSample(raw_one, 0); 131 BattOrSample one = converter.ToSample(raw_one, 0);
132 132
133 ASSERT_DOUBLE_EQ(0, one.time_ms); 133 ASSERT_DOUBLE_EQ(0, one.time_ms);
134 ASSERT_DOUBLE_EQ(-2885.2980205462577, one.voltage_mV); 134 ASSERT_DOUBLE_EQ(-2885.2980205462577, one.voltage_mV);
135 ASSERT_DOUBLE_EQ(-28.332106130755665, one.current_mA); 135 ASSERT_DOUBLE_EQ(-28.332106130755665, one.current_mA);
136 } 136 }
137 137
138 TEST(BattOrSampleConverterTest, ToSampleMultipleSamples) { 138 TEST(BattOrSampleConverterTest, ToSampleMultipleSamples) {
139 BattOrEEPROM eeprom; 139 BattOrEEPROM eeprom;
140 eeprom.r1 = 1; 140 eeprom.r1 = 1.0f;
141 eeprom.r2 = 1; 141 eeprom.r2 = 1.0f;
142 eeprom.r3 = 1; 142 eeprom.r3 = 1.0f;
143 eeprom.low_gain = 1; 143 eeprom.low_gain = 1.0f;
144 eeprom.low_gain_correction_offset = 0; 144 eeprom.low_gain_correction_offset = 0.0f;
145 eeprom.low_gain_correction_factor = 1; 145 eeprom.low_gain_correction_factor = 1.0f;
146 eeprom.sd_sample_rate = 50; 146 eeprom.sd_sample_rate = 50;
147 147
148 std::vector<RawBattOrSample> calibration_frame; 148 std::vector<RawBattOrSample> calibration_frame;
149 calibration_frame.push_back(RawBattOrSample{0, 0}); 149 calibration_frame.push_back(RawBattOrSample{0, 0});
150 BattOrSampleConverter converter(eeprom, calibration_frame); 150 BattOrSampleConverter converter(eeprom, calibration_frame);
151 151
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
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_agent_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698