From 72632f2b9a4162823fe07b0478c4ab9f7e885f27 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:49:50 +0300 Subject: [PATCH] #2863 add extra object to reduce code duplication --- .github/workflows/simian.yml | 2 +- .../src/test/java/org/eolang/PhConstTest.java | 67 +++++++++++-------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/simian.yml b/.github/workflows/simian.yml index 2f1afb342c..8abe6d3eb9 100644 --- a/.github/workflows/simian.yml +++ b/.github/workflows/simian.yml @@ -24,4 +24,4 @@ jobs: - run: | wget --quiet http://public.yegor256.com/simian.jar -O /tmp/simian.jar - run: | - java -jar /tmp/simian.jar -threshold=25 -excludes=**/gen -excludes=**/it **/*.java + java -jar /tmp/simian.jar -threshold=15 -excludes=**/gen -excludes=**/it **/*.java diff --git a/eo-runtime/src/test/java/org/eolang/PhConstTest.java b/eo-runtime/src/test/java/org/eolang/PhConstTest.java index 13bf298514..bc8544569a 100644 --- a/eo-runtime/src/test/java/org/eolang/PhConstTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhConstTest.java @@ -171,20 +171,7 @@ void keepsConstMultiLayers() { @Test void dataizesOnlyOnceViaEnvelopes() { final Dummy dummy = new Dummy("x"); - final Phi phi = new PhConst( - new PhWith( - new Envelope(Phi.Φ), - 0, - new PhWith( - new Envelope(Phi.Φ), - 0, - new PhWith( - new Envelope(Phi.Φ), - 0, dummy - ) - ) - ) - ); + final Phi phi = new PhConst(new EnvelopedDummy(Phi.Φ, dummy)); phi.attr("eq").get(); new Dataized(phi).take(Long.class); MatcherAssert.assertThat( @@ -196,20 +183,7 @@ void dataizesOnlyOnceViaEnvelopes() { @Test void dataizesOnlyOnceViaMethods() { final Dummy dummy = new Dummy("x"); - final Phi phi = new PhConst( - new PhWith( - new Envelope(Phi.Φ), - 0, - new PhWith( - new Envelope(Phi.Φ), - 0, - new PhWith( - new Envelope(Phi.Φ), - 0, dummy - ) - ) - ) - ); + final Phi phi = new PhConst(new EnvelopedDummy(Phi.Φ, dummy)); new Dataized(phi).take(); new Dataized(phi).take(); MatcherAssert.assertThat( @@ -309,6 +283,43 @@ private static class Envelope extends PhDefault { } } + /** + * Enveloped dummy Phi. + * @since 1.0 + */ + private static class EnvelopedDummy extends PhDefault { + /** + * Ctor. + * @param sigma Sigma + * @param dummy Dummy to be enveloped + */ + EnvelopedDummy(final Phi sigma, final Phi dummy) { + super(sigma); + this.add( + "φ", + new AtComposite( + this, + self -> new Data.ToPhi( + new Dataized( + new PhWith( + new Envelope(Phi.Φ), + 0, + new PhWith( + new Envelope(Phi.Φ), + 0, + new PhWith( + new Envelope(Phi.Φ), + 0, dummy + ) + ) + ) + ).take(Long.class) + ) + ) + ); + } + } + /** * Boom Phi. * @since 1.0