Skip to content

Commit

Permalink
Test coverage & fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentk committed Jan 2, 2025
1 parent 13a0aa3 commit a5e35f7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ default boolean isEmpty() {

// TODO: the cardinality of the union is actually not known
// at this point:
return new Union<E, C>(this, (NonEmptySet<E, ?, ?>) cpl);
return new Union<E, C>((NonEmptySet<E, ?, ?>) cpl, (NonEmptySet<E, ?, ?>) that);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public interface SingletonSet<E extends Element<E>, S extends SingletonSet<E, S>
FiniteSet.B64<E, Small.One, S>
{
E elem();


@Override
default boolean contains(E that) {
return elem().eq(that);
}

@Override
default Set<E, ? extends Small.One, ?> where(Predicate<E> Φ) {
return Φ.test(elem()) ? this : EmptySet.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ record Union<
implements
NonEmptySet<E, C, Union<E, C>>
{
@Override
public boolean
contains(E elem) {
return fst().contains(elem) || snd().contains(elem);
}

@Override
public
Set<E, ?, ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.vincentk.dedekind.sets;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.github.vincentk.dedekind.algebra.numbers.N;

public class UnionTest {

private static final SingletonSet<N.N63.Ne, ?> S1 = new SingletonSet.Ordered.Default<>(N.ONE);
private static final SingletonSet<N.N63.Ne, ?> S2 = new SingletonSet.Ordered.Default<>(N.TWO);
private static final EmptySet<N.N63.Ne> EMPTY = EmptySet.empty();

@Test
public void testConstruction() {
assertThat(EMPTY.union(EMPTY)).isEqualTo(EMPTY);
assertThat(S1.union(EMPTY)).isEqualTo(S1);
assertThat(EMPTY.union(S1)).isEqualTo(S1);
assertThat(S1.union(S1)).isEqualTo(S1);

final var u2 = S1.union(S2);
assertThat(u2).isInstanceOf(Union.class);
assertThat(u2.contains(N.ONE)).isTrue();
assertThat(u2.contains(N.TWO)).isTrue();
}

@Test
public void testEmptySet() {

final var SUBJECT = S1.union(S1);

assertTrue(SUBJECT.eq(SUBJECT));

assertThat(SUBJECT.intersection(SUBJECT)).isEqualTo(SUBJECT);

assertThat(SUBJECT.union(SUBJECT)).isEqualTo(SUBJECT);

assertThat(SUBJECT.sub(SUBJECT))
.as(() -> "The empty set is a subset of itself.")
.isTrue();

assertThat(SUBJECT.sup(SUBJECT))
.as(() -> "The empty set is a super-set of itself.")
.isTrue();

assertThat(SUBJECT.where(x -> true))
.as(() -> "A conditioned empty set is still empty.")
.isEqualTo(SUBJECT);

assertThat(SUBJECT.complement(SUBJECT))
.as(() -> "The difference between the empty set and itself empty.")
.isEqualTo(EmptySet.empty());
}
}

0 comments on commit a5e35f7

Please sign in to comment.