changeset 1617:bdc19a09a1f9 single-point

Minor tweaks, comments, span tests
author Chris Cannam
date Fri, 08 Mar 2019 11:15:59 +0000
parents de446dd905e6
children ba3ddb7fe2bd
files base/EventSeries.h base/test/TestEventSeries.h
diffstat 2 files changed, 127 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/base/EventSeries.h	Fri Mar 08 10:16:12 2019 +0000
+++ b/base/EventSeries.h	Fri Mar 08 11:15:59 2019 +0000
@@ -53,8 +53,9 @@
         ++m_count;
 
         if (p.hasDuration()) {
-            sv_frame_t frame = p.getFrame();
-            sv_frame_t endFrame = p.getFrame() + p.getDuration();
+
+            const sv_frame_t frame = p.getFrame();
+            const sv_frame_t endFrame = p.getFrame() + p.getDuration();
 
             createSeam(frame);
             createSeam(endFrame);
@@ -101,8 +102,8 @@
 
         if (p.hasDuration() && isUnique) {
             
-            sv_frame_t frame = p.getFrame();
-            sv_frame_t endFrame = p.getFrame() + p.getDuration();
+            const sv_frame_t frame = p.getFrame();
+            const sv_frame_t endFrame = p.getFrame() + p.getDuration();
 
             const auto i0 = m_seams.find(frame);
             const auto i1 = m_seams.find(endFrame);
@@ -190,15 +191,16 @@
      * greater than f.
      * 
      * Note that getEventsSpanning(f, 0) is not equivalent to
-     * getEventsCovering(f) - they have different behaviour in the
-     * case of events starting exactly at f, which are included in the
-     * latter but not the former.
+     * getEventsCovering(f). The latter includes durationless events
+     * at f and events starting at f, both of which are excluded from
+     * the former.
      */
-    EventVector getEventsSpanning(sv_frame_t f, sv_frame_t d) const {
+    EventVector getEventsSpanning(sv_frame_t frame,
+                                  sv_frame_t duration) const {
         EventVector span;
 
-        sv_frame_t start = f;
-        sv_frame_t end = f + d;
+        const sv_frame_t start = frame;
+        const sv_frame_t end = frame + duration;
         
         // first find any zero-duration events
         
--- a/base/test/TestEventSeries.h	Fri Mar 08 10:16:12 2019 +0000
+++ b/base/test/TestEventSeries.h	Fri Mar 08 11:15:59 2019 +0000
@@ -88,6 +88,58 @@
         QCOMPARE(s.getEventsCovering(9), EventVector());
     }
 
+    void singleEventSpan() {
+
+        EventSeries s;
+        Event p(10, QString());
+        s.add(p);
+        EventVector span;
+        span.push_back(p);
+        QCOMPARE(s.getEventsSpanning(10, 2), span);
+        QCOMPARE(s.getEventsSpanning(9, 2), span);
+        QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(7, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
+    }
+    
+    void identicalEventsCover() {
+
+        EventSeries s;
+        Event p(10, QString());
+        s.add(p);
+        s.add(p);
+
+        EventVector cover;
+        cover.push_back(p);
+        cover.push_back(p);
+        QCOMPARE(s.getEventsCovering(10), cover);
+        QCOMPARE(s.getEventsCovering(11), EventVector());
+        QCOMPARE(s.getEventsCovering(9), EventVector());
+
+        s.remove(p);
+        cover.clear();
+        cover.push_back(p);
+        QCOMPARE(s.getEventsCovering(10), cover);
+        QCOMPARE(s.getEventsCovering(11), EventVector());
+        QCOMPARE(s.getEventsCovering(9), EventVector());
+    }
+    
+    void identicalEventsSpan() {
+
+        EventSeries s;
+        Event p(10, QString());
+        s.add(p);
+        s.add(p);
+
+        EventVector span;
+        span.push_back(p);
+        span.push_back(p);
+        QCOMPARE(s.getEventsSpanning(10, 2), span);
+        QCOMPARE(s.getEventsSpanning(9, 2), span);
+        QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
+    }
+
     void similarEventsCover() {
 
         EventSeries s;
@@ -103,6 +155,22 @@
         QCOMPARE(s.getEventsCovering(9), EventVector());
     }
 
+    void similarEventsSpan() {
+
+        EventSeries s;
+        Event a(10, QString("a"));
+        Event b(10, QString("b"));
+        s.add(a);
+        s.add(b);
+        EventVector span;
+        span.push_back(a);
+        span.push_back(b);
+        QCOMPARE(s.getEventsSpanning(10, 2), span);
+        QCOMPARE(s.getEventsSpanning(9, 2), span);
+        QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
+    }
+
     void singleEventWithDurationCover() {
 
         EventSeries s;
@@ -117,28 +185,20 @@
         QCOMPARE(s.getEventsCovering(9), EventVector());
     }
 
-    void identicalEventsCover() {
+    void singleEventWithDurationSpan() {
 
         EventSeries s;
-        Event p(10, QString());
+        Event p(10, 1.0, 20, QString());
         s.add(p);
-        s.add(p);
+        EventVector span;
+        span.push_back(p);
+        QCOMPARE(s.getEventsSpanning(9, 2), span);
+        QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(19, 4), span);
+        QCOMPARE(s.getEventsSpanning(29, 2), span);
+        QCOMPARE(s.getEventsSpanning(30, 2), EventVector());
+    }
 
-        EventVector cover;
-        cover.push_back(p);
-        cover.push_back(p);
-        QCOMPARE(s.getEventsCovering(10), cover);
-        QCOMPARE(s.getEventsCovering(11), EventVector());
-        QCOMPARE(s.getEventsCovering(9), EventVector());
-
-        s.remove(p);
-        cover.clear();
-        cover.push_back(p);
-        QCOMPARE(s.getEventsCovering(10), cover);
-        QCOMPARE(s.getEventsCovering(11), EventVector());
-        QCOMPARE(s.getEventsCovering(9), EventVector());
-    }
-    
     void identicalEventsWithDurationCover() {
 
         EventSeries s;
@@ -164,6 +224,23 @@
         QCOMPARE(s.getEventsCovering(9), EventVector());
     }
 
+    void identicalEventsWithDurationSpan() {
+
+        EventSeries s;
+        Event p(10, 1.0, 20, QString());
+        s.add(p);
+        s.add(p);
+        EventVector span;
+        span.push_back(p);
+        span.push_back(p);
+        QCOMPARE(s.getEventsSpanning(9, 2), span);
+        QCOMPARE(s.getEventsSpanning(10, 2), span);
+        QCOMPARE(s.getEventsSpanning(11, 2), span);
+        QCOMPARE(s.getEventsSpanning(29, 2), span);
+        QCOMPARE(s.getEventsSpanning(30, 2), EventVector());
+        QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
+    }
+
     void multipleEventsCover() {
 
         EventSeries s;
@@ -187,6 +264,26 @@
         QCOMPARE(s.getEventsCovering(9), EventVector());
     }
 
+    void multipleEventsSpan() {
+
+        EventSeries s;
+        Event a(10, QString("a"));
+        Event b(11, QString("b"));
+        Event c(40, QString("c"));
+        s.add(c);
+        s.add(a);
+        s.add(b);
+        EventVector span;
+        span.push_back(a);
+        span.push_back(b);
+        QCOMPARE(s.getEventsSpanning(10, 2), span);
+        span.clear();
+        span.push_back(c);
+        QCOMPARE(s.getEventsSpanning(39, 3), span);
+        QCOMPARE(s.getEventsSpanning(9, 1), EventVector());
+        QCOMPARE(s.getEventsSpanning(10, 0), EventVector());
+    }
+
     void disjointEventsWithDurationCover() {
 
         EventSeries s;