Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file test_hellen_board_id.cpp | |||
3 | * | |||
4 | * @date Jan 20, 2022 | |||
5 | * @author andreika <prometheus.pcb@gmail.com> | |||
6 | * @author Andrey Belomutskiy, (c) 2012-2022 | |||
7 | */ | |||
8 | ||||
9 | #include "pch.h" | |||
10 | #include "gtest/gtest.h" | |||
11 | #include "hellen_meta.h" | |||
12 | #include "digital_input_exti.h" | |||
13 | ||||
14 | #include "hellen_board_id.h" | |||
15 | ||||
16 | 4 | TEST(hellen_board_id, testNewtonSolver) { | ||
17 | // let's prove that our formula is independent of the threshold voltage: | |||
18 | 1 | HellenBoardIdSolver solver; | ||
19 | // 1.5V threshold | |||
20 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(1100, solver.solve(666.74938f, 353.32522f, 1000.0f, 1.0f, 1.0f), 0.001); | |
21 | // 2.5V threshold | |||
22 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(1100, solver.solve(1558.773f, 1335.563f, 1000.0f, 1.0f, 1.0f), 0.001); | |
23 | 1 | } | ||
24 | ||||
25 | 4 | TEST(hellen_board_id, testClosestResistor) { | ||
26 | 1 | HellenBoardIdFinderBase finder; | ||
27 | 1 | int rIdx; | ||
28 | // use only major series | |||
29 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1000, finder.findClosestResistor(876, true, &rIdx)); | |
30 | ||||
31 | // break point between 1000 and 1200 = ~1091 | |||
32 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1000, finder.findClosestResistor(1090, true, &rIdx)); | |
33 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1200, finder.findClosestResistor(1091, true, &rIdx)); | |
34 | // use full series | |||
35 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1000, finder.findClosestResistor(1047, false, &rIdx)); | |
36 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1100, finder.findClosestResistor(1049, false, &rIdx)); | |
37 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1100, finder.findClosestResistor(1147, false, &rIdx)); | |
38 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(1200, finder.findClosestResistor(1149, false, &rIdx)); | |
39 | ||||
40 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_FLOAT_EQ(510, finder.findClosestResistor(0, true, &rIdx)); | |
41 |
3/8✓ Branch 3 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✓ Branch 26 taken 1 time.
✗ Branch 27 not taken.
|
1 | ASSERT_EQ(0, rIdx); | |
42 | } | |||
43 | ||||
44 | 4 | TEST(hellen_board_id, testEstimatedResistor) { | ||
45 | 1 | HellenBoardIdFinderBase finder; | ||
46 |
3/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_NEAR(10000, finder.calcEstimatedResistance(6931.4718055995f, 1.0f), 0.001); | |
47 | 1 | } | ||
48 | ||||
49 | TEST(hellen_board_id, testCalc) { | |||
50 | HellenBoardIdFinderBase finder; | |||
51 | float Rmeasured, newC; | |||
52 | int rIdx; | |||
53 | float R = finder.calc(1024.714f, 724.639555f, 1099.0f, 1.0f, false, &Rmeasured, &newC, &rIdx); | |||
54 | EXPECT_NEAR(1100, R, 0.001); | |||
55 | EXPECT_NEAR(1099.998779, Rmeasured, 0.001); | |||
56 | EXPECT_NEAR(0.980316, newC, 0.001); | |||
57 | ASSERT_EQ(19, rIdx); | |||
58 | } | |||
59 |