Updated and Validated
[betaflight.git] / src / test / unit / motor_output_unittest.cc
blob37a20bfad710ab577084d0474bcc547e59a57068
1 /*
2 * This file is part of Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdint.h>
22 #include <iostream>
24 extern "C" {
25 #include "drivers/dshot.h"
28 #include "unittest_macros.h"
29 #include "gtest/gtest.h"
31 TEST(MotorOutputUnittest, TestFixMotorOutputReordering)
33 const unsigned size = 8;
35 uint8_t a1_initial[size] = {0, 1, 2, 3, 4, 5, 6, 7};
36 uint8_t a1_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
37 validateAndfixMotorOutputReordering(a1_initial, size);
38 EXPECT_TRUE( 0 == memcmp(a1_expected, a1_initial, sizeof(a1_expected)));
40 uint8_t a2_initial[size] = {3, 2, 1, 4, 5, 6, 7, 0};
41 uint8_t a2_expected[size] = {3, 2, 1, 4, 5, 6, 7, 0};
42 validateAndfixMotorOutputReordering(a2_initial, size);
43 EXPECT_TRUE( 0 == memcmp(a2_expected, a2_initial, sizeof(a2_expected)));
45 uint8_t a3_initial[size] = {3, 2, 1, 100, 5, 6, 7, 0};
46 uint8_t a3_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
47 validateAndfixMotorOutputReordering(a3_initial, size);
48 EXPECT_TRUE( 0 == memcmp(a3_expected, a3_initial, sizeof(a3_expected)));
50 uint8_t a4_initial[size] = {3, 2, 1, 100, 5, 6, 200, 0};
51 uint8_t a4_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
52 validateAndfixMotorOutputReordering(a4_initial, size);
53 EXPECT_TRUE( 0 == memcmp(a4_expected, a4_initial, sizeof(a4_expected)));
55 uint8_t a5_initial[size] = {0, 0, 0, 0, 0, 0, 0, 0};
56 uint8_t a5_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
57 validateAndfixMotorOutputReordering(a5_initial, size);
58 EXPECT_TRUE( 0 == memcmp(a5_expected, a5_initial, sizeof(a5_expected)));
60 uint8_t a6_initial[size] = {0, 0, 0, 1, 0, 99, 0, 0};
61 uint8_t a6_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
62 validateAndfixMotorOutputReordering(a6_initial, size);
63 EXPECT_TRUE( 0 == memcmp(a6_expected, a6_initial, sizeof(a5_expected)));
65 uint8_t a7_initial[size] = {1, 5, 3, 4, 5, 6, 7, 0};
66 uint8_t a7_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
67 validateAndfixMotorOutputReordering(a7_initial, size);
68 EXPECT_TRUE( 0 == memcmp(a7_expected, a7_initial, sizeof(a7_expected)));
70 uint8_t a8_initial[size] = {1, 5, 1, 5, 3, 3, 3, 3};
71 uint8_t a8_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
72 validateAndfixMotorOutputReordering(a8_initial, size);
73 EXPECT_TRUE( 0 == memcmp(a8_expected, a8_initial, sizeof(a8_expected)));
75 uint8_t a9_initial[size] = {7, 6, 5, 4, 3, 2, 1, 0};
76 uint8_t a9_expected[size] = {7, 6, 5, 4, 3, 2, 1, 0};
77 validateAndfixMotorOutputReordering(a9_initial, size);
78 EXPECT_TRUE( 0 == memcmp(a9_expected, a9_initial, sizeof(a9_expected)));