comparison data/model/test/TestSparseModels.h @ 1658:5b7b01da430a single-point

Start updating SparseOneDimensionalModel
author Chris Cannam
date Wed, 20 Mar 2019 16:22:13 +0000
parents 7a56bb85030f
children 8bf3a52a1604
comparison
equal deleted inserted replaced
1657:31b46a5647db 1658:5b7b01da430a
31 31
32 private slots: 32 private slots:
33 void s1d_empty() { 33 void s1d_empty() {
34 SparseOneDimensionalModel m(100, 10, false); 34 SparseOneDimensionalModel m(100, 10, false);
35 QCOMPARE(m.isEmpty(), true); 35 QCOMPARE(m.isEmpty(), true);
36 QCOMPARE(m.getPointCount(), 0); 36 QCOMPARE(m.getEventCount(), 0);
37 QCOMPARE(m.getPoints().begin(), m.getPoints().end()); 37 QCOMPARE(m.getAllEvents().size(), 0);
38 QCOMPARE(m.getStartFrame(), 0); 38 QCOMPARE(m.getStartFrame(), 0);
39 QCOMPARE(m.getEndFrame(), 0); 39 QCOMPARE(m.getEndFrame(), 0);
40 QCOMPARE(m.getSampleRate(), 100); 40 QCOMPARE(m.getSampleRate(), 100);
41 QCOMPARE(m.getResolution(), 10); 41 QCOMPARE(m.getResolution(), 10);
42 QCOMPARE(m.isSparse(), true); 42 QCOMPARE(m.isSparse(), true);
43 43
44 SparseOneDimensionalModel::Point p(10); 44 Event p(10);
45 m.addPoint(p); 45 m.add(p);
46 /*!!!
46 m.clear(); 47 m.clear();
47 QCOMPARE(m.isEmpty(), true); 48 QCOMPARE(m.isEmpty(), true);
48 QCOMPARE(m.getPointCount(), 0); 49 QCOMPARE(m.getEventCount(), 0);
49 QCOMPARE(m.getPoints().begin(), m.getPoints().end()); 50 QCOMPARE(m.getAllEvents().size(), 0);
50 QCOMPARE(m.getStartFrame(), 0); 51 QCOMPARE(m.getStartFrame(), 0);
51 QCOMPARE(m.getEndFrame(), 0); 52 QCOMPARE(m.getEndFrame(), 0);
52 53
53 m.addPoint(p); 54 m.add(p);
54 m.deletePoint(p); 55 */
56 m.remove(p);
55 QCOMPARE(m.isEmpty(), true); 57 QCOMPARE(m.isEmpty(), true);
56 QCOMPARE(m.getPointCount(), 0); 58 QCOMPARE(m.getEventCount(), 0);
57 QCOMPARE(m.getPoints().begin(), m.getPoints().end()); 59 QCOMPARE(m.getAllEvents().size(), 0);
58 QCOMPARE(m.getStartFrame(), 0); 60 QCOMPARE(m.getStartFrame(), 0);
59 QCOMPARE(m.getEndFrame(), 0); 61 QCOMPARE(m.getEndFrame(), 0);
60 } 62 }
61 63
62 void s1d_extents() { 64 void s1d_extents() {
63 SparseOneDimensionalModel m(100, 10, false); 65 SparseOneDimensionalModel m(100, 10, false);
64 SparseOneDimensionalModel::Point p1(20); 66 Event p1(20);
65 m.addPoint(p1); 67 m.add(p1);
66 QCOMPARE(m.isEmpty(), false); 68 QCOMPARE(m.isEmpty(), false);
67 QCOMPARE(m.getPointCount(), 1); 69 QCOMPARE(m.getEventCount(), 1);
68 SparseOneDimensionalModel::Point p2(50); 70 Event p2(50);
69 m.addPoint(p2); 71 m.add(p2);
70 QCOMPARE(m.isEmpty(), false); 72 QCOMPARE(m.isEmpty(), false);
71 QCOMPARE(m.getPointCount(), 2); 73 QCOMPARE(m.getEventCount(), 2);
72 QCOMPARE(m.getPoints().size(), 2); 74 QCOMPARE(m.getAllEvents().size(), 2);
73 QCOMPARE(*m.getPoints().begin(), p1); 75 QCOMPARE(*m.getAllEvents().begin(), p1);
74 QCOMPARE(*m.getPoints().rbegin(), p2); 76 QCOMPARE(*m.getAllEvents().rbegin(), p2);
75 QCOMPARE(m.getStartFrame(), 20); 77 QCOMPARE(m.getStartFrame(), 20);
76 QCOMPARE(m.getEndFrame(), 60); 78 QCOMPARE(m.getEndFrame(), 60);
77 QCOMPARE(m.containsPoint(p1), true); 79 QCOMPARE(m.containsEvent(p1), true);
78 m.deletePoint(p1); 80 m.remove(p1);
79 QCOMPARE(m.getPointCount(), 1); 81 QCOMPARE(m.getEventCount(), 1);
80 QCOMPARE(m.getPoints().size(), 1); 82 QCOMPARE(m.getAllEvents().size(), 1);
81 QCOMPARE(*m.getPoints().begin(), p2); 83 QCOMPARE(*m.getAllEvents().begin(), p2);
82 QCOMPARE(m.getStartFrame(), 50); 84 QCOMPARE(m.getStartFrame(), 50);
83 QCOMPARE(m.getEndFrame(), 60); 85 QCOMPARE(m.getEndFrame(), 60);
84 QCOMPARE(m.containsPoint(p1), false); 86 QCOMPARE(m.containsEvent(p1), false);
85 } 87 }
86 88
87 void s1d_sample() { 89 void s1d_sample() {
88 SparseOneDimensionalModel m(100, 10, false); 90 SparseOneDimensionalModel m(100, 10, false);
89 SparseOneDimensionalModel::Point p1(20), p2(20), p3(50); 91 Event p1(20), p2(20), p3(50);
90 m.addPoint(p1); 92 m.add(p1);
91 m.addPoint(p2); 93 m.add(p2);
92 m.addPoint(p3); 94 m.add(p3);
93 QCOMPARE(m.getPoints().size(), 3); 95 QCOMPARE(m.getAllEvents().size(), 3);
94 QCOMPARE(*m.getPoints().begin(), p1); 96 QCOMPARE(*m.getAllEvents().begin(), p1);
95 QCOMPARE(*m.getPoints().rbegin(), p3); 97 QCOMPARE(*m.getAllEvents().rbegin(), p3);
96 /*!!! 98 /*!!!
97 auto pp = m.getPoints(20, 30); 99 auto pp = m.getAllEvents(20, 30);
98 QCOMPARE(pp.size(), 2); 100 QCOMPARE(pp.size(), 2);
99 QCOMPARE(*pp.begin(), p1); 101 QCOMPARE(*pp.begin(), p1);
100 QCOMPARE(*pp.rbegin(), p2); 102 QCOMPARE(*pp.rbegin(), p2);
101 103
102 pp = m.getPoints(40, 50); 104 pp = m.getAllEvents(40, 50);
103 QCOMPARE(pp.size(), 0); 105 QCOMPARE(pp.size(), 0);
104 106
105 pp = m.getPoints(50, 50); 107 pp = m.getAllEvents(50, 50);
106 QCOMPARE(pp.size(), 1); 108 QCOMPARE(pp.size(), 1);
107 QCOMPARE(*pp.begin(), p3); 109 QCOMPARE(*pp.begin(), p3);
108 */ 110 */
109 } 111 }
110 112
111 void s1d_xml() { 113 void s1d_xml() {
112 SparseOneDimensionalModel m(100, 10, false); 114 SparseOneDimensionalModel m(100, 10, false);
113 m.setObjectName("This \"&\" that"); 115 m.setObjectName("This \"&\" that");
114 SparseOneDimensionalModel::Point p1(20), p2(20), p3(50); 116 Event p1(20), p2(20), p3(50);
115 p2.label = "Label &'\">"; 117 p2 = p2.withLabel("Label &'\">");
116 m.addPoint(p1); 118 m.add(p1);
117 m.addPoint(p2); 119 m.add(p2);
118 m.addPoint(p3); 120 m.add(p3);
119 QString xml; 121 QString xml;
120 QTextStream str(&xml, QIODevice::WriteOnly); 122 QTextStream str(&xml, QIODevice::WriteOnly);
121 m.toXml(str); 123 m.toXml(str);
122 str.flush(); 124 str.flush();
123 QString expected = 125 QString expected =
124 "<model id='1' name='This &quot;&amp;&quot; that' sampleRate='100' start='20' end='60' type='sparse' dimensions='1' resolution='10' notifyOnAdd='false' dataset='0' />\n" 126 "<model id='1' name='This &quot;&amp;&quot; that' sampleRate='100' start='20' end='60' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='0' />\n"
125 "<dataset id='0' dimensions='1'>\n" 127 "<dataset id='0' dimensions='1'>\n"
126 " <point frame='20' label='' />\n" 128 " <point frame='20' label='' />\n"
127 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n" 129 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n"
128 " <point frame='50' label='' />\n" 130 " <point frame='50' label='' />\n"
129 "</dataset>\n"; 131 "</dataset>\n";