Debian Codegraph @

test_suite/unit_tests/Autopilot/testDigitalFilter.cxx

raw symbols SCIP
1 #include "testDigitalFilter.hxx"
2
3 #include <strstream>
4
5 #include "test_suite/FGTestApi/testGlobals.hxx"
6
7
8 #include <Autopilot/autopilot.hxx>
9 #include <Autopilot/digitalfilter.hxx>
10 #include <Main/fg_props.hxx>
11 #include <Main/globals.hxx>
12
13
14 #include <simgear/math/sg_random.hxx>
15 #include <simgear/props/props_io.hxx>
16
17 // Set up function for each test.
18 void DigitalFilterTests::setUp()
19 {
20 FGTestApi::setUp::initTestGlobals("ap-digitialfilter");
21 }
22
23
24 // Clean up after each test.
25 void DigitalFilterTests::tearDown()
26 {
27 FGTestApi::tearDown::shutdownTestGlobals();
28 }
29
30
31 SGPropertyNode_ptr DigitalFilterTests::configFromString(const std::string& s)
32 {
33 SGPropertyNode_ptr config = new SGPropertyNode;
34
35 std::istringstream iss(s);
36 readProperties(iss, config);
37 return config;
38 }
39
40 void DigitalFilterTests::testNoise()
41 {
42 sg_srandom(999);
43
44 auto config = configFromString(R"(<?xml version="1.0" encoding="UTF-8"?>
45 <PropertyList>
46 <filter>
47 <input>/test/a</input>
48 <output>/test/b</output>
49 <type>coherent-noise</type>
50 <amplitude>3.0</amplitude>
51 <absolute type="bool">true</absolute>
52 <discrete-resolution>1024</discrete-resolution>
53 </filter>
54 </PropertyList>
55 )");
56
57 auto ap = new FGXMLAutopilot::Autopilot(globals->get_props(), config);
58
59 globals->get_subsystem_mgr()->add("ap", ap);
60 ap->bind();
61 ap->init();
62
63 //
64 // for (double x=0.0; x < 5.0; x+=0.01) {
65 // fgSetDouble("/test/a", x);
66 // ap->update(0.1);
67 // std::cerr << fgGetDouble("/test/b") << std::endl;
68 // }
69
70 fgSetDouble("/test/a", 0.5);
71 ap->update(0.1);
72 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.029, fgGetDouble("/test/b"), 0.001);
73
74 fgSetDouble("/test/a", 0.8);
75 ap->update(0.1);
76 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.808, fgGetDouble("/test/b"), 0.001);
77
78 fgSetDouble("/test/a", 0.3);
79 ap->update(0.1);
80 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.478, fgGetDouble("/test/b"), 0.001);
81 }