Skip to content

Commit

Permalink
Fix style warnings, reformat assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Mar 18, 2024
1 parent 81301f3 commit 92964cd
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 178 deletions.
18 changes: 11 additions & 7 deletions src/test/java/org/cactoos/list/SyncedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.RunsInThreads;

/**
Expand All @@ -38,29 +39,32 @@
final class SyncedTest {

@Test
void behavesAsCollection() throws Exception {
MatcherAssert.assertThat(
void behavesAsCollection() {
new Assertion<>(
"Can't behave as a list",
new Synced<>(new ListOf<>(1, 0, -1, -1, 2)),
new BehavesAsList<>(0)
);
).affirm();
}

@Test
void worksInThreads() {
MatcherAssert.assertThat(
new Assertion<>(
"should be run in threads",
list -> !list.iterator().hasNext(),
new RunsInThreads<>(new Synced<>(Collections.emptyList()))
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"should work as list",
list -> {
MatcherAssert.assertThat(
"should behave as a list",
list,
new BehavesAsList<>(0)
);
return true;
},
new RunsInThreads<>(new Synced<>(new ListOf<>(1, 0, -1, -1, 2)))
);
).affirm();
}
}
82 changes: 49 additions & 33 deletions src/test/java/org/cactoos/number/MinOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package org.cactoos.number;

import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link MinOf}.
Expand All @@ -37,114 +37,130 @@ final class MinOfTest {

@Test
void withIntegerCollection() {
MatcherAssert.assertThat(
new Assertion<>(
"must select minimum integer of positive integers",
new MinOf(
new ListOf<>(1, 2, 3, 4).toArray(new Integer[4])
).intValue(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum long of positive integers",
new MinOf(
new ListOf<>(1, 2, 3, 4).toArray(new Integer[4])
).longValue(),
Matchers.equalTo(1L)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum double of positive integers",
new MinOf(
new ListOf<>(1, 2, 3, 4).toArray(new Integer[4])
).doubleValue(),
Matchers.equalTo(1.0d)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum float of positive integers",
new MinOf(
new ListOf<>(1, 2, 3, 4).toArray(new Integer[4])
).floatValue(),
Matchers.equalTo(1.0f)
);
).affirm();
}

@Test
void withLongCollection() {
MatcherAssert.assertThat(
new Assertion<>(
"must select minimum integer of positive longs",
new MinOf(
new ListOf<>(1L, 2L, 3L, 4L).toArray(new Long[4])
).intValue(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum long of positive longs",
new MinOf(
new ListOf<>(1L, 2L, 3L, 4L).toArray(new Long[4])
).longValue(),
Matchers.equalTo(1L)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum double of positive longs",
new MinOf(
new ListOf<>(1L, 2L, 3L, 4L).toArray(new Long[4])
).doubleValue(),
Matchers.equalTo(1.0d)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum float of positive longs",
new MinOf(
new ListOf<>(1L, 2L, 3L, 4L).toArray(new Long[4])
).floatValue(),
Matchers.equalTo(1.0f)
);
).affirm();
}

@Test
void withDoubleCollection() {
MatcherAssert.assertThat(
new Assertion<>(
"must select minimum integer of positive doubles",
new MinOf(
new ListOf<>(1.0d, 2.0d, 3.0d, 4.0d).toArray(new Double[4])
).intValue(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum long of positive doubles",
new MinOf(
new ListOf<>(1.0d, 2.0d, 3.0d, 4.0d).toArray(new Double[4])
).longValue(),
Matchers.equalTo(1L)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum double of positive doubles",
new MinOf(
new ListOf<>(1.0d, 2.0d, 3.0d, 4.0d).toArray(new Double[4])
).doubleValue(),
Matchers.equalTo(1.0d)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum float of positive doubles",
new MinOf(
new ListOf<>(1.0d, 2.0d, 3.0d, 4.0d).toArray(new Double[4])
).floatValue(),
Matchers.equalTo(1.0f)
);
).affirm();
}

@Test
void withFloatCollection() {
MatcherAssert.assertThat(
new Assertion<>(
"must select minimum integer of positive floats",
new MinOf(
new ListOf<>(1.0f, 2.0f, 3.0f, 4.0f).toArray(new Float[4])
).intValue(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum long of positive floats",
new MinOf(
new ListOf<>(1.0f, 2.0f, 3.0f, 4.0f).toArray(new Float[4])
).longValue(),
Matchers.equalTo(1L)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum float of positive floats",
new MinOf(
new ListOf<>(1.0f, 2.0f, 3.0f, 4.0f).toArray(new Float[4])
).doubleValue(),
Matchers.equalTo(1.0d)
);
MatcherAssert.assertThat(
).affirm();
new Assertion<>(
"must select minimum float of positive floats",
new MinOf(
new ListOf<>(1.0f, 2.0f, 3.0f, 4.0f).toArray(new Float[4])
).floatValue(),
Matchers.equalTo(1.0f)
);
).affirm();
}

}
69 changes: 43 additions & 26 deletions src/test/java/org/cactoos/number/SumOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.util.Collection;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.cactoos.text.Joined;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link SumOf}.
Expand All @@ -46,110 +47,126 @@ final class SumOfTest {

@Test
void withListOfNumbersInt() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of integers should be calculated as integer",
new SumOf(1, 2, 3).intValue(),
new IsEqual<>(6)
);
).affirm();
}

@Test
void withListOfNumbersDouble() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of doubles should be calculated as double",
new SumOf(1.0d, 2.0d, 3.0d).doubleValue(),
new IsEqual<>(6.0d)
);
).affirm();
}

@Test
void withListOfNumbersFloat() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of floats should be calculated as float",
new SumOf(1.0f, 2.0f, 3.0f).floatValue(),
new IsEqual<>(6.0f)
);
).affirm();
}

@Test
void withListOfNumbersLong() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of longs should be calculated as long",
new SumOf(1L, 2L, 3L).longValue(),
new IsEqual<>(6L)
);
).affirm();
}

@Test
void withCollectionLong() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of longs should be calculated as long",
new SumOf(
new IterableOf<>(1, 2, 3, 4)
).longValue(),
new IsEqual<>(10L)
);
).affirm();
}

@Test
void withCollectionInt() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of longs should be calculated as integer",
new SumOf(
new IterableOf<>(1L, 2L, 3L, 4L)
).intValue(),
new IsEqual<>(10)
);
).affirm();
}

@Test
void withCollectionFloat() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of floats should be calculated as float",
new SumOf(
new IterableOf<>(1.0f, 2.0f, 3.0f, 4.0f)
).floatValue(),
new IsEqual<>(10.0f)
);
).affirm();
}

@Test
void withCollectionDouble() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of double should be calculated as double",
new SumOf(
new IterableOf<>(1.0d, 2.0d, 3.0d, 4.0d)
).doubleValue(),
new IsEqual<>(10.0d)
);
).affirm();
}

@Test
void withIterableOfInts() {
final Collection<Integer> ints = new ListOf<>(1, 2, 3, 4);
MatcherAssert.assertThat(
new Assertion<>(
"sum of integers should be calculated as integer",
new SumOf(ints).intValue(),
new IsEqual<>(10)
);
).affirm();
}

@Test
void overflowIntFromLongValues() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of longs should be calculated as integer without overflow error",
new SumOf(2_147_483_647L + 1L << 1, 10L).intValue(),
new IsEqual<>(10)
);
).affirm();
}

@Test
void overflowIntFromLongValuesIncludingNegative() {
MatcherAssert.assertThat(
void overflowIntFromLongValuesIncludingNegative() throws Exception {
new Assertion<>(
new Joined(
"",
"sum of positive and negative longs should be calculated",
"as integer without overflow error"
).asString(),
new SumOf(
2_147_483_647L + 1L << 1,
10L,
-(2_147_483_647L + 1L) << 1
).intValue(),
new IsEqual<>(10)
);
).affirm();
}

@Test
void overflowFloatFromLongValues() {
MatcherAssert.assertThat(
new Assertion<>(
"sum of longs should be calculated as float",
new SumOf(2_147_483_647L + 1L << 1, 10L).floatValue(),
new IsEqual<>(4_294_967_300.0f)
);
).affirm();
}
}
Loading

0 comments on commit 92964cd

Please sign in to comment.