URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Finalise an exhaustive int_u8 test.
* mln/value/concept/scalar.hh: (operator %=) New.
* tests/value_int_u8.cc: Add tests.
---
mln/value/concept/scalar.hh | 12 ++++++++++
tests/value_int_u8.cc | 52 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1300)
+++ trunk/milena/tests/value_int_u8.cc (revision 1301)
@@ -95,12 +95,43 @@
// i = 255, ++i;
}
+
+ // Comparaison
+ {
+ 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);
+
+ }
+
// Addition.
{
test_operator(int_u8, +, 5, 1);
test_interop(int_u8, int, +, 5, -1);
test_interop(int_u8, char, +, 4, 2);
test_interop(int_u8, unsigned char, +, 4, 2);
+
+ int_u8 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
}
// Soustraction
@@ -115,6 +146,15 @@
mln_assertion(c == 0);
+ int_u8 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
}
// Multiplication
@@ -132,8 +172,8 @@
i *= 2;
int k; k *= i;
- unsigned char c = 0;
- i *= c;
+ unsigned char d = 0;
+ i *= d;
mln_assertion(i == 0);
// Error at run-time as expected :-)
@@ -162,4 +202,12 @@
}
+
+ // Modulo
+ {
+ test_operator(int_u8, %, 5, 10);
+ test_interop(int_u8, int, %, 5, 10);
+ test_interop(int_u8, char, %, 4, 20);
+ test_interop(int_u8, unsigned char, %, 4, 20);
+ }
}
Index: trunk/milena/mln/value/concept/scalar.hh
===================================================================
--- trunk/milena/mln/value/concept/scalar.hh (revision 1300)
+++ trunk/milena/mln/value/concept/scalar.hh (revision 1301)
@@ -96,6 +96,9 @@
template <typename S>
S& operator-=(value::Scalar<S>& lhs, typename S::interop i);
+ template <typename S>
+ S& operator%=(value::Scalar<S>& lhs, typename S::interop i);
+
# ifndef MLN_INCLUDE_ONLY
@@ -146,6 +149,15 @@
return lhs;
}
+
+ template <typename S>
+ S& operator%=(value::Scalar<S>& lhs_, typename S::interop i)
+ {
+ S& lhs = exact(lhs_);
+ lhs = lhs % i;
+ return lhs;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln