annotate data/model/test/TestZoomConstraints.h @ 1548:51d6551d5244

Show default name for unlabelled bin
author Chris Cannam
date Wed, 03 Oct 2018 15:45:57 +0100
parents a7485c1bdba5
children bf32b26d1dad
rev   line source
Chris@1528 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1528 2
Chris@1528 3 /*
Chris@1528 4 Sonic Visualiser
Chris@1528 5 An audio file viewer and annotation editor.
Chris@1528 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1528 7
Chris@1528 8 This program is free software; you can redistribute it and/or
Chris@1528 9 modify it under the terms of the GNU General Public License as
Chris@1528 10 published by the Free Software Foundation; either version 2 of the
Chris@1528 11 License, or (at your option) any later version. See the file
Chris@1528 12 COPYING included with this distribution for more information.
Chris@1528 13 */
Chris@1528 14
Chris@1528 15 #ifndef TEST_ZOOM_CONSTRAINTS_H
Chris@1528 16 #define TEST_ZOOM_CONSTRAINTS_H
Chris@1528 17
Chris@1528 18 #include "../PowerOfTwoZoomConstraint.h"
Chris@1528 19 #include "../PowerOfSqrtTwoZoomConstraint.h"
Chris@1528 20
Chris@1528 21 #include <QObject>
Chris@1528 22 #include <QtTest>
Chris@1528 23 #include <QDir>
Chris@1528 24
Chris@1528 25 #include <iostream>
Chris@1528 26
Chris@1528 27 using namespace std;
Chris@1528 28
Chris@1528 29 class TestZoomConstraints : public QObject
Chris@1528 30 {
Chris@1528 31 Q_OBJECT
Chris@1528 32
Chris@1528 33 private slots:
Chris@1528 34 void unconstrainedNearest() {
Chris@1528 35 ZoomConstraint c;
Chris@1528 36 QCOMPARE(c.getNearestBlockSize(1), 1);
Chris@1528 37 QCOMPARE(c.getNearestBlockSize(2), 2);
Chris@1528 38 QCOMPARE(c.getNearestBlockSize(3), 3);
Chris@1528 39 QCOMPARE(c.getNearestBlockSize(4), 4);
Chris@1528 40 QCOMPARE(c.getNearestBlockSize(20), 20);
Chris@1528 41 QCOMPARE(c.getNearestBlockSize(23), 23);
Chris@1528 42 int max = c.getMaxZoomLevel();
Chris@1528 43 QCOMPARE(c.getNearestBlockSize(max), max);
Chris@1528 44 QCOMPARE(c.getNearestBlockSize(max+1), max);
Chris@1528 45 }
Chris@1528 46
Chris@1528 47 void unconstrainedUp() {
Chris@1528 48 ZoomConstraint c;
Chris@1528 49 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1);
Chris@1528 50 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2);
Chris@1528 51 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 3);
Chris@1528 52 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4);
Chris@1528 53 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundUp), 20);
Chris@1528 54 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundUp), 32);
Chris@1528 55 int max = c.getMaxZoomLevel();
Chris@1528 56 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max);
Chris@1528 57 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max);
Chris@1528 58 }
Chris@1528 59
Chris@1528 60 void unconstrainedDown() {
Chris@1528 61 ZoomConstraint c;
Chris@1528 62 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1);
Chris@1528 63 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2);
Chris@1528 64 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 3);
Chris@1528 65 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4);
Chris@1528 66 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundDown), 20);
Chris@1528 67 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundDown), 32);
Chris@1528 68 int max = c.getMaxZoomLevel();
Chris@1528 69 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max);
Chris@1528 70 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max);
Chris@1528 71 }
Chris@1528 72
Chris@1528 73 void powerOfTwoNearest() {
Chris@1528 74 PowerOfTwoZoomConstraint c;
Chris@1528 75 QCOMPARE(c.getNearestBlockSize(1), 1);
Chris@1528 76 QCOMPARE(c.getNearestBlockSize(2), 2);
Chris@1528 77 QCOMPARE(c.getNearestBlockSize(3), 2);
Chris@1528 78 QCOMPARE(c.getNearestBlockSize(4), 4);
Chris@1528 79 QCOMPARE(c.getNearestBlockSize(20), 16);
Chris@1528 80 QCOMPARE(c.getNearestBlockSize(23), 16);
Chris@1528 81 QCOMPARE(c.getNearestBlockSize(24), 16);
Chris@1528 82 QCOMPARE(c.getNearestBlockSize(25), 32);
Chris@1528 83 int max = c.getMaxZoomLevel();
Chris@1528 84 QCOMPARE(c.getNearestBlockSize(max), max);
Chris@1528 85 QCOMPARE(c.getNearestBlockSize(max+1), max);
Chris@1528 86 }
Chris@1528 87
Chris@1528 88 void powerOfTwoUp() {
Chris@1528 89 PowerOfTwoZoomConstraint c;
Chris@1528 90 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1);
Chris@1528 91 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2);
Chris@1528 92 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 4);
Chris@1528 93 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4);
Chris@1528 94 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundUp), 32);
Chris@1528 95 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundUp), 32);
Chris@1528 96 QCOMPARE(c.getNearestBlockSize(33, ZoomConstraint::RoundUp), 64);
Chris@1528 97 int max = c.getMaxZoomLevel();
Chris@1528 98 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max);
Chris@1528 99 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max);
Chris@1528 100 }
Chris@1528 101
Chris@1528 102 void powerOfTwoDown() {
Chris@1528 103 PowerOfTwoZoomConstraint c;
Chris@1528 104 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1);
Chris@1528 105 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2);
Chris@1528 106 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 2);
Chris@1528 107 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4);
Chris@1528 108 QCOMPARE(c.getNearestBlockSize(20, ZoomConstraint::RoundDown), 16);
Chris@1528 109 QCOMPARE(c.getNearestBlockSize(32, ZoomConstraint::RoundDown), 32);
Chris@1528 110 QCOMPARE(c.getNearestBlockSize(33, ZoomConstraint::RoundDown), 32);
Chris@1528 111 int max = c.getMaxZoomLevel();
Chris@1528 112 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max);
Chris@1528 113 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max);
Chris@1528 114 }
Chris@1528 115
Chris@1528 116 void powerOfSqrtTwoNearest() {
Chris@1528 117 PowerOfSqrtTwoZoomConstraint c;
Chris@1528 118 QCOMPARE(c.getNearestBlockSize(1), 1);
Chris@1528 119 QCOMPARE(c.getNearestBlockSize(2), 2);
Chris@1528 120 QCOMPARE(c.getNearestBlockSize(3), 2);
Chris@1528 121 QCOMPARE(c.getNearestBlockSize(4), 4);
Chris@1528 122 QCOMPARE(c.getNearestBlockSize(18), 16);
Chris@1528 123 QCOMPARE(c.getNearestBlockSize(19), 16);
Chris@1528 124 QCOMPARE(c.getNearestBlockSize(20), 22);
Chris@1528 125 QCOMPARE(c.getNearestBlockSize(23), 22);
Chris@1528 126 QCOMPARE(c.getNearestBlockSize(28), 32);
Chris@1528 127 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure
Chris@1528 128 // bigger numbers get rounded to a multiple of something
Chris@1528 129 // simple (64 or 90 depending on whether they are power-of-two
Chris@1528 130 // or power-of-sqrt-two types)
Chris@1528 131 QCOMPARE(c.getNearestBlockSize(800), 720);
Chris@1528 132 QCOMPARE(c.getNearestBlockSize(1023), 1024);
Chris@1528 133 QCOMPARE(c.getNearestBlockSize(1024), 1024);
Chris@1528 134 QCOMPARE(c.getNearestBlockSize(1025), 1024);
Chris@1528 135 int max = c.getMaxZoomLevel();
Chris@1528 136 QCOMPARE(c.getNearestBlockSize(max), max);
Chris@1528 137 QCOMPARE(c.getNearestBlockSize(max+1), max);
Chris@1528 138 }
Chris@1528 139
Chris@1528 140 void powerOfSqrtTwoUp() {
Chris@1528 141 PowerOfSqrtTwoZoomConstraint c;
Chris@1528 142 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundUp), 1);
Chris@1528 143 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundUp), 2);
Chris@1528 144 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundUp), 4);
Chris@1528 145 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundUp), 4);
Chris@1528 146 QCOMPARE(c.getNearestBlockSize(18, ZoomConstraint::RoundUp), 22);
Chris@1528 147 QCOMPARE(c.getNearestBlockSize(22, ZoomConstraint::RoundUp), 22);
Chris@1528 148 QCOMPARE(c.getNearestBlockSize(23, ZoomConstraint::RoundUp), 32);
Chris@1528 149 QCOMPARE(c.getNearestBlockSize(800, ZoomConstraint::RoundUp), 1024);
Chris@1528 150 QCOMPARE(c.getNearestBlockSize(1023, ZoomConstraint::RoundUp), 1024);
Chris@1528 151 QCOMPARE(c.getNearestBlockSize(1024, ZoomConstraint::RoundUp), 1024);
Chris@1528 152 // see comment above
Chris@1528 153 QCOMPARE(c.getNearestBlockSize(1025, ZoomConstraint::RoundUp), 1440);
Chris@1528 154 int max = c.getMaxZoomLevel();
Chris@1528 155 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundUp), max);
Chris@1528 156 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundUp), max);
Chris@1528 157 }
Chris@1528 158
Chris@1528 159 void powerOfSqrtTwoDown() {
Chris@1528 160 PowerOfSqrtTwoZoomConstraint c;
Chris@1528 161 QCOMPARE(c.getNearestBlockSize(1, ZoomConstraint::RoundDown), 1);
Chris@1528 162 QCOMPARE(c.getNearestBlockSize(2, ZoomConstraint::RoundDown), 2);
Chris@1528 163 QCOMPARE(c.getNearestBlockSize(3, ZoomConstraint::RoundDown), 2);
Chris@1528 164 QCOMPARE(c.getNearestBlockSize(4, ZoomConstraint::RoundDown), 4);
Chris@1528 165 QCOMPARE(c.getNearestBlockSize(18, ZoomConstraint::RoundDown), 16);
Chris@1528 166 QCOMPARE(c.getNearestBlockSize(22, ZoomConstraint::RoundDown), 22);
Chris@1528 167 QCOMPARE(c.getNearestBlockSize(23, ZoomConstraint::RoundDown), 22);
Chris@1528 168 // see comment above
Chris@1528 169 QCOMPARE(c.getNearestBlockSize(800, ZoomConstraint::RoundDown), 720);
Chris@1528 170 QCOMPARE(c.getNearestBlockSize(1023, ZoomConstraint::RoundDown), 720);
Chris@1528 171 QCOMPARE(c.getNearestBlockSize(1024, ZoomConstraint::RoundDown), 1024);
Chris@1528 172 QCOMPARE(c.getNearestBlockSize(1025, ZoomConstraint::RoundDown), 1024);
Chris@1528 173 int max = c.getMaxZoomLevel();
Chris@1528 174 QCOMPARE(c.getNearestBlockSize(max, ZoomConstraint::RoundDown), max);
Chris@1528 175 QCOMPARE(c.getNearestBlockSize(max+1, ZoomConstraint::RoundDown), max);
Chris@1528 176 }
Chris@1528 177 };
Chris@1528 178
Chris@1528 179 #endif
Chris@1528 180