Skip to content

Commit fb315e2

Browse files
committed
fix: resolve test errors
1 parent 3a617c6 commit fb315e2

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/CycleComputer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "Config.h"
43
#include "domain/Clock.h"
54
#include "domain/Trip.h"
65
#include "ui/Input.h"

tests/host/CycleComputerTest.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,15 @@ TEST_F(CycleComputerTest, ResetData) {
182182
EXPECT_CALL(mockBtnA, isPressed()).WillOnce(Return(true)).WillRepeatedly(Return(false));
183183
computer->update(); // Change Mode
184184

185+
// Simulate BTN_BOTH: (A Pressed && B Held) OR (B Pressed && A Held)
186+
mockGnss.setSpeed(0.0f);
187+
185188
// Simulate BTN_BOTH: (A Pressed && B Held) OR (B Pressed && A Held)
186189
EXPECT_CALL(mockBtnA, isPressed()).WillOnce(Return(true)).RetiresOnSaturation();
187190
EXPECT_CALL(mockBtnB, isHeld()).WillOnce(Return(true)).RetiresOnSaturation();
188191

189-
computer->update();
190-
191-
mockGnss.setSpeed(0.0f);
192-
192+
// Expect the display to update with "0.0" after reset
193193
EXPECT_CALL(mockDisplay, print(testing::HasSubstr("0.0"))).Times(AtLeast(1));
194194

195-
delay(1000); // Advance time to trigger display update
196195
computer->update();
197196
}

tests/host/TripTest.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,9 @@ TEST_F(TripTest, IgnoreLowSpeed) {
5151
EXPECT_FLOAT_EQ(trip.getDistanceKm(), 0.0f);
5252
}
5353

54-
TEST_F(TripTest, TimeFormatting) {
55-
char buffer[32];
56-
54+
TEST_F(TripTest, MovingTimeCalculation) {
5755
// Test 0
58-
trip.getMovingTimeStr(buffer, sizeof(buffer));
59-
EXPECT_STREQ(buffer, "00:00");
56+
EXPECT_EQ(trip.getMovingTimeMs(), 0);
6057

6158
// Test 1h 1m 1s = 3600 + 60 + 1 = 3661 sec = 3661000 ms
6259
// Manually injecting moving time via update logic is hard without specific speed profile.
@@ -69,8 +66,7 @@ TEST_F(TripTest, TimeFormatting) {
6966
now += 3661000;
7067
trip.update(createNavData(10.0f), now); // Moving, so adds to moving time
7168

72-
trip.getMovingTimeStr(buffer, sizeof(buffer));
73-
EXPECT_STREQ(buffer, "01:01");
69+
EXPECT_EQ(trip.getMovingTimeMs(), 3661000);
7470
}
7571

7672
TEST_F(TripTest, CalculateAvgSpeed) {
@@ -111,15 +107,12 @@ TEST_F(TripTest, StopMovingDoesNotIncreaseMovingTime) {
111107
trip.update(createNavData(10.0f), now); // Moving for 1 hour
112108
// movingTime = 1h
113109

114-
char buffer[32];
115-
trip.getMovingTimeStr(buffer, sizeof(buffer));
116-
// 1h -> 01:00
117-
EXPECT_STREQ(buffer, "01:00");
110+
// 1h -> 3600000ms
111+
EXPECT_EQ(trip.getMovingTimeMs(), 3600000);
118112

119113
now += 3600000; // Another hour passes...
120114
trip.update(createNavData(0.0f), now); // ...but not moving
121115
// movingTime should stay 1h
122116

123-
trip.getMovingTimeStr(buffer, sizeof(buffer));
124-
EXPECT_STREQ(buffer, "01:00");
117+
EXPECT_EQ(trip.getMovingTimeMs(), 3600000);
125118
}

0 commit comments

Comments
 (0)