diff base/test/TestRangeMapper.h @ 885:12a6140b3ae0

Add unclamped range mapper methods
author Chris Cannam
date Thu, 06 Feb 2014 15:31:16 +0000
parents 633a8fa622c9
children ccc8658914ef
line wrap: on
line diff
--- a/base/test/TestRangeMapper.h	Thu Feb 06 10:14:59 2014 +0000
+++ b/base/test/TestRangeMapper.h	Thu Feb 06 15:31:16 2014 +0000
@@ -42,6 +42,10 @@
 	QCOMPARE(rm.getPositionForValue(0.2), 1);
 	QCOMPARE(rm.getPositionForValue(-12), 1);
 	QCOMPARE(rm.getPositionForValue(6.1), 8);
+	QCOMPARE(rm.getPositionForValueUnclamped(3.0), 6);
+	QCOMPARE(rm.getPositionForValueUnclamped(0.2), 0);
+	QCOMPARE(rm.getPositionForValueUnclamped(-12), -24);
+	QCOMPARE(rm.getPositionForValueUnclamped(6.1), 12);
     }
 
     void linearDownForward()
@@ -56,6 +60,10 @@
 	QCOMPARE(rm.getPositionForValue(0.2), 8);
 	QCOMPARE(rm.getPositionForValue(-12), 8);
 	QCOMPARE(rm.getPositionForValue(6.1), 1);
+	QCOMPARE(rm.getPositionForValueUnclamped(3.0), 3);
+	QCOMPARE(rm.getPositionForValueUnclamped(0.2), 9);
+	QCOMPARE(rm.getPositionForValueUnclamped(-12), 33);
+	QCOMPARE(rm.getPositionForValueUnclamped(6.1), -3);
     }
 
     void linearUpBackward()
@@ -68,6 +76,10 @@
 	QCOMPARE(rm.getValueForPosition(7), 3.5);
 	QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
 	QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
+	QCOMPARE(rm.getValueForPositionUnclamped(6), 3.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(0), 0.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(-24), -12.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(12), 6.0);
     }
 
     void linearDownBackward()
@@ -80,6 +92,10 @@
 	QCOMPARE(rm.getValueForPosition(2), 3.5);
 	QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
 	QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
+	QCOMPARE(rm.getValueForPositionUnclamped(3), 3.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(9), 0.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(33), -12.0);
+	QCOMPARE(rm.getValueForPositionUnclamped(-3), 6.0);
     }
 
     void logUpForward()
@@ -93,6 +109,9 @@
 	QCOMPARE(rm.getPositionForValue(1000.0), 5);
 	QCOMPARE(rm.getPositionForValue(900.0), 5);
 	QCOMPARE(rm.getPositionForValue(20000), 6);
+	QCOMPARE(rm.getPositionForValueUnclamped(1.0), 2);
+	QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 8);
+	QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5);
     }
 
     void logDownForward()
@@ -106,6 +125,9 @@
 	QCOMPARE(rm.getPositionForValue(1000.0), 5);
 	QCOMPARE(rm.getPositionForValue(900.0), 5);
 	QCOMPARE(rm.getPositionForValue(20000), 4);
+	QCOMPARE(rm.getPositionForValueUnclamped(1.0), 8);
+	QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 2);
+	QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5);
     }
 
     void logUpBackward()
@@ -118,6 +140,9 @@
 	QCOMPARE(rm.getValueForPosition(6), 10000.0);
 	QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
 	QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
+	QCOMPARE(rm.getValueForPositionUnclamped(2), 1.0);
+        QCOMPARE(rm.getValueForPositionUnclamped(8), 1000000.0);
+        QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0);
     }
 
     void logDownBackward()
@@ -130,6 +155,9 @@
 	QCOMPARE(rm.getValueForPosition(4), 10000.0);
 	QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
 	QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
+	QCOMPARE(rm.getValueForPositionUnclamped(8), 1.0);
+        QCOMPARE(rm.getValueForPositionUnclamped(2), 1000000.0);
+        QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0);
     }
 
     void interpolatingForward()
@@ -147,6 +175,9 @@
 	QCOMPARE(rm.getPositionForValue(3.0), 30);
 	QCOMPARE(rm.getPositionForValue(2.5), 25);
 	QCOMPARE(rm.getPositionForValue(4.5), 60);
+	QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0);
+	QCOMPARE(rm.getPositionForValueUnclamped(2.5), 25);
+	QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90);
     }
 
     void interpolatingBackward()
@@ -174,10 +205,15 @@
 	AutoRangeMapper rm1(mappings, "x");
 	QCOMPARE(rm1.getUnit(), QString("x"));
 	QCOMPARE(rm1.getType(), AutoRangeMapper::StraightLine);
+	QCOMPARE(rm1.getPositionForValue(0.1), 1);
 	QCOMPARE(rm1.getPositionForValue(0.5), 1);
 	QCOMPARE(rm1.getPositionForValue(4.0), 8);
+	QCOMPARE(rm1.getPositionForValue(4.5), 8);
 	QCOMPARE(rm1.getPositionForValue(3.0), 6);
 	QCOMPARE(rm1.getPositionForValue(3.1), 6);
+	QCOMPARE(rm1.getPositionForValueUnclamped(0.1), 0);
+	QCOMPARE(rm1.getPositionForValueUnclamped(3.1), 6);
+	QCOMPARE(rm1.getPositionForValueUnclamped(4.5), 9);
 	mappings[3.0] = 6;
 	mappings[3.5] = 7;
 	AutoRangeMapper rm2(mappings, "x");
@@ -205,6 +241,9 @@
 	QCOMPARE(rm1.getPositionForValue(1000.0), 5);
 	QCOMPARE(rm1.getPositionForValue(900.0), 5);
 	QCOMPARE(rm1.getPositionForValue(20000), 6);
+	QCOMPARE(rm1.getPositionForValueUnclamped(1.0), 2);
+	QCOMPARE(rm1.getPositionForValueUnclamped(900.0), 5);
+	QCOMPARE(rm1.getPositionForValueUnclamped(1000000.0), 8);
 	mappings[100] = 4;
 	AutoRangeMapper rm2(mappings, "x");
 	QCOMPARE(rm2.getUnit(), QString("x"));
@@ -234,6 +273,9 @@
 	QCOMPARE(rm.getPositionForValue(3.0), 30);
 	QCOMPARE(rm.getPositionForValue(2.5), 25);
 	QCOMPARE(rm.getPositionForValue(4.5), 60);
+	QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0);
+	QCOMPARE(rm.getPositionForValueUnclamped(5.0), 70);
+	QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90);
     }
 };