Debian Codegraph @

src/game/unittests/gearboxtest/gearboxtest.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2019 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "gearboxtest.hpp"
17 #include "gearbox.hpp"
18
19 GearboxTest::GearboxTest()
20 {
21 }
22
23 void GearboxTest::testInit()
24 {
25 Gearbox gb;
26
27 QVERIFY(gb.gear() == Gearbox::Gear::Neutral);
28 }
29
30 void GearboxTest::testGearForward()
31 {
32 Gearbox gb;
33
34 gb.setAcceleratorEnabled(true);
35 gb.update(1);
36
37 QVERIFY(gb.gear() == Gearbox::Gear::Forward);
38 }
39
40 void GearboxTest::testGearReverse()
41 {
42 Gearbox gb;
43
44 gb.setAcceleratorEnabled(true);
45 gb.update(1);
46
47 QVERIFY(gb.gear() == Gearbox::Gear::Forward);
48
49 gb.setAcceleratorEnabled(false);
50 gb.setBrakeEnabled(true);
51
52 gb.update(1);
53
54 QVERIFY(gb.gear() == Gearbox::Gear::Forward);
55
56 gb.update(0);
57
58 for (int i = 0; i < 31; i++)
59 {
60 QVERIFY(gb.gear() == Gearbox::Gear::Stop);
61
62 gb.update(0);
63 }
64
65 QVERIFY(gb.gear() == Gearbox::Gear::Reverse);
66
67 gb.setBrakeEnabled(false);
68 gb.setAcceleratorEnabled(false);
69 gb.update(1);
70
71 QVERIFY(gb.gear() == Gearbox::Gear::Neutral);
72
73 gb.setBrakeEnabled(false);
74 gb.setAcceleratorEnabled(true);
75 gb.update(1);
76
77 QVERIFY(gb.gear() == Gearbox::Gear::Forward);
78 }
79
80 void GearboxTest::testBothPressed()
81 {
82 Gearbox gb;
83
84 gb.setAcceleratorEnabled(true);
85 gb.update(1);
86
87 QVERIFY(gb.gear() == Gearbox::Gear::Forward);
88
89 gb.setBrakeEnabled(true);
90 gb.setAcceleratorEnabled(true);
91
92 gb.update(1);
93
94 QVERIFY(gb.gear() == Gearbox::Gear::Neutral);
95 }
96
97 QTEST_GUILESS_MAIN(GearboxTest)