vala r2301 - in trunk: . tests tests/basic-types
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2301 - in trunk: . tests tests/basic-types
- Date: Fri, 9 Jan 2009 13:10:53 +0000 (UTC)
Author: juergbi
Date: Fri Jan 9 13:10:53 2009
New Revision: 2301
URL: http://svn.gnome.org/viewvc/vala?rev=2301&view=rev
Log:
2009-01-09 JÃrg Billeter <j bitron ch>
* tests/Makefile.am:
* tests/basic-types/integers.test:
Improve integer tests
Modified:
trunk/ChangeLog
trunk/tests/Makefile.am
trunk/tests/basic-types/integers.test
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Fri Jan 9 13:10:53 2009
@@ -15,8 +15,8 @@
TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) $(srcdir)/testrunner.sh
TESTS = \
- basic-types/floats.test \
basic-types/integers.test \
+ basic-types/floats.test \
basic-types/strings.test \
basic-types/test-027.test \
namespaces.test \
Modified: trunk/tests/basic-types/integers.test
==============================================================================
--- trunk/tests/basic-types/integers.test (original)
+++ trunk/tests/basic-types/integers.test Fri Jan 9 13:10:53 2009
@@ -1,177 +1,85 @@
Program: test
-using GLib;
-
-class Maman.Bar : Object {
- static void test_binary_expressions () {
- stdout.printf ("Binary Expression Test: 1");
-
- stdout.printf (" %d", 1 + 1);
-
- stdout.printf (" %d", 4 - 1);
-
- stdout.printf (" %d", 2 * 2);
-
- stdout.printf (" %d", 10 / 2);
-
- stdout.printf (" %d", 13 % 7);
-
- stdout.printf (" %d", (4 << 1) - 1);
-
- stdout.printf (" %d", 16 >> 1);
-
- if (1 < 2) {
- stdout.printf (" 9");
- } else {
- stdout.printf (" BAD");
- }
-
- if (1 > 2) {
- stdout.printf (" BAD");
- } else {
- stdout.printf (" 10");
- }
-
- if (1 <= 2) {
- stdout.printf (" 11");
- } else {
- stdout.printf (" BAD");
- }
-
- if (1 >= 2) {
- stdout.printf (" BAD");
- } else {
- stdout.printf (" 12");
- }
-
- if (1 == 1) {
- stdout.printf (" 13");
- } else {
- stdout.printf (" BAD");
- }
-
- if (1 != 1) {
- stdout.printf (" BAD");
- } else {
- stdout.printf (" 14");
- }
-
- stdout.printf (" %d", 31 & 47);
-
- stdout.printf (" %d", 0 | 16);
-
- stdout.printf (" %d", 16 ^ 1);
-
- if (true && false) {
- stdout.printf (" BAD");
- } else {
- stdout.printf (" 18");
- }
-
- if (true || false) {
- stdout.printf (" 19");
- } else {
- stdout.printf (" BAD");
- }
-
- stdout.printf (" 20\n");
- }
-
- static void test_assignments () {
- stdout.printf ("Assignment Test: 1");
-
- int i;
-
- i = 2;
- stdout.printf (" %d", i);
-
- i |= 1;
- stdout.printf (" %d", i);
-
- i = 5;
- i &= 6;
- stdout.printf (" %d", i);
-
- i ^= 1;
- stdout.printf (" %d", i);
-
- i += 1;
- stdout.printf (" %d", i);
-
- i -= -1;
- stdout.printf (" %d", i);
-
- i = 2;
- i *= 4;
- stdout.printf (" %d", i);
-
- i = 18;
- i /= 2;
- stdout.printf (" %d", i);
-
- i = 21;
- i %= 11;
- stdout.printf (" %d", i);
-
- i = 6;
- i <<= 1;
- stdout.printf (" %d", i - 1);
-
- i = 25;
- i >>= 1;
- stdout.printf (" %d", i);
-
- i = 12;
- i -= 1 - 2;
- stdout.printf (" %d", i);
-
- stdout.printf (" 14\n");
- }
-
- static void test_ranges () {
- stdout.printf (
- "int8: %s...%s\n",
- int8.MIN.to_string (),
- int8.MAX.to_string ());
- stdout.printf (
- "int16: %s...%s\n",
- int16.MIN.to_string (),
- int16.MAX.to_string ());
- stdout.printf (
- "int32: %s...%s\n",
- int32.MIN.to_string (),
- int32.MAX.to_string ());
- stdout.printf (
- "int64: %s...%s\n",
- int64.MIN.to_string (),
- int64.MAX.to_string ());
-
- stdout.printf (
- "uint8: %s...%s\n",
- uint8.MIN.to_string (),
- uint8.MAX.to_string ());
- stdout.printf (
- "uint16: %s...%s\n",
- uint16.MIN.to_string (),
- uint16.MAX.to_string ());
- stdout.printf (
- "uint32: %s...%s\n",
- uint32.MIN.to_string (),
- uint32.MAX.to_string ());
- stdout.printf (
- "uint64: %s...%s\n",
- uint64.MIN.to_string (),
- uint64.MAX.to_string ());
- }
-
- static int main (string[] args) {
- test_binary_expressions ();
-
- test_assignments ();
-
- test_ranges ();
+void test_int () {
+ // declaration and initialization
+ int i = 42;
+ assert (i == 42);
+
+ // assignment
+ i = 23;
+ assert (i == 23);
+
+ // access
+ int j = i;
+ assert (j == 23);
+
+ // +
+ i = 42 + 23;
+ assert (i == 65);
+
+ // -
+ i = 42 - 23;
+ assert (i == 19);
+
+ // *
+ i = 42 * 23;
+ assert (i == 966);
+
+ // /
+ i = 42 / 23;
+ assert (i == 1);
+
+ // %
+ i = 42 % 23;
+ assert (i == 19);
+
+ // <<
+ i = 42 << 3;
+ assert (i == 336);
+
+ // >>
+ i = 42 >> 3;
+ assert (i == 5);
+
+ // &
+ i = 42 & 23;
+ assert (i == 2);
+
+ // |
+ i = 42 | 23;
+ assert (i == 63);
+
+ // ^
+ i = 42 ^ 23;
+ assert (i == 61);
+
+ // equality and relational
+ i = 42;
+ assert (i == 42);
+ assert (i != 50);
+ assert (i < 50);
+ assert (!(i < 40));
+ assert (i <= 42);
+ assert (!(i <= 41));
+ assert (i >= 42);
+ assert (!(i >= 43));
+ assert (i > 40);
+ assert (!(i > 50));
+
+ // to_string
+ string s = i.to_string ();
+ assert (s == "42");
+
+ // ensure that MIN and MAX are valid values
+ i = int.MIN;
+ assert (i == int.MIN);
+ assert (i < int.MAX);
+ i = int.MAX;
+ assert (i == int.MAX);
+ assert (i > int.MIN);
+}
- return 0;
- }
+void main () {
+ test_int ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]