[Scummvm-cvs-logs] SF.net SVN: scummvm:[40027] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Mon Apr 20 21:27:11 CEST 2009
Revision: 40027
http://scummvm.svn.sourceforge.net/scummvm/?rev=40027&view=rev
Author: fingolfin
Date: 2009-04-20 19:27:11 +0000 (Mon, 20 Apr 2009)
Log Message:
-----------
COMMON & TESTS: Added new constructor to Array<T>, namely Array(const T* data, int n), which makes it possible to clone a regular array into a Common::Array; added a unit test for that and slightly extended existing Common::Array unit tests
Modified Paths:
--------------
scummvm/trunk/common/array.h
scummvm/trunk/test/common/array.h
Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h 2009-04-20 19:26:50 UTC (rev 40026)
+++ scummvm/trunk/common/array.h 2009-04-20 19:27:11 UTC (rev 40027)
@@ -46,12 +46,20 @@
public:
Array() : _capacity(0), _size(0), _storage(0) {}
Array(const Array<T> &array) : _capacity(0), _size(0), _storage(0) {
- _size = array._size;
- _capacity = _size + 32;
+ _capacity = _size = array._size;
_storage = new T[_capacity];
copy(array._storage, array._storage + _size, _storage);
}
+ /**
+ * Construct an array by copying data from a regular array.
+ */
+ Array(const T *data, int n) {
+ _capacity = _size = n;
+ _storage = new T[_capacity];
+ copy(data, data + _size, _storage);
+ }
+
~Array() {
delete[] _storage;
}
Modified: scummvm/trunk/test/common/array.h
===================================================================
--- scummvm/trunk/test/common/array.h 2009-04-20 19:26:50 UTC (rev 40026)
+++ scummvm/trunk/test/common/array.h 2009-04-20 19:27:11 UTC (rev 40027)
@@ -73,6 +73,8 @@
TS_ASSERT_EQUALS( array[2], 33 );
TS_ASSERT_EQUALS( array[3], 25 );
TS_ASSERT_EQUALS( array[4], -11 );
+
+ TS_ASSERT_EQUALS( array.size(), 5 );
}
void test_remove_at() {
@@ -92,6 +94,8 @@
TS_ASSERT_EQUALS( array[1], 33 );
TS_ASSERT_EQUALS( array[2], 25 );
TS_ASSERT_EQUALS( array[3], -11 );
+
+ TS_ASSERT_EQUALS( array.size(), 4 );
}
void test_push_back() {
@@ -114,6 +118,9 @@
TS_ASSERT_EQUALS( array1[3], 3 );
TS_ASSERT_EQUALS( array1[4], -2 );
TS_ASSERT_EQUALS( array1[5], -131 );
+
+ TS_ASSERT_EQUALS( array1.size(), 6 );
+ TS_ASSERT_EQUALS( array2.size(), 3 );
}
void test_copy_constructor() {
@@ -129,5 +136,19 @@
TS_ASSERT_EQUALS( array2[0], -3 );
TS_ASSERT_EQUALS( array2[1], 5 );
TS_ASSERT_EQUALS( array2[2], 9 );
+
+ TS_ASSERT_EQUALS( array2.size(), 3 );
}
+
+ void test_array_constructor() {
+ const int array1[] = { -3, 5, 9 };
+
+ Common::Array<int> array2(array1, 3);
+
+ TS_ASSERT_EQUALS( array2[0], -3 );
+ TS_ASSERT_EQUALS( array2[1], 5 );
+ TS_ASSERT_EQUALS( array2[2], 9 );
+
+ TS_ASSERT_EQUALS( array2.size(), 3 );
+ }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list