From 731a3c610684f8428ebfea04b47d6f5dace24d9d Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Tue, 7 Jan 2025 23:06:43 +0300 Subject: [PATCH 1/9] #3461 Add Expect for EOnumber$EOplus --- .../java/EOorg/EOeolang/EOnumber$EOplus.java | 13 ++-- .../EOorg/EOeolang/EOnumber$EOplusTest.java | 72 +++++++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java index b491e65b25..c679a92af6 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java @@ -30,6 +30,7 @@ import org.eolang.AtVoid; import org.eolang.Atom; +import org.eolang.Expect; import org.eolang.Attr; import org.eolang.Data; import org.eolang.Dataized; @@ -56,11 +57,11 @@ public final class EOnumber$EOplus extends PhDefault implements Atom { @Override public Phi lambda() { - return new Data.ToPhi( - Double.sum( - new Dataized(this.take(Attr.RHO)).asNumber(), - new Dataized(this.take("x")).asNumber() - ) - ); + Double left = new Dataized(this.take(Attr.RHO)).asNumber(); + Double right = Expect.at(this, "x") + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("number.plus expects its second argument to be a number") + .it(); + return new Data.ToPhi(Double.sum(left, right)); } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java new file mode 100644 index 0000000000..2aff34b20b --- /dev/null +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java @@ -0,0 +1,72 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * @checkstyle PackageNameCheck (10 lines) + * @checkstyle TrailingCommentCheck (3 lines) + */ +package EOorg.EOeolang; // NOPMD + +import org.eolang.Attr; +import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link EOnumber$EOplus}. + * + * @since 0.51 + * @checkstyle TypeNameCheck (3 lines) + */ +@SuppressWarnings("PMD.AvoidDollarSigns") +final class EOnumber$EOplusTest { + + @Test + void throwsCorrectError() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOplus(), + Attr.RHO, + new Data.ToPhi(42) + ), + "x", + new Data.ToPhi(true) + ) + ).take(), + "addition with TRUE fails with a proper message that explains what happened" + ).getMessage(), + Matchers.containsString("number.plus expects its second argument to be a number") + ); + } +} From 53b226350268220e3e450f1661978d41e564c647 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Thu, 16 Jan 2025 12:29:59 +0300 Subject: [PATCH 2/9] Update EOnumber$EOplus due to new 'Expect' --- .../java/EOorg/EOeolang/EOnumber$EOplus.java | 13 +++++---- .../EOorg/EOeolang/EOnumber$EOplusTest.java | 27 +++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java index c679a92af6..f36dc6f855 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java @@ -28,12 +28,12 @@ */ package EOorg.EOeolang; // NOPMD -import org.eolang.AtVoid; import org.eolang.Atom; -import org.eolang.Expect; import org.eolang.Attr; +import org.eolang.AtVoid; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; import org.eolang.XmirObject; @@ -57,10 +57,13 @@ public final class EOnumber$EOplus extends PhDefault implements Atom { @Override public Phi lambda() { - Double left = new Dataized(this.take(Attr.RHO)).asNumber(); - Double right = Expect.at(this, "x") + final Double left = Expect.at(this, Attr.RHO) + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("must be a number") + .it(); + final Double right = Expect.at(this, "x") .that(phi -> new Dataized(phi).asNumber()) - .otherwise("number.plus expects its second argument to be a number") + .otherwise("must be a number") .it(); return new Data.ToPhi(Double.sum(left, right)); } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java index 2aff34b20b..7c3ada742c 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java @@ -48,7 +48,7 @@ final class EOnumber$EOplusTest { @Test - void throwsCorrectError() { + void throwsCorrectErrorForXAttr() { MatcherAssert.assertThat( "the message in the error is correct", Assertions.assertThrows( @@ -66,7 +66,30 @@ void throwsCorrectError() { ).take(), "addition with TRUE fails with a proper message that explains what happened" ).getMessage(), - Matchers.containsString("number.plus expects its second argument to be a number") + Matchers.equalTo("the 'x' attribute must be a number") + ); + } + + @Test + void throwsCorrectErrorForRhoAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOplus(), + Attr.RHO, + new Data.ToPhi(true) + ), + "x", + new Data.ToPhi(42) + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") ); } } From 5eabfada5761c1fb904b85965ccc8e6de1cb4448 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Thu, 16 Jan 2025 13:10:07 +0300 Subject: [PATCH 3/9] Use Expect in EOnumber$EOas_i64 --- .../EOorg/EOeolang/EOnumber$EOas_i64.java | 6 +- .../java/EOorg/EOeolang/EOnumber$EOplus.java | 2 +- .../EOorg/EOeolang/EOnumber$EOas_i64Test.java | 68 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java index 55e226a0df..1e23216df8 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java @@ -33,6 +33,7 @@ import org.eolang.BytesOf; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; import org.eolang.XmirObject; @@ -52,7 +53,10 @@ public Phi lambda() { 0, new Data.ToPhi( new BytesOf( - new Dataized(this.take(Attr.RHO)).asNumber().longValue() + Expect.at(this, Attr.RHO) + .that(phi -> new Dataized(phi).take(Long.class)) + .otherwise("must be a number") + .it() ).take() ) ); diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java index f36dc6f855..9d0bf401a3 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java @@ -28,9 +28,9 @@ */ package EOorg.EOeolang; // NOPMD +import org.eolang.AtVoid; import org.eolang.Atom; import org.eolang.Attr; -import org.eolang.AtVoid; import org.eolang.Data; import org.eolang.Dataized; import org.eolang.Expect; diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java new file mode 100644 index 0000000000..60a6ec8e9e --- /dev/null +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java @@ -0,0 +1,68 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * @checkstyle PackageNameCheck (10 lines) + * @checkstyle TrailingCommentCheck (3 lines) + */ +package EOorg.EOeolang; // NOPMD + +import org.eolang.Attr; +import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link EOnumber$EOas_i64}. + * + * @since 0.51 + * @checkstyle TypeNameCheck (3 lines) + */ +@SuppressWarnings("PMD.AvoidDollarSigns") +final class EOnumber$EOas_i64Test { + + @Test + void throwsCorrectErrorForRhoAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new EOnumber$EOas_i64(), + Attr.RHO, + new Data.ToPhi("string") + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") + ); + } +} From 25d918b9fa003afecbd0f5516496f889a3386f84 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Fri, 17 Jan 2025 09:34:54 +0300 Subject: [PATCH 4/9] Use Expect in EOnumber$EOdiv --- .../java/EOorg/EOeolang/EOnumber$EOdiv.java | 14 ++- .../EOorg/EOeolang/EOnumber$EOdivTest.java | 96 +++++++++++++++++++ 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java index 15346e0945..b14df9b338 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java @@ -33,6 +33,7 @@ import org.eolang.Attr; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; import org.eolang.XmirObject; @@ -56,9 +57,14 @@ public final class EOnumber$EOdiv extends PhDefault implements Atom { @Override public Phi lambda() { - return new Data.ToPhi( - new Dataized(this.take(Attr.RHO)).asNumber() - / new Dataized(this.take("x")).asNumber() - ); + final Double left = Expect.at(this, Attr.RHO) + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("must be a number") + .it(); + final Double right = Expect.at(this, "x") + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("must be a number") + .it(); + return new Data.ToPhi(left / right); } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java new file mode 100644 index 0000000000..523df1d56e --- /dev/null +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java @@ -0,0 +1,96 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * @checkstyle PackageNameCheck (10 lines) + * @checkstyle TrailingCommentCheck (3 lines) + */ +package EOorg.EOeolang; // NOPMD + +import org.eolang.Attr; +import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link EOnumber$EOdiv}. + * + * @since 0.51 + * @checkstyle TypeNameCheck (3 lines) + */ +@SuppressWarnings("PMD.AvoidDollarSigns") +final class EOnumber$EOdivTest { + + @Test + void throwsCorrectErrorForXAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOdiv(), + Attr.RHO, + new Data.ToPhi(42) + ), + "x", + new Data.ToPhi(true) + ) + ).take(), + "addition with TRUE fails with a proper message that explains what happened" + ).getMessage(), + Matchers.equalTo("the 'x' attribute must be a number") + ); + } + + @Test + void throwsCorrectErrorForRhoAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOdiv(), + Attr.RHO, + new Data.ToPhi(true) + ), + "x", + new Data.ToPhi(42) + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") + ); + } + +} From 16dcd8f6234f8dc216e868d7023297120e91c1c8 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Fri, 17 Jan 2025 09:46:10 +0300 Subject: [PATCH 5/9] Use Expect in EOnumber$EOgt --- .../java/EOorg/EOeolang/EOnumber$EOgt.java | 14 ++- .../EOorg/EOeolang/EOnumber$EOgtTest.java | 96 +++++++++++++++++++ 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java index 6f531d6bdd..61e70c6ce7 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java @@ -33,6 +33,7 @@ import org.eolang.Attr; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; import org.eolang.XmirObject; @@ -56,9 +57,14 @@ public final class EOnumber$EOgt extends PhDefault implements Atom { @Override public Phi lambda() { - return new Data.ToPhi( - new Dataized(this.take(Attr.RHO)).asNumber() - > new Dataized(this.take("x")).asNumber() - ); + final Double left = Expect.at(this, Attr.RHO) + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("must be a number") + .it(); + final Double right = Expect.at(this, "x") + .that(phi -> new Dataized(phi).asNumber()) + .otherwise("must be a number") + .it(); + return new Data.ToPhi(left > right); } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java new file mode 100644 index 0000000000..918d0f8a77 --- /dev/null +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java @@ -0,0 +1,96 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * @checkstyle PackageNameCheck (10 lines) + * @checkstyle TrailingCommentCheck (3 lines) + */ +package EOorg.EOeolang; // NOPMD + +import org.eolang.Attr; +import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link EOnumber$EOgt}. + * + * @since 0.51 + * @checkstyle TypeNameCheck (3 lines) + */ +@SuppressWarnings("PMD.AvoidDollarSigns") +final class EOnumber$EOgtTest { + + @Test + void throwsCorrectErrorForXAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOgt(), + Attr.RHO, + new Data.ToPhi(42) + ), + "x", + new Data.ToPhi(true) + ) + ).take(), + "comparison with TRUE fails with a proper message that explains what happened" + ).getMessage(), + Matchers.equalTo("the 'x' attribute must be a number") + ); + } + + @Test + void throwsCorrectErrorForRhoAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + new EOnumber$EOdiv(), + Attr.RHO, + new Data.ToPhi(true) + ), + "x", + new Data.ToPhi(42) + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") + ); + } + +} From c33477fbdbc611477a0d72003cf27134a816b612 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Fri, 17 Jan 2025 09:51:00 +0300 Subject: [PATCH 6/9] Use Expect in EOnumber$EOfloor --- .../java/EOorg/EOeolang/EOnumber$EOfloor.java | 6 +- .../EOorg/EOeolang/EOnumber$EOfloorTest.java | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java index 36783dcbe1..b2227ce1c4 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java @@ -32,6 +32,7 @@ import org.eolang.Attr; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; import org.eolang.XmirObject; @@ -48,7 +49,10 @@ public final class EOnumber$EOfloor extends PhDefault implements Atom { @Override public Phi lambda() { return new Data.ToPhi( - new Dataized(this.take(Attr.RHO)).asNumber().longValue() + Expect.at(this, Attr.RHO) + .that(phi -> new Dataized(phi).take(Long.class)) + .otherwise("must be a number") + .it() ); } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java new file mode 100644 index 0000000000..48b9829a52 --- /dev/null +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java @@ -0,0 +1,68 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * @checkstyle PackageNameCheck (10 lines) + * @checkstyle TrailingCommentCheck (3 lines) + */ +package EOorg.EOeolang; // NOPMD + +import org.eolang.Attr; +import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link EOnumber$EOfloor}. + * + * @since 0.51 + * @checkstyle TypeNameCheck (3 lines) + */ +@SuppressWarnings("PMD.AvoidDollarSigns") +final class EOnumber$EOfloorTest { + + @Test + void throwsCorrectErrorForRhoAttr() { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new EOnumber$EOfloor(), + Attr.RHO, + new Data.ToPhi("string") + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") + ); + } +} From 5636f3eed2564489b236e52f9512fc8a2e4692f0 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Sun, 19 Jan 2025 12:13:36 +0300 Subject: [PATCH 7/9] fix PMD errors | refactor: use Expect.Number --- .../src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java | 10 ++-------- .../src/main/java/EOorg/EOeolang/EOnumber$EOgt.java | 10 ++-------- .../src/main/java/EOorg/EOeolang/EOnumber$EOplus.java | 10 ++-------- .../src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java | 10 ++-------- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java index b14df9b338..fee17c578b 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java @@ -57,14 +57,8 @@ public final class EOnumber$EOdiv extends PhDefault implements Atom { @Override public Phi lambda() { - final Double left = Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); - final Double right = Expect.at(this, "x") - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); + final Double left = new Expect.Number(Expect.at(this, Attr.RHO)).it(); + final Double right = new Expect.Number(Expect.at(this, "x")).it(); return new Data.ToPhi(left / right); } } diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java index 61e70c6ce7..c2a093776f 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java @@ -57,14 +57,8 @@ public final class EOnumber$EOgt extends PhDefault implements Atom { @Override public Phi lambda() { - final Double left = Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); - final Double right = Expect.at(this, "x") - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); + final Double left = new Expect.Number(Expect.at(this, Attr.RHO)).it(); + final Double right = new Expect.Number(Expect.at(this, "x")).it(); return new Data.ToPhi(left > right); } } diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java index 9d0bf401a3..fb0bc9bebd 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java @@ -57,14 +57,8 @@ public final class EOnumber$EOplus extends PhDefault implements Atom { @Override public Phi lambda() { - final Double left = Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); - final Double right = Expect.at(this, "x") - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); + final Double left = new Expect.Number(Expect.at(this, Attr.RHO)).it(); + final Double right = new Expect.Number(Expect.at(this, "x")).it(); return new Data.ToPhi(Double.sum(left, right)); } } diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java index fca0a43c41..6e05a0e34f 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java @@ -57,14 +57,8 @@ public final class EOnumber$EOtimes extends PhDefault implements Atom { @Override public Phi lambda() { - final Double left = Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); - final Double right = Expect.at(this, "x") - .that(phi -> new Dataized(phi).asNumber()) - .otherwise("must be a number") - .it(); + final Double left = new Expect.Number(Expect.at(this, Attr.RHO)).it(); + final Double right = new Expect.Number(Expect.at(this, "x")).it(); return new Data.ToPhi(left * right); } } From cccff194b230debb8ad983ff0120435201cd9b97 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Sat, 25 Jan 2025 16:29:06 +0300 Subject: [PATCH 8/9] fix lint errors | refactor: use Expect.Number --- eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java | 1 - eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java | 1 - eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java | 1 - eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java | 1 - eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java | 2 +- eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java | 2 +- 6 files changed, 2 insertions(+), 6 deletions(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java index fee17c578b..a4851e4319 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOdiv.java @@ -32,7 +32,6 @@ import org.eolang.Atom; import org.eolang.Attr; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java index c2a093776f..9b606b42f0 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOgt.java @@ -32,7 +32,6 @@ import org.eolang.Atom; import org.eolang.Attr; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java index fb0bc9bebd..783465c508 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOplus.java @@ -32,7 +32,6 @@ import org.eolang.Atom; import org.eolang.Attr; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java index 6e05a0e34f..f6c155076d 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOtimes.java @@ -32,7 +32,6 @@ import org.eolang.Atom; import org.eolang.Attr; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java index 523df1d56e..94868f8b6f 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java @@ -58,7 +58,7 @@ void throwsCorrectErrorForXAttr() { new PhWith( new EOnumber$EOdiv(), Attr.RHO, - new Data.ToPhi(42) + new Data.ToPhi(1) ), "x", new Data.ToPhi(true) diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java index 918d0f8a77..6eb4a6d593 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java @@ -64,7 +64,7 @@ void throwsCorrectErrorForXAttr() { new Data.ToPhi(true) ) ).take(), - "comparison with TRUE fails with a proper message that explains what happened" + "comparison with TRUE fails" ).getMessage(), Matchers.equalTo("the 'x' attribute must be a number") ); From 2a9b19da6e580b0a6770c407c7987d4343b10593 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Sat, 25 Jan 2025 16:50:44 +0300 Subject: [PATCH 9/9] refactor tests for EONumber --- .../EOorg/EOeolang/EOnumber$EOas_i64.java | 6 +- .../java/EOorg/EOeolang/EOnumber$EOfloor.java | 6 +- .../EOorg/EOeolang/EOnumber$EOas_i64Test.java | 68 ------------- .../EOorg/EOeolang/EOnumber$EOdivTest.java | 96 ------------------- .../EOorg/EOeolang/EOnumber$EOfloorTest.java | 68 ------------- .../EOorg/EOeolang/EOnumber$EOgtTest.java | 96 ------------------- .../EOorg/EOeolang/EOnumber$EOplusTest.java | 95 ------------------ .../EOorg/EOeolang/EOnumber$EOtimesTest.java | 95 ------------------ .../java/EOorg/EOeolang/EOnumberTest.java | 64 +++++++++++++ 9 files changed, 66 insertions(+), 528 deletions(-) delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java delete mode 100644 eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOtimesTest.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java index 1e23216df8..f122f8f250 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java @@ -32,7 +32,6 @@ import org.eolang.Attr; import org.eolang.BytesOf; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; @@ -53,10 +52,7 @@ public Phi lambda() { 0, new Data.ToPhi( new BytesOf( - Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).take(Long.class)) - .otherwise("must be a number") - .it() + new Expect.Number(Expect.at(this, Attr.RHO)).it().longValue() ).take() ) ); diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java index b2227ce1c4..744221e31f 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOfloor.java @@ -31,7 +31,6 @@ import org.eolang.Atom; import org.eolang.Attr; import org.eolang.Data; -import org.eolang.Dataized; import org.eolang.Expect; import org.eolang.PhDefault; import org.eolang.Phi; @@ -49,10 +48,7 @@ public final class EOnumber$EOfloor extends PhDefault implements Atom { @Override public Phi lambda() { return new Data.ToPhi( - Expect.at(this, Attr.RHO) - .that(phi -> new Dataized(phi).take(Long.class)) - .otherwise("must be a number") - .it() + new Expect.Number(Expect.at(this, Attr.RHO)).it().longValue() ); } } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java deleted file mode 100644 index 60a6ec8e9e..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOas_i64Test.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOas_i64}. - * - * @since 0.51 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOas_i64Test { - - @Test - void throwsCorrectErrorForRhoAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new EOnumber$EOas_i64(), - Attr.RHO, - new Data.ToPhi("string") - ) - ).take(), - "EOnumber must be a number" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java deleted file mode 100644 index 94868f8b6f..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOdivTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOdiv}. - * - * @since 0.51 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOdivTest { - - @Test - void throwsCorrectErrorForXAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOdiv(), - Attr.RHO, - new Data.ToPhi(1) - ), - "x", - new Data.ToPhi(true) - ) - ).take(), - "addition with TRUE fails with a proper message that explains what happened" - ).getMessage(), - Matchers.equalTo("the 'x' attribute must be a number") - ); - } - - @Test - void throwsCorrectErrorForRhoAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOdiv(), - Attr.RHO, - new Data.ToPhi(true) - ), - "x", - new Data.ToPhi(42) - ) - ).take(), - "EOnumber must be a number" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } - -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java deleted file mode 100644 index 48b9829a52..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOfloorTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOfloor}. - * - * @since 0.51 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOfloorTest { - - @Test - void throwsCorrectErrorForRhoAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new EOnumber$EOfloor(), - Attr.RHO, - new Data.ToPhi("string") - ) - ).take(), - "EOnumber must be a number" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java deleted file mode 100644 index 6eb4a6d593..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOgtTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOgt}. - * - * @since 0.51 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOgtTest { - - @Test - void throwsCorrectErrorForXAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOgt(), - Attr.RHO, - new Data.ToPhi(42) - ), - "x", - new Data.ToPhi(true) - ) - ).take(), - "comparison with TRUE fails" - ).getMessage(), - Matchers.equalTo("the 'x' attribute must be a number") - ); - } - - @Test - void throwsCorrectErrorForRhoAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOdiv(), - Attr.RHO, - new Data.ToPhi(true) - ), - "x", - new Data.ToPhi(42) - ) - ).take(), - "EOnumber must be a number" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } - -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java deleted file mode 100644 index 7c3ada742c..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOplusTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOplus}. - * - * @since 0.51 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOplusTest { - - @Test - void throwsCorrectErrorForXAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOplus(), - Attr.RHO, - new Data.ToPhi(42) - ), - "x", - new Data.ToPhi(true) - ) - ).take(), - "addition with TRUE fails with a proper message that explains what happened" - ).getMessage(), - Matchers.equalTo("the 'x' attribute must be a number") - ); - } - - @Test - void throwsCorrectErrorForRhoAttr() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOplus(), - Attr.RHO, - new Data.ToPhi(true) - ), - "x", - new Data.ToPhi(42) - ) - ).take(), - "EOnumber must be a number" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOtimesTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOtimesTest.java deleted file mode 100644 index 62bc918ec5..0000000000 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumber$EOtimesTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * @checkstyle PackageNameCheck (10 lines) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.Attr; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.ExAbstract; -import org.eolang.PhWith; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link EOnumber$EOtimes}. - * - * @since 0.41 - * @checkstyle TypeNameCheck (3 lines) - */ -@SuppressWarnings("PMD.AvoidDollarSigns") -final class EOnumber$EOtimesTest { - - @Test - void throwsCorrectErrorWhenRhoAttrIsWrong() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOtimes(), - Attr.RHO, - new Data.ToPhi(true) - ), - "x", - new Data.ToPhi(42) - ) - ).take(), - "Attr.RHO must be a number, not anything else" - ).getMessage(), - Matchers.equalTo("the 'ρ' attribute must be a number") - ); - } - - @Test - void throwsCorrectErrorWhenXAttrIsWrong() { - MatcherAssert.assertThat( - "the message in the error is correct", - Assertions.assertThrows( - ExAbstract.class, - () -> new Dataized( - new PhWith( - new PhWith( - new EOnumber$EOtimes(), - Attr.RHO, - new Data.ToPhi(4L) - ), - "x", - new Data.ToPhi(true) - ) - ).take(), - "multiplies 3 by TRUE and fails with a proper message that explains what happened" - ).getMessage(), - Matchers.equalTo("the 'x' attribute must be a number") - ); - } -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java index d0b21014f7..038ba939de 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java @@ -29,10 +29,18 @@ package EOorg.EOeolang; // NOPMD import org.eolang.AtCompositeTest; +import org.eolang.Attr; import org.eolang.Data; +import org.eolang.Dataized; +import org.eolang.ExAbstract; +import org.eolang.PhWith; +import org.eolang.Phi; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * Test case for {@link EOnumber}. @@ -69,4 +77,60 @@ void hasDifferentHash() { Matchers.not(new Data.ToPhi(0L).hashCode()) ); } + + @ParameterizedTest + @ValueSource(classes = { + EOnumber$EOdiv.class, + EOnumber$EOgt.class, + EOnumber$EOplus.class, + EOnumber$EOtimes.class + }) + void throwsCorrectErrorForXAttr(final Class cls) { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + new PhWith( + (Phi) cls.getDeclaredConstructor().newInstance(), + Attr.RHO, + new Data.ToPhi(42) + ), + "x", + new Data.ToPhi(true) + ) + ).take(), + "operation with TRUE fails with a proper message that explains what happened" + ).getMessage(), + Matchers.equalTo("the 'x' attribute must be a number") + ); + } + + @ParameterizedTest + @ValueSource(classes = { + EOnumber$EOdiv.class, + EOnumber$EOgt.class, + EOnumber$EOplus.class, + EOnumber$EOtimes.class, + EOnumber$EOas_i64.class, + EOnumber$EOfloor.class + }) + void throwsCorrectErrorForRhoAttr(final Class cls) { + MatcherAssert.assertThat( + "the message in the error is correct", + Assertions.assertThrows( + ExAbstract.class, + () -> new Dataized( + new PhWith( + (Phi) cls.getDeclaredConstructor().newInstance(), + Attr.RHO, + new Data.ToPhi(true) + ) + ).take(), + "EOnumber must be a number" + ).getMessage(), + Matchers.equalTo("the 'ρ' attribute must be a number") + ); + } }