URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-11 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix graylevel. Tests on graylevel.
* mln/value/graylevel.hh: Re add operator=(int)
* tests/value_int_u8.cc: More tests.
* tests/value_graylevel.cc: Likewise. FIXME : to augment.
---
mln/value/graylevel.hh | 10 +++
tests/value_graylevel.cc | 144 +++++++++++++++++++++++++++++++++++++++++++----
tests/value_int_u8.cc | 94 ++++++++++--------------------
3 files changed, 175 insertions(+), 73 deletions(-)
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1319)
+++ trunk/milena/tests/value_int_u8.cc (revision 1320)
@@ -31,37 +31,7 @@
*/
#include <mln/value/int_u8.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
+#include <tests/value_macros.hh>
int main()
{
@@ -73,21 +43,21 @@
// Assignment.
{
i = 51;
- mln_assertion(i == 51);
+ sym_compare_assert(i, ==, 51);
i = 51u;
- mln_assertion(i == 51);
+ sym_compare_assert(i, ==, 51);
signed char c = 51;
i = c;
- mln_assertion(i == 51);
+ sym_compare_assert(i, ==, 51);
j = i;
- mln_assertion(j == 51);
+ sym_compare_assert(j, ==, 51);
i = 3;
- mln_assertion(3.0f == i);
- mln_assertion(i != 2.99f);
+ sym_compare_assert(3.0f, ==, i);
+ sym_compare_assert(i, !=, 2.99f);
// Error at run-time as expected :-)
// i = 256;
@@ -101,16 +71,16 @@
int_u8 i = 42;
int_u8 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);
+ asym_compare_assert(i, <, j);
+ asym_compare_assert(j, >, i);
+ asym_compare_assert(i, <, 12345.f);
+ asym_compare_assert(12345.f, >, i);
+
+ sym_compare_assert(i, !=, j);
+ sym_compare_assert(i, ==, 42.f);
+ sym_compare_assert(42.f, ==, i);
+ sym_compare_assert(i, !=, 69.f);
+ sym_compare_assert(69.f, !=, i);
}
@@ -124,13 +94,13 @@
int_u8 i = 234;
i++;
- mln_assertion(i == 235);
+ sym_compare_assert(i, ==, 235.f);
++i;
- mln_assertion(i == 236);
+ sym_compare_assert(i, ==, 236.f);
i = +i;
- mln_assertion(i == 236);
+ sym_compare_assert(i, ==, 236.f);
}
@@ -139,26 +109,24 @@
test_operator(int_u8, -, 100, 5);
test_interop(int_u8, int, -, 100, 5);
test_interop(int_u8, char, -, 100, 5);
- test_interop(int_u8, unsigned char, -, 100, 5);
+ test_interop(int_u8, unsigned char, -, 5, 5);
int_u8 c = 255;
c -= c;
- mln_assertion(c == 0);
+ sym_compare_assert(c, ==, 0.f);
int_u8 i = 236;
i--;
- mln_assertion(i == 235);
+ sym_compare_assert(i, ==, 235.f);
--i;
- mln_assertion(i == 234);
+ sym_compare_assert(i, ==, 234.f);
- std::cout << (-i) << " FIXME Matthieu: add .f to literals "
<< i << std::endl;
- mln_assertion(-i == -234); // FIXME: old version
- mln_assertion(-i == -234.f); // FIXME: new better version
+ sym_compare_assert(-i, ==, -234.f);
- mln_assertion(i * -2 != 0.f);
+ sym_compare_assert(i * -2, !=, 0.f);
std::cout << (i) << " * -2 = "
<< (i * -2) << ' '
<< (-2 * i) << ' '
@@ -176,14 +144,14 @@
int_u8 c = 255;
c *= 0;
- mln_assertion(c == 0);
+ sym_compare_assert(c, ==, 0.f);
i *= 2;
int k; k *= i;
unsigned char d = 0;
i *= d;
- mln_assertion(i == 0);
+ sym_compare_assert(i, ==, 0.f);
// Error at run-time as expected :-)
// i = 128;
@@ -201,13 +169,13 @@
int_u8 c = 200;
c /= 1;
- mln_assertion(c == 200);
+ sym_compare_assert(c, ==, 200.f);
c /= 2;
- mln_assertion(c == 100);
+ sym_compare_assert(c, ==, 100.f);
int_u8 d = 2;
c /= 2;
- mln_assertion(c == 50);
+ sym_compare_assert(c, ==, 50.f);
}
Index: trunk/milena/tests/value_graylevel.cc
===================================================================
--- trunk/milena/tests/value_graylevel.cc (revision 1319)
+++ trunk/milena/tests/value_graylevel.cc (revision 1320)
@@ -27,7 +27,9 @@
/*! \file tests/value_graylevel.cc
*
- * \brief Tests on mln::value::graylevel.
+ * \brief Tests on mln::value::graylevel. Tests operations between
+ * graylevel of different encodings.
+ *
*/
@@ -45,22 +47,144 @@
using mln::literal::white;
using mln::literal::black;
+ // Literals
+ {
gl8 a = white;
- gl16 b = black;
+ gl16 b = white;
+
mln_assertion(a == b);
- mln_assertion(a.value() != b.value());
+ mln_assertion(a.value() == 255);
+ mln_assertion(b.value() == 65535);
- gl8 c = (a + b) / 2;
+ gl8 c = (white + white) / 2;
mln_assertion(c == white);
mln_assertion(c.value() == 255);
- c = a;
- mln_assertion(c == white);
+ a = black;
+ b = black;
- c = (a * 2) / 2;
- mln_assertion(c == white);
+ mln_assertion(a == b);
+ mln_assertion(a.value() == 0);
+ mln_assertion(b.value() == 0);
+
+ c = (black + black) / 2;
+ mln_assertion(c == black);
+ mln_assertion(c.value() == 0);
+ }
+
+ // Assigment
+ {
+ gl8 a;
+ gl8 b;
+
+ a = white;
+ mln_assertion(a == white);
+ mln_assertion(a.value() == 255);
+
+ a = 23;
+ mln_assertion(a != white);
+ mln_assertion(a != black);
+ mln_assertion(a.value() == 23);
+
+ b = 2;
+ mln_assertion(b != white);
+ mln_assertion(b != black);
+ mln_assertion(b.value() == 2);
+
+ a = b;
+ mln_assertion(a.value() == 2);
+
+ signed char c = 51;
+ a = c;
+ mln_assertion(a.value() == 51);
+
+ // bounds
+ a = 255;
+ mln_assertion(a.value() == 255);
+ a = 0;
+ mln_assertion(a.value() == 0);
+ }
+
+ // Addition
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 + gl8
+ a = 42;
+ b = 16969;
+ a += a;
+ mln_assertion(a.value() == 84);
+
+ a = 42;
+ b = 16969;
+ a = a + a;
+ mln_assertion(a.value() == 84);
+
+ // gl8 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ a = a + b;
+ mln_assertion(a.value() == (42 + b.value() / 257) );
+ a = 42;
+ b = 16969;
+ a += b;
+ mln_assertion(a.value() == (42 + b.value() / 257) );
+
+
+ // gl16 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ b += a;
+ mln_assertion(b.value() == (42 * 257 + 16969) );
+
+ a = 42;
+ b = 16969;
+ b = a + b;
+ mln_assertion(b.value() == (42 * 257 + 16969) );
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a + b;
+ mln_assertion(a.value() == 255);
+
+ a = 0;
+ b = 65535;
+ a = a + b;
+ mln_assertion(a.value() == 255);
+ }
+
+
+
+ // Not exhaustive
+
+ // gl8 a = white;
+ // gl16 b = white;
+ // mln_assertion(a == b);
+ // // mln_assertion(-a == -b);
+
+ // mln_assertion(a.value() != b.value());
+
+ // {
+ // gl8 c = (a + b) / 2;
+ // mln_assertion(c == white);
+ // mln_assertion(c.value() == 255);
+
+ // c = a;
+ // mln_assertion(c == white);
+
+ // c = (a * 2) / 2;
+ // mln_assertion(c == white);
+
+ // c = c / 6;
+ // }
- c = c / 6;
+ // {
+ // gl8 c = (white + white) / 2;
+ // mln_assertion(c == white);
+ // mln_assertion(c.value() == 255);
+ // }
- gray g = black;
+ // gray g = black;
}
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1319)
+++ trunk/milena/mln/value/graylevel.hh (revision 1320)
@@ -162,6 +162,16 @@
template <unsigned n>
graylevel<n>&
+ graylevel<n>::operator=(int val)
+ {
+ mln_precondition(val >= 0);
+ mln_precondition(unsigned(val) <= mln_max(mln_enc(int_u<n>)));
+ this->v_ = val;
+ return *this;
+ }
+
+ template <unsigned n>
+ graylevel<n>&
graylevel<n>::operator=(const literal::black_t&)
{
this->v_ = 0;
Index: trunk/milena/mln/value/gray.hh
===================================================================