File: UnsizedSegmentationTest.cxx

package info (click to toggle)
clam 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 20,981
  • sloc: cpp: 92,504; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (110 lines) | stat: -rw-r--r-- 4,032 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
#include <cppunit/extensions/HelperMacros.h>
#include "cppUnitHelper.hxx" // necessary for the custom assert

#include "UnsizedSegmentation.hxx"
#include "XMLTestHelper.hxx"
#include <sstream>

using CLAM::UnsizedSegmentation;
using CLAM::XmlStorage;

namespace CLAMTest
{
	class UnsizedSegmentationTest;

	CPPUNIT_TEST_SUITE_REGISTRATION( UnsizedSegmentationTest );

	class UnsizedSegmentationTest : public CppUnit::TestFixture
	{
		CPPUNIT_TEST_SUITE( UnsizedSegmentationTest );
		CPPUNIT_TEST( testStoreOn);
		CPPUNIT_TEST( testtakeArray);
		CPPUNIT_TEST( testLoadFromWithoutMaxPos);
		CPPUNIT_TEST( testLoadFromWithMaxPos);
		CPPUNIT_TEST(testStoreOn_withinAnArray);
		CPPUNIT_TEST(testLoadFromWithoutMaxPos_withinAnArray);
		CPPUNIT_TEST(testLoadFromWithMaxPos_withinAnArray);
		CPPUNIT_TEST_SUITE_END();

	public:

		void testStoreOn()
		{
			const TData onsets[]={90, 100, 110, 120};
			UnsizedSegmentation segmentation(200, onsets, onsets+4);
			std::ostringstream stream;
			XmlStorage::Dump(segmentation, "Segmentation", stream);
			CLAMTEST_ASSERT_XML_EQUAL(
				"<Segmentation max=\"200\" size=\"4\">90 100 110 120</Segmentation>"
				, stream.str());
		}

		void testtakeArray()
		{
			const TData bounds[]={90, 100, 110, 120};
			UnsizedSegmentation segmentation(200);
			segmentation.takeArray(bounds, bounds+4);
			CPPUNIT_ASSERT_EQUAL(std::string("(90,90) (100,100) (110,110) (120,120) "), segmentation.boundsAsString());
		}
		void testLoadFromWithoutMaxPos()
		{
			UnsizedSegmentation segmentation(200);
			std::istringstream stream("<Segmentation size=\"4\">90 100 110 120</Segmentation>");
			XmlStorage::Restore(segmentation, stream);
			CPPUNIT_ASSERT_EQUAL(std::string("(90,90) (100,100) (110,110) (120,120) "), segmentation.boundsAsString());
		}
		void testLoadFromWithMaxPos()
		{
			UnsizedSegmentation segmentation;
			std::istringstream stream("<Segmentation max=\"200\" size=\"4\">90 100 110 120</Segmentation>");
			XmlStorage::Restore(segmentation, stream);
			CPPUNIT_ASSERT_EQUAL(std::string("(90,90) (100,100) (110,110) (120,120) "), segmentation.boundsAsString());
		}

		void testStoreOn_withinAnArray()
		{
			const TData onsets1[]={90, 100, 110, 120};
			const TData onsets2[]={9, 10, 11};
			CLAM::Array<UnsizedSegmentation> segmentations(2);
			segmentations[0].maxPosition(200);
			segmentations[0].takeArray(onsets1, onsets1+4);
			segmentations[1].maxPosition(20);
			segmentations[1].takeArray(onsets2, onsets2+3);
			std::ostringstream stream;
			XmlStorage::Dump(segmentations, "Segmentations", stream);
			CLAMTEST_ASSERT_XML_EQUAL(
				"<Segmentations>"
					"<UnsizedSegmentation max=\"200\" size=\"4\">90 100 110 120</UnsizedSegmentation>"
					"<UnsizedSegmentation max=\"20\" size=\"3\">9 10 11</UnsizedSegmentation>"
				"</Segmentations>"
				, stream.str());
		}
		void testLoadFromWithoutMaxPos_withinAnArray()
		{
			CLAM::Array<UnsizedSegmentation> segmentations;
			std::istringstream stream(
				"<Segmentations>"
					"<UnsizedSegmentation size=\"4\">90 100 110 120</UnsizedSegmentation>"
					"<UnsizedSegmentation size=\"3\">9 10 11</UnsizedSegmentation>"
				"</Segmentations>");
			XmlStorage::Restore(segmentations, stream);
			CPPUNIT_ASSERT_EQUAL(std::string("(90,90) (100,100) (110,110) (120,120) "), segmentations[0].boundsAsString());
			CPPUNIT_ASSERT_EQUAL(std::string("(9,9) (10,10) (11,11) "), segmentations[1].boundsAsString());
		}
		void testLoadFromWithMaxPos_withinAnArray()
		{
			CLAM::Array<UnsizedSegmentation> segmentations;
			std::istringstream stream(
				"<Segmentations>"
					"<UnsizedSegmentation max=\"200\" size=\"4\">90 100 110 120</UnsizedSegmentation>"
					"<UnsizedSegmentation max=\"20\" size=\"3\">9 10 11</UnsizedSegmentation>"
				"</Segmentations>");
			XmlStorage::Restore(segmentations, stream);
			CPPUNIT_ASSERT_EQUAL(std::string("(90,90) (100,100) (110,110) (120,120) "), segmentations[0].boundsAsString());
			CPPUNIT_ASSERT_EQUAL(std::string("(9,9) (10,10) (11,11) "), segmentations[1].boundsAsString());
		}
	};


}