[svn:parrot] r41377 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun Sep 20 13:39:18 UTC 2009
Author: bacek
Date: Sun Sep 20 13:39:17 2009
New Revision: 41377
URL: https://trac.parrot.org/parrot/changeset/41377
Log:
[core] Implement FixedIntegerArray.is_equal
Modified:
trunk/src/pmc/fixedintegerarray.pmc
trunk/t/pmc/fixedintegerarray.t
Modified: trunk/src/pmc/fixedintegerarray.pmc
==============================================================================
--- trunk/src/pmc/fixedintegerarray.pmc Sun Sep 20 13:29:35 2009 (r41376)
+++ trunk/src/pmc/fixedintegerarray.pmc Sun Sep 20 13:39:17 2009 (r41377)
@@ -584,6 +584,38 @@
/*
+=item C<INTVAL is_equal(PMC *value)>
+
+The C<==> operation. Compares two array to hold equal elements.
+
+=cut
+
+*/
+
+ VTABLE INTVAL is_equal(PMC *value) {
+ INTVAL j, n;
+
+ if (value->vtable->base_type != SELF->vtable->base_type)
+ return 0;
+
+ n = SELF.elements();
+
+ if (VTABLE_elements(INTERP, value) != n)
+ return 0;
+
+ for (j = 0; j < n; ++j) {
+ INTVAL item1 = SELF.get_integer_keyed_int(j);
+ INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
+
+ if (item1 != item2)
+ return 0;
+ }
+
+ return 1;
+ }
+
+/*
+
=item C<PMC *get_iter()>
Return a new Iterator for this PMC.
Modified: trunk/t/pmc/fixedintegerarray.t
==============================================================================
--- trunk/t/pmc/fixedintegerarray.t Sun Sep 20 13:29:35 2009 (r41376)
+++ trunk/t/pmc/fixedintegerarray.t Sun Sep 20 13:39:17 2009 (r41377)
@@ -19,7 +19,7 @@
.sub 'main' :main
.include 'test_more.pir'
- plan(24)
+ plan(29)
'test_set_size'() # 2 tests
'test_reset_size'() # 1 test
@@ -29,7 +29,8 @@
'test_set_via_pmc'() # 3 tests
'test_get_via_pmc'() # 4 tests
'test_interface_done'() # 4 tests
- 'test_get_iter'() # 1 tests
+ 'test_get_iter'() # 1 test
+ 'test_equality'() # 5 tests
.end
.sub 'test_set_size'
@@ -211,6 +212,29 @@
is($S0, "424344", "Iteration works")
.end
+.sub 'test_equality'
+ .local pmc a1, a2
+ a1 = new ['FixedIntegerArray']
+ a2 = new ['FixedIntegerArray']
+
+ is(a1, a2, "Empty arrays are equal")
+
+ a1 = 3
+ isnt(a1, a2, "Different size arrays aren't equal")
+
+ a2 = 3
+
+ a1[0] = 42
+ a2[0] = 42
+ is(a1, a2, "Equal with first element set")
+
+ a1[1] = 84
+ isnt(a1, a2, "Not equal when second element differ")
+
+ a2[1] = 84
+ is(a1, a2, "Equal when second element same")
+.end
+
# Local Variables:
# mode: cperl
More information about the parrot-commits
mailing list