Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[core] Implement FixedIntegerArray.is_equal

git-svn-id: https://svn.parrot.org/parrot/trunk@41377 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 0c38764c9c8e9d3a0c84b6c0a2e698d89182d462 1 parent 456e188
Vasily Chekalkin bacek authored
Showing with 58 additions and 2 deletions.
  1. +32 −0 src/pmc/fixedintegerarray.pmc
  2. +26 −2 t/pmc/fixedintegerarray.t
32 src/pmc/fixedintegerarray.pmc
View
@@ -584,6 +584,38 @@ Sets the string value of the element at index C<key> to C<value>.
/*
+=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.
28 t/pmc/fixedintegerarray.t
View
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.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 @@ out-of-bounds test. Checks INT and PMC keys.
'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 @@ out-of-bounds test. Checks INT and PMC keys.
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
Please sign in to comment.
Something went wrong with that request. Please try again.