Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 5, 2020
2 parents f48e7d9 + a5b3326 commit b0bae7b
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 87 deletions.
34 changes: 17 additions & 17 deletions src/test/java/org/cactoos/scalar/BoolOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.cactoos.scalar;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
* Test case for {@link BoolOf}.
Expand All @@ -37,28 +37,28 @@ public final class BoolOfTest {

@Test
public void trueTest() throws Exception {
MatcherAssert.assertThat(
"Can't parse 'true' string",
new BoolOf("true").value(),
Matchers.equalTo(true)
);
new Assertion<>(
"Must be parsed string 'true'",
new BoolOf("true"),
new ScalarHasValue<>(true)
).affirm();
}

@Test
public void falseTest() throws Exception {
MatcherAssert.assertThat(
"Can't parse 'false' string",
new BoolOf("false").value(),
Matchers.equalTo(false)
);
new Assertion<>(
"Must be parsed string 'false'",
new BoolOf("false"),
new ScalarHasValue<>(false)
).affirm();
}

@Test
public void isFalseIfTextDoesNotRepresentABoolean() throws Exception {
MatcherAssert.assertThat(
"Can't parse a non-boolean string",
new BoolOf("abc").value(),
Matchers.equalTo(false)
);
new Assertion<>(
"Must be parsed a non-boolean string",
new BoolOf("abc"),
new ScalarHasValue<>(false)
).affirm();
}
}
24 changes: 12 additions & 12 deletions src/test/java/org/cactoos/scalar/ConstantTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.cactoos.scalar;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
* Test case for {@link Constant}.
Expand All @@ -37,20 +37,20 @@ public final class ConstantTest {
@Test
public void returnsGivenValue() throws Exception {
final String value = "Hello World";
MatcherAssert.assertThat(
"Can't return given value",
new Constant<>(value).value(),
Matchers.equalTo(value)
);
new Assertion<>(
"Must return given value",
new Constant<>(value),
new ScalarHasValue<>(value)
).affirm();
}

@Test
public void alwaysReturnsSameValue() throws Exception {
final Constant<String> constant = new Constant<>("Good Bye!");
MatcherAssert.assertThat(
"Can't return same value",
constant.value(),
Matchers.sameInstance(constant.value())
);
new Assertion<>(
"Must return same value",
constant,
new ScalarHasValue<>(constant.value())
).affirm();
}
}
22 changes: 13 additions & 9 deletions src/test/java/org/cactoos/scalar/DivisionOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.cactoos.scalar;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link DivisionOf}.
Expand All @@ -40,42 +40,46 @@ public final class DivisionOfTest {
*/
@Test
public void dividesIntNumbers() {
MatcherAssert.assertThat(
new Assertion<>(
"Must divide int numbers",
new DivisionOf(4, 2).intValue(),
new IsEqual<>(2)
);
).affirm();
}

/**
* Ensures that division of long numbers return proper value.
*/
@Test
public void dividesLongNumbers() {
MatcherAssert.assertThat(
new Assertion<>(
"Must divide long numbers",
new DivisionOf(4L, 2L).longValue(),
new IsEqual<>(2L)
);
).affirm();
}

/**
* Ensures that division of float numbers return proper value.
*/
@Test
public void dividesFloatNumbers() {
MatcherAssert.assertThat(
new Assertion<>(
"Must divide float numbers",
new DivisionOf(2f, 4f).floatValue(),
new IsEqual<>(0.5f)
);
).affirm();
}

/**
* Ensures that division of double numbers return proper value.
*/
@Test
public void dividesDoubleNumbers() {
MatcherAssert.assertThat(
new Assertion<>(
"Must divide double numbers",
new DivisionOf(2d, 4d).doubleValue(),
new IsEqual<>(0.5d)
);
).affirm();
}
}
44 changes: 22 additions & 22 deletions src/test/java/org/cactoos/scalar/EqualsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.cactoos.scalar;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
* Test case for {@link Equals}.
Expand All @@ -37,50 +37,50 @@ public final class EqualsTest {

@Test
public void compareEquals() throws Exception {
MatcherAssert.assertThat(
"Can't compare if two integers are equals",
new Assertion<>(
"Must compare if two integers are equals",
new Equals<>(
() -> Integer.valueOf(1),
() -> Integer.valueOf(1)
).value(),
Matchers.equalTo(true)
);
),
new ScalarHasValue<>(true)
).affirm();
}

@Test
public void compareNotEquals() throws Exception {
MatcherAssert.assertThat(
"Can't compare if two integers are not equals",
new Assertion<>(
"Must compare if two integers are not equals",
new Equals<>(
() -> Integer.valueOf(1),
() -> Integer.valueOf(2)
).value(),
Matchers.equalTo(false)
);
),
new ScalarHasValue<>(false)
).affirm();
}

@Test
public void compareEqualsText() throws Exception {
final String str = "hello";
MatcherAssert.assertThat(
"Can't compare if two strings are equals",
new Assertion<>(
"Must compare if two strings are equals",
new Equals<>(
() -> str,
() -> str
).value(),
Matchers.equalTo(true)
);
),
new ScalarHasValue<>(true)
).affirm();
}

@Test
public void compareNotEqualsText() throws Exception {
MatcherAssert.assertThat(
"Can't compare if two strings are not equals",
new Assertion<>(
"Must compare if two strings are not equals",
new Equals<>(
() -> "world",
() -> "worle"
).value(),
Matchers.equalTo(false)
);
),
new ScalarHasValue<>(false)
).affirm();
}
}
19 changes: 9 additions & 10 deletions src/test/java/org/cactoos/scalar/FirstOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.IterableOfInts;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;
Expand All @@ -42,15 +41,15 @@ public final class FirstOfTest {
@Test
public void returnsMatchingValue() {
final int value = 1;
MatcherAssert.assertThat(
"Didn't return the only matching element",
new Assertion<>(
"Must return the only matching element",
new FirstOf<>(
i -> i >= value,
new IterableOfInts(0, value),
() -> -1
),
new ScalarHasValue<>(value)
);
).affirm();
}

@Test
Expand All @@ -74,29 +73,29 @@ public void returnsMatchingValueWithExceptionalFallback() {
@Test
public void returnsFirstValueForMultipleMatchingOnes() {
final String value = "1";
MatcherAssert.assertThat(
"Didn't return first matching element",
new Assertion<>(
"Must return first matching element",
new FirstOf<>(
i -> !i.isEmpty(),
new IterableOf<>("1", "2"),
() -> ""
),
new ScalarHasValue<>(value)
);
).affirm();
}

@Test
public void returnsFallbackIfNothingMatches() {
final String value = "abc";
MatcherAssert.assertThat(
"Didn't return fallback",
new Assertion<>(
"Must return fallback",
new FirstOf<>(
i -> i.length() > 2,
new IterableOf<>("ab", "cd"),
() -> value
),
new ScalarHasValue<>(value)
);
).affirm();
}

@Test
Expand Down
23 changes: 12 additions & 11 deletions src/test/java/org/cactoos/scalar/FoldedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

import org.cactoos.iterable.HeadOf;
import org.cactoos.iterable.RangeOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.ScalarHasValue;

/**
* Test case for {@link Folded}.
Expand All @@ -39,29 +40,29 @@ public final class FoldedTest {

@Test
public void skipIterable() throws Exception {
MatcherAssert.assertThat(
"Can't fold elements in iterable",
new Assertion<>(
"Must fold elements in iterable",
new Folded<>(
0L, (first, second) -> first + second,
new HeadOf<>(
10,
new RangeOf<>(0L, Long.MAX_VALUE, value -> ++value)
)
).value(),
Matchers.equalTo(45L)
);
),
new ScalarHasValue<>(45L)
).affirm();
}

@Test
public void constructedFromVarargs() throws Exception {
MatcherAssert.assertThat(
"Can't fold elements in vararg array",
new Assertion<>(
"Must fold elements in vararg array",
new Folded<>(
0L,
(first, second) -> first + second,
1, 2, 3, 4, 5
).value(),
Matchers.equalTo(15L)
);
new IsEqual<>(15L)
).affirm();
}
}
Loading

3 comments on commit b0bae7b

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on b0bae7b May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1362-b5541bca disappeared from src/test/java/org/cactoos/scalar/package-info.java, that's why I closed #1367. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on b0bae7b May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1367-b5541bca discovered in src/test/java/org/cactoos/scalar/package-info.java and submitted as #1375. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on b0bae7b May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1367-e974cc79 discovered in src/test/java/org/cactoos/scalar/package-info.java and submitted as #1376. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.