1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <CLAM/RangeView.hxx>
#include <cppunit/extensions/HelperMacros.h>
namespace CLAMTest {
class RangeViewTest;
CPPUNIT_TEST_SUITE_REGISTRATION( RangeViewTest );
class RangeViewTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE (RangeViewTest);
CPPUNIT_TEST (testZoom_OutAtTheMiddle);
CPPUNIT_TEST (testZoom_InAtTheMiddle);
CPPUNIT_TEST (testZoom_InAtTheBegining);
CPPUNIT_TEST (testZoom_OutAtTheBegining);
CPPUNIT_TEST (testZoom_InAtTheEnd);
CPPUNIT_TEST (testZoom_OutAtTheEnd);
CPPUNIT_TEST (testKeepInRange_whenOverHighest);
CPPUNIT_TEST (testKeepInRange_whenUnderLowest);
CPPUNIT_TEST (testKeepInRange_whenDoesNotFit);
CPPUNIT_TEST_SUITE_END();
private:
void testZoom_OutAtTheMiddle()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, 2, .5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.2, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.2, high, 1e-14);
}
void testZoom_InAtTheMiddle()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, .5, .5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(8.7, high, 1e-14);
}
void testZoom_InAtTheBegining()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, .5, 0.);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.2, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2, high, 1e-14);
}
void testZoom_OutAtTheBegining()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, 2., 0.);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.2, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(16.2, high, 1e-14);
}
void testZoom_InAtTheEnd()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, .5, 1.);
CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.2, high, 1e-14);
}
void testZoom_OutAtTheEnd()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::zoom(low, high, 2., 1.);
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.2, high, 1e-14);
}
void testKeepInRange_whenOverHighest()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::keepWithinInterval(low, high, 0, 10);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, high, 1e-14);
}
void testKeepInRange_whenUnderLowest()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::keepWithinInterval(low, high, 5, 20);
CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, high, 1e-14);
}
void testKeepInRange_whenDoesNotFit()
{
double low = 4.2;
double high = 10.2;
CLAM::RangeView::keepWithinInterval(low, high, 0, 3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, low, 1e-14);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, high, 1e-14);
}
};
}
|