Skip to content

Commit

Permalink
#2863 create additional object for test to reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Mar 5, 2024
1 parent 333e32f commit 153aeb9
Showing 1 changed file with 59 additions and 32 deletions.
91 changes: 59 additions & 32 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import EOorg.EOeolang.EOtuple$EOempty;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.eolang.AtComposite;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhCopy;
import org.eolang.PhDefault;
import org.eolang.PhMethod;
import org.eolang.PhWith;
import org.eolang.Phi;
Expand Down Expand Up @@ -96,27 +98,16 @@ public void doesNotPrintTwiceOnIntComparisonMethods(final String method) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final String str = "Hello world";
new Dataized(
new PhWith(
new PrintWithCmp(
new PhMethod(
new Data.ToPhi(1L),
method
),
0,
new Data.ToPhi(2L),
new PhWith(
new EOseq(Phi.),
0,
new PhWith(
new PhWith(
new EOtuple$EOempty(Phi.).attr("with").get().copy(),
0,
new PhWith(
new EOstdout(Phi., new PrintStream(stream)),
"text",
new Data.ToPhi(str)
)
).attr("with").get().copy(),
0, new Data.ToPhi(2L)
)
new EOstdout(Phi., new PrintStream(stream)),
"text",
new Data.ToPhi(str)
)
)
).take();
Expand All @@ -132,27 +123,16 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final String str = "Hello world";
new Dataized(
new PhWith(
new PrintWithCmp(
new PhMethod(
new Data.ToPhi(1.0),
method
),
0,
new Data.ToPhi(3.0),
new PhWith(
new EOseq(Phi.),
0,
new PhWith(
new PhWith(
new EOtuple$EOempty(Phi.).attr("with").get().copy(),
0,
new PhWith(
new EOstdout(Phi., new PrintStream(stream)),
"text",
new Data.ToPhi(str)
)
).attr("with").get().copy(),
0, new Data.ToPhi(3.0)
)
new EOstdout(Phi., new PrintStream(stream)),
"text",
new Data.ToPhi(str)
)
)
).take();
Expand All @@ -161,4 +141,51 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method) {
Matchers.equalTo(str)
);
}

/**
* Handler implementation for tests.
*
* @since 1.0
*/
private static class PrintWithCmp extends PhDefault {
/**
* Ctor.
*
* @param method Comparison PhMethod ("lt", "gt", "lte", "gte")
* @param value Phi value to be compared
* @param stdout Phi object with printing a string via {@link EOstdout} object
*/
PrintWithCmp(final Phi method, final Phi value, final Phi stdout) {
super(Phi.);
this.add(
"蠁",
new AtComposite(
this,
self -> new Data.ToPhi(
new Dataized(
new PhWith(
method,
0,
new PhWith(
new EOseq(Phi.),
0,
new PhWith(
new PhWith(
new EOtuple$EOempty(Phi.)
.attr("with")
.get()
.copy(),
0,
stdout
).attr("with").get().copy(),
0, value
)
)
)
).take()
)
)
);
}
}
}

0 comments on commit 153aeb9

Please sign in to comment.