URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-11 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add tests for mat and vec and h_mat and h_vec.
* tests/fun_x2x_translation.cc: Fix.
* mln/make/vec.hh,
* mln/metal/mat.hh,
* mln/metal/vec.hh: Update.
* tests/mat.cc: New.
* tests/vec.cc: New.
---
mln/make/vec.hh | 20 -------------
mln/metal/mat.hh | 16 ++++++++++
mln/metal/vec.hh | 1
tests/fun_x2x_translation.cc | 2 -
tests/mat.cc | 60 ++++++++++++++++++++++++++++++++++++++++
tests/vec.cc | 64 +++++++++++++++++++++++++++++++++++++++++++
6 files changed, 142 insertions(+), 21 deletions(-)
Index: trunk/milena/tests/fun_x2x_translation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_translation.cc (revision 1304)
+++ trunk/milena/tests/fun_x2x_translation.cc (revision 1305)
@@ -47,7 +47,7 @@
c = 2.9;
metal::vec<3,float> vec1 = make::vec(a, b, c);
- fun::x2x::translation<3,float> tr1(make::vec<3, float>(all(1.6)));
+ fun::x2x::translation<3,float> tr1(all(1.6));
std::cout << vec1 << std::endl;
std::cout << tr1(vec1) << std::endl;
Index: trunk/milena/tests/mat.cc
===================================================================
--- trunk/milena/tests/mat.cc (revision 0)
+++ trunk/milena/tests/mat.cc (revision 1305)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/image2d.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+
+#include <iostream>
+#include <mln/fun/i2v/all.hh>
+#include <mln/metal/mat.hh>
+#include <mln/core/h_mat.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ metal::mat<1,3,float> m1(all(4.));
+ metal::mat<2,2,float> m2 = metal::mat<2,2,float>::Id;
+
+ h_mat<1,float> hm1(m2);
+ h_mat<2,float> hm2;
+ h_mat<3,float> hm3(all(1.5));
+
+ metal::mat<4,4,float> m4 = hm3;
+
+ std::cout << "m1 = " << m1 << ";" << std::endl;
+ std::cout << "m2 = " << m2 << ";" << std::endl;
+ std::cout << "m4 = " << m4 << ";" << std::endl;
+ std::cout << "hm1 = " << hm1 << ";" << std::endl;
+ std::cout << "hm2 = " << hm2 << ";" << std::endl;
+ std::cout << "hm3 = " << hm3 << ";" << std::endl;
+}
Index: trunk/milena/tests/vec.cc
===================================================================
--- trunk/milena/tests/vec.cc (revision 0)
+++ trunk/milena/tests/vec.cc (revision 1305)
@@ -0,0 +1,64 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/image2d.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+
+#include <iostream>
+#include <mln/fun/i2v/all.hh>
+#include <mln/metal/vec.hh>
+#include <mln/core/h_vec.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ metal::vec<1,float> v1(all(4.));
+ metal::vec<2,float> v2 = make::vec(6., 2.8);
+
+ h_vec<1,float> hv1;
+ h_vec<2,float> hv2(v2);
+ h_vec<3,float> hv3(all(1.5));
+
+ hv3 += make::vec(0., 0., 0., 0.5);
+
+ metal::vec<3,float> v3 = hv3;
+ metal::vec<4,float> v4 = hv3;
+
+ std::cout << "v1 = " << v1 << ";" << std::endl;
+ std::cout << "v2 = " << v2 << ";" << std::endl;
+ std::cout << "v3 = " << v3 << ";" << std::endl;
+ std::cout << "v4 = " << v4 << ";" << std::endl;
+ std::cout << "hv1 = " << hv1 << ";" << std::endl;
+ std::cout << "hv2 = " << hv2 << ";" << std::endl;
+ std::cout << "hv3 = " << hv3 << ";" << std::endl;
+}
Index: trunk/milena/mln/metal/mat.hh
===================================================================
--- trunk/milena/mln/metal/mat.hh (revision 1304)
+++ trunk/milena/mln/metal/mat.hh (revision 1305)
@@ -31,6 +31,7 @@
# include <iostream>
# include <mln/core/concept/object.hh>
+# include <mln/core/concept/function.hh>
# include <mln/core/contract.hh>
# include <mln/trait/all.hh>
# include <mln/value/props.hh>
@@ -66,6 +67,10 @@
template <typename U>
mat(const mat<n,m,U>& rhs);
+ /// Constructor; coordinates are set by function \p f.
+ template <typename F>
+ mat(const Function_i2v<F>& f);
+
template <typename U>
mat& operator=(const mat<n,m,U>& rhs);
@@ -281,6 +286,17 @@
}
template <unsigned n, unsigned m, typename T>
+ template <typename F>
+ mat<n,m,T>::mat(const Function_i2v<F>& f_)
+ {
+ mlc_converts_to(mln_result(F), T)::check();
+ const F& f = exact(f_);
+ for (unsigned i = 0; i < n; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ data_[i][j] = f(i * n + j);
+ }
+
+ template <unsigned n, unsigned m, typename T>
template <typename U>
mat<n,m,T>&
mat<n,m,T>::operator=(const mat<n,m,U>& rhs)
Index: trunk/milena/mln/metal/vec.hh
===================================================================
--- trunk/milena/mln/metal/vec.hh (revision 1304)
+++ trunk/milena/mln/metal/vec.hh (revision 1305)
@@ -414,6 +414,7 @@
template <typename F>
vec<n, T>::vec(const Function_i2v<F>& f_)
{
+ mlc_converts_to(mln_result(F), T)::check();
const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
data_[i] = f(i);
Index: trunk/milena/mln/make/vec.hh
===================================================================
--- trunk/milena/mln/make/vec.hh (revision 1304)
+++ trunk/milena/mln/make/vec.hh (revision 1305)
@@ -45,15 +45,6 @@
/*! \brief Create an mln::metal::vec<n,T>.
*
- * \param[in] f Function.
- *
- * \return A nD vector filled with the function \p f .
- */
- template <unsigned n, typename T, typename F>
- metal::vec<n, T> vec(const Function_i2v<F>& f_);
-
- /*! \brief Create an mln::metal::vec<n,T>.
- *
* \param[in] v_0 First coordinate.
*
* \return A 1D vector.
@@ -97,17 +88,6 @@
# ifndef MLN_INCLUDE_ONLY
- template <unsigned n, typename T, typename F>
- metal::vec<n, T> vec(const Function_i2v<F>& f_)
- {
- mlc_converts_to(mln_result(F), T)::check();
- F f = exact(f_);
- metal::vec<n, T> tmp;
- for (unsigned i; i < n; ++i)
- tmp[i] = f(i);
- return tmp;
- }
-
template <typename T>
metal::vec<1, T> vec(const T& v_0)
{
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add int_s16 test.
* mln/value/int_s16.hh: New, signed int on 16bits.
* tests/value_int_s16.cc: New, tests.
---
mln/value/int_s16.hh | 55 ++++++++++++
tests/value_int_s16.cc | 213 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 268 insertions(+)
Index: trunk/milena/tests/value_int_s16.cc
===================================================================
--- trunk/milena/tests/value_int_s16.cc (revision 0)
+++ trunk/milena/tests/value_int_s16.cc (revision 1302)
@@ -0,0 +1,213 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/value_int_s16.cc
+ *
+ * \brief Tests on mln::value::int_s16.
+ */
+
+#include <mln/value/int_s16.hh>
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+
+// test_operator
+
+int main()
+{
+ using namespace mln;
+ using value::int_s16;
+
+ int_s16 i = 3, j;
+
+ // Assignment.
+ {
+ i = 51;
+ mln_assertion(i == 51);
+
+ i = 51u;
+ mln_assertion(i == 51);
+
+ signed char c = 51;
+ i = c;
+ mln_assertion(i == 51);
+
+ j = i;
+ mln_assertion(j == 51);
+
+ i = 3;
+ mln_assertion(3.0f == i);
+ mln_assertion(i != 2.99f);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
+ }
+
+
+ // Comparaison
+ {
+ int_s16 i = 42;
+ int_s16 j = 51;
+
+ mln_assertion(i < j);
+ mln_assertion(j > i);
+ mln_assertion(i < 12345);
+ mln_assertion(12345 > i);
+
+ mln_assertion(i != j);
+ mln_assertion(i == 42);
+ mln_assertion(42 == i);
+ mln_assertion(i != 69);
+ mln_assertion(69 != i);
+
+ }
+
+ // Addition.
+ {
+ test_operator(int_s16, +, -5, 1);
+ test_interop(int_s16, int, +, 5, -1);
+ test_interop(int_s16, char, +, -4, 2);
+ test_interop(int_s16, unsigned char, +, 4, 2);
+
+ int_s16 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
+ }
+
+ // Soustraction
+ {
+ test_operator(int_s16, -, 100, 5);
+ test_interop(int_s16, int, -, 100, 5);
+ test_interop(int_s16, char, -, 100, 5);
+ test_interop(int_s16, unsigned char, -, 100, 5);
+
+ int_s16 c = 255;
+ c -= c;
+
+ mln_assertion(c == 0);
+
+ int_s16 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
+ }
+
+ // Multiplication
+ {
+ test_operator(int_s16, *, 5, 1);
+ test_interop(int_s16, int, *, 5, 1);
+ test_interop(int_s16, char, *, 4, 2);
+ test_interop(int_s16, unsigned char, *, 4, 2);
+
+ int_s16 c = 255;
+
+ c *= 0;
+ mln_assertion(c == 0);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char d = 0;
+ i *= d;
+ mln_assertion(i == 0);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
+ }
+
+ // Division
+ {
+ test_operator(int_s16, /, 5, 1);
+ test_interop(int_s16, int, /, 5, 1);
+ test_interop(int_s16, char, /, 4, 2);
+ test_interop(int_s16, unsigned char, /, 4, 2);
+
+ int_s16 c = 200;
+
+ c /= 1;
+ mln_assertion(c == 200);
+ c /= 2;
+ mln_assertion(c == 100);
+
+ int_s16 d = 2;
+ c /= 2;
+ mln_assertion(c == 50);
+
+ }
+
+
+ // Modulo
+ {
+ test_operator(int_s16, %, 5, 10);
+ test_interop(int_s16, int, %, 5, 10);
+ test_interop(int_s16, char, %, 4, 20);
+ test_interop(int_s16, unsigned char, %, 4, 20);
+ }
+}
Index: trunk/milena/mln/value/int_s16.hh
===================================================================
--- trunk/milena/mln/value/int_s16.hh (revision 0)
+++ trunk/milena/mln/value/int_s16.hh (revision 1302)
@@ -0,0 +1,55 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_INT_S16_HH
+# define MLN_VALUE_INT_S16_HH
+
+/*! \file mln/value/int_s16.hh
+ *
+ * \brief Define the alias value::int_s16.
+ */
+
+# include <mln/value/int_s.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for signed 16 bit integers.
+ typedef int_s<16> int_s16;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S16_HH