Skip to content

Implement Vector equals #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V2.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V2(final P2<A, A> inner) {
this.inner = inner;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V2.class, this, other, () -> Equal.v2Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v2Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-2 from a homogeneous product-2.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V3.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V3(final P1<A> head, final V2<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V3.class, this, other, () -> Equal.v3Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v3Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-3 from a homogeneous product-3.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V4.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V4(final P1<A> head, final V3<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V4.class, this, other, () -> Equal.v4Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v4Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-4 from a homogeneous product-4.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V5.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V5(final P1<A> head, final V4<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V5.class, this, other, () -> Equal.v5Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v5Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-5 from a homogeneous product-5.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V6.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V6(final P1<A> head, final V5<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V6.class, this, other, () -> Equal.v6Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v6Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-6 from a homogeneous product-6.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V7.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V7(final P1<A> head, final V6<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V7.class, this, other, () -> Equal.v7Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v7Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-7 from a homogeneous product-7.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/fj/data/vector/V8.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ private V8(final P1<A> head, final V7<A> tail) {
this.tail = tail;
}

@Override
public final boolean equals(Object other) {
return Equal.equals0(V8.class, this, other, () -> Equal.v8Equal(Equal.anyEqual()));
}

@Override
public final int hashCode() {
return Hash.v8Hash(Hash.<A>anyHash()).hash(this);
}

/**
* Creates a vector-8 from a homogeneous product-8.
*
Expand Down
60 changes: 52 additions & 8 deletions core/src/test/java/fj/data/vector/VTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package fj.data.vector;

import fj.P;
import fj.P2;
import fj.P3;
import fj.P4;
import fj.P5;
import fj.P6;
import fj.P7;
import fj.P8;
import fj.*;
import fj.data.Array;
import org.junit.Test;

Expand Down Expand Up @@ -59,4 +52,55 @@ public void testVectorP(){
assertThat(v8.toArray(), is(Array.range(1, 9)));
assertThat(v8.p(), is(p8));
}

@Test
public void testVectorFunc2() {
V2<Integer> v2 = V.v(() -> 2, () -> 1);
F2<Integer, Integer, V2<Integer>> fv2 = V.v2();
V2<Integer> vf2 = fv2.f(2, 1);
assertThat(vf2, is(v2));
}

@Test
public void testVectorFunc3() {
V3<Integer> v3 = V.v(P.p(3), () -> 2, () -> 1);
F3<Integer, Integer, Integer, V3<Integer>> fv3 = V.v3();
V3<Integer> vf3 = fv3.f(3, 2, 1);
assertThat(vf3, is(v3));
}

@Test
public void testVectorFunc4() {
V4<Integer> v4 = V.v(P.p(4), P.p(3), () -> 2, () -> 1);
F4<Integer, Integer, Integer, Integer, V4<Integer>> fv4 = V.v4();
V4<Integer> vf4 = fv4.f(4, 3, 2, 1);
assertThat(vf4, is(v4));
}

@Test
public void testVectorFunc5() {
V5<Integer> v5 = V.v(P.p(5), P.p(4), P.p(3), () -> 2, () -> 1);
F5<Integer, Integer, Integer, Integer, Integer, V5<Integer>> fv5 = V.v5();
V5<Integer> vf5 = fv5.f(5, 4, 3, 2, 1);
assertThat(vf5, is(v5));
}

@Test
public void testVectorMap() {
final V2<Integer> v2 = V.v(() -> 2, () -> 1);
assertThat(v2, is(v2.map(i -> i * 1)));
final V3<Integer> v3 = V3.cons(P.p(3), v2);
assertThat(v3, is(v3.map(i -> i * 1)));
final V4<Integer> v4 = V4.cons(P.p(4), v3);
assertThat(v4, is(v4.map(i -> i * 1)));
final V5<Integer> v5 = V5.cons(P.p(5), v4);
assertThat(v5, is(v5.map(i -> i * 1)));
final V6<Integer> v6 = V6.cons(P.p(6), v5);
assertThat(v6, is(v6.map(i -> i * 1)));
final V7<Integer> v7 = V7.cons(P.p(7), v6);
assertThat(v7, is(v7.map(i -> i * 1)));
final V8<Integer> v8 = V8.cons(P.p(8), v7);
assertThat(v8, is(v8.map(i -> i * 1)));
}

}