Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 68dcb40

Browse files
committed
#33 new errors
1 parent ca9d2cf commit 68dcb40

File tree

8 files changed

+72
-67
lines changed

8 files changed

+72
-67
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ SOFTWARE
9494
<dependency>
9595
<groupId>org.eolang</groupId>
9696
<artifactId>eo-runtime</artifactId>
97-
<version>0.25.4</version>
97+
<version>0.25.5</version>
9898
</dependency>
9999
<dependency>
100100
<groupId>org.junit.jupiter</groupId>
@@ -108,7 +108,7 @@ SOFTWARE
108108
<plugin>
109109
<groupId>org.eolang</groupId>
110110
<artifactId>eo-maven-plugin</artifactId>
111-
<version>0.25.4</version>
111+
<version>0.25.5</version>
112112
<executions>
113113
<execution>
114114
<id>compile</id>
@@ -155,6 +155,7 @@ SOFTWARE
155155
<plugin>
156156
<groupId>com.qulice</groupId>
157157
<artifactId>qulice-maven-plugin</artifactId>
158+
<version>0.21.0</version>
158159
<configuration>
159160
<excludes combine.children="append">
160161
<exclude>pmd:.*</exclude>

src/main/eo/org/eolang/math/number.eo

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
xor.
6969
^.n.as-bytes
7070
x.as-bytes
71-
[]
72-
"xor cannot be applied to float" > msg
71+
error "xor cannot be applied to float"
7372

7473
[x] > or
7574
if. > @
@@ -78,8 +77,7 @@
7877
or.
7978
^.n.as-bytes
8079
x.as-bytes
81-
[]
82-
"or cannot be applied to float" > msg
80+
error "or cannot be applied to float"
8381

8482
[x] > and
8583
if. > @
@@ -88,8 +86,7 @@
8886
and.
8987
^.n.as-bytes
9088
x.as-bytes
91-
[]
92-
"and cannot be applied to float" > msg
89+
error "and cannot be applied to float"
9390

9491
# Calculate bitwise left shift
9592
[x] > left
@@ -99,8 +96,7 @@
9996
left.
10097
^.n.as-bytes
10198
x
102-
[]
103-
"left cannot be applied to float" > msg
99+
error "left cannot be applied to float"
104100

105101
# Calculate bitwise right shift
106102
[x] > right
@@ -110,8 +106,7 @@
110106
right.
111107
^.n.as-bytes
112108
x
113-
[]
114-
"right cannot be applied to float" > msg
109+
error "right cannot be applied to float"
115110

116111
# Tests that $.n ≠ x
117112
[x] > neq
@@ -124,8 +119,7 @@
124119

125120
if. > @
126121
divisor.eq 0
127-
[]
128-
"mod by zero" > msg
122+
error "mod by zero"
129123
if.
130124
dividend.gt 0
131125
abs-mod

src/main/java/EOorg/EOeolang/EOmath/EOnumber$EOas_float.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import EOorg.EOeolang.EOerror;
2828
import org.eolang.AtComposite;
2929
import org.eolang.Data;
30+
import org.eolang.ExFailure;
3031
import org.eolang.Param;
3132
import org.eolang.PhDefault;
3233
import org.eolang.PhWith;
@@ -63,13 +64,10 @@ public final class EOnumber$EOas_float extends PhDefault {
6364
} else if (obj instanceof Long) {
6465
phi = new Data.ToPhi(((Long) obj).doubleValue());
6566
} else {
66-
phi = new PhWith(
67-
new EOerror(Phi.Φ), "msg",
68-
new Data.ToPhi(
69-
String.format(
70-
"Wrong number's %s argument in number.as-float operation",
71-
obj
72-
)
67+
throw new ExFailure(
68+
String.format(
69+
"Wrong number's %s argument in number.as-float operation",
70+
obj
7371
)
7472
);
7573
}

src/main/java/EOorg/EOeolang/EOmath/EOnumber$EOas_int.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import EOorg.EOeolang.EOerror;
2828
import org.eolang.AtComposite;
2929
import org.eolang.Data;
30+
import org.eolang.ExFailure;
3031
import org.eolang.Param;
3132
import org.eolang.PhDefault;
3233
import org.eolang.PhWith;
@@ -63,13 +64,10 @@ public final class EOnumber$EOas_int extends PhDefault {
6364
} else if (obj instanceof Long) {
6465
phi = new Data.ToPhi(obj);
6566
} else {
66-
phi = new PhWith(
67-
new EOerror(Phi.Φ), "msg",
68-
new Data.ToPhi(
69-
String.format(
70-
"Wrong number's %s argument in number.as-int operation",
71-
obj
72-
)
67+
throw new ExFailure(
68+
String.format(
69+
"Wrong number's %s argument in number.as-int operation",
70+
obj
7371
)
7472
);
7573
}

src/main/java/EOorg/EOeolang/EOmath/EOnumber$EOas_string.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import EOorg.EOeolang.EOerror;
2828
import org.eolang.AtComposite;
2929
import org.eolang.Data;
30+
import org.eolang.ExFailure;
3031
import org.eolang.Param;
3132
import org.eolang.PhDefault;
3233
import org.eolang.PhWith;
@@ -63,13 +64,10 @@ public final class EOnumber$EOas_string extends PhDefault {
6364
} else if (obj instanceof Long) {
6465
phi = new Data.ToPhi(Long.toString((Long) obj));
6566
} else {
66-
phi = new PhWith(
67-
new EOerror(Phi.Φ), "msg",
68-
new Data.ToPhi(
69-
String.format(
70-
"Wrong number's %s argument in number.as-string operation",
71-
obj
72-
)
67+
throw new ExFailure(
68+
String.format(
69+
"Wrong number's %s argument in number.as-string operation",
70+
obj
7371
)
7472
);
7573
}

src/main/java/EOorg/EOeolang/EOmath/EOnumber$EOpow.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eolang.AtComposite;
2929
import org.eolang.AtFree;
3030
import org.eolang.Data;
31+
import org.eolang.ExFailure;
3132
import org.eolang.Param;
3233
import org.eolang.PhDefault;
3334
import org.eolang.PhWith;
@@ -64,9 +65,8 @@ public final class EOnumber$EOpow extends PhDefault {
6465
final double self = (Double) base;
6566
final double pow = new Param(rho, "x").strong(Double.class);
6667
if (self == 0.0d && pow < 0.0d) {
67-
phi = new PhWith(
68-
new EOerror(Phi.Φ), "msg",
69-
new Data.ToPhi("0.0 cannot be raised to a negative power")
68+
throw new ExFailure(
69+
"0.0 cannot be raised to a negative power"
7070
);
7171
} else {
7272
phi = new Data.ToPhi(Math.pow(self, pow));
@@ -75,21 +75,17 @@ public final class EOnumber$EOpow extends PhDefault {
7575
final long self = (Long) base;
7676
final long pow = new Param(rho, "x").strong(Long.class);
7777
if (self == 0L && pow < 0L) {
78-
phi = new PhWith(
79-
new EOerror(Phi.Φ), "msg",
80-
new Data.ToPhi("0 cannot be raised to a negative power")
78+
throw new ExFailure(
79+
"0 cannot be raised to a negative power"
8180
);
8281
} else {
8382
phi = new Data.ToPhi(((Double) Math.pow(self, pow)).longValue());
8483
}
8584
} else {
86-
phi = new PhWith(
87-
new EOerror(Phi.Φ), "msg",
88-
new Data.ToPhi(
89-
String.format(
90-
"Wrong number's %s argument in number.div operation",
91-
base
92-
)
85+
throw new ExFailure(
86+
String.format(
87+
"Wrong number's %s argument in number.div operation",
88+
base
9389
)
9490
);
9591
}

src/main/java/EOorg/EOeolang/EOmath/EOrandom$EOpseudo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public final class EOrandom$EOpseudo extends PhDefault {
5959
new EOrandom(self),
6060
"seed",
6161
new Data.ToPhi(
62-
((System.nanoTime() << thirtyfive) & ((1L << fiftythree) - 1))
63-
+ ((System.nanoTime() << seventeen) & ((1L << thirtyfive) - 1))
64-
+ (System.nanoTime() & ((1L << seventeen) - 1))
62+
(System.nanoTime() << thirtyfive & (1L << fiftythree) - 1L)
63+
+ (System.nanoTime() << seventeen & (1L << thirtyfive) - 1L)
64+
+ (System.nanoTime() & (1L << seventeen) - 1L)
6565
)
6666
);
6767
}

src/test/eo/org/eolang/math/number-tests.eo

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@
7979

8080
[] > xor-float-3-6
8181
assert-that > @
82-
number 3.0
83-
.xor 6.0
84-
.msg
82+
try
83+
[]
84+
(number 3.0).xor 6.0 > @
85+
[e]
86+
e > @
87+
nop
8588
$.equal-to
8689
"xor cannot be applied to float"
8790

@@ -93,9 +96,12 @@
9396

9497
[] > or-float-1-2
9598
assert-that > @
96-
number 1.0
97-
.or 2.0
98-
.msg
99+
try
100+
[]
101+
(number 1.0).or 2.0 > @
102+
[e]
103+
e > @
104+
nop
99105
$.equal-to
100106
"or cannot be applied to float"
101107

@@ -107,9 +113,12 @@
107113

108114
[] > and-float-3-6
109115
assert-that > @
110-
number 3.0
111-
.and 6.0
112-
.msg
116+
try
117+
[]
118+
(number 3.0).and 6.0 > @
119+
[e]
120+
e > @
121+
nop
113122
$.equal-to
114123
"and cannot be applied to float"
115124

@@ -121,9 +130,12 @@
121130

122131
[] > left-float-1-2
123132
assert-that > @
124-
number 1.0
125-
.left 2
126-
.msg
133+
try
134+
[]
135+
(number 1.0).left 2 > @
136+
[e]
137+
e > @
138+
nop
127139
$.equal-to
128140
"left cannot be applied to float"
129141

@@ -135,9 +147,12 @@
135147

136148
[] > right-float-8-2
137149
assert-that > @
138-
number 8.0
139-
.right 2
140-
.msg
150+
try
151+
[]
152+
(number 8.0).right 2 > @
153+
[e]
154+
e > @
155+
nop
141156
$.equal-to
142157
"right cannot be applied to float"
143158

@@ -353,7 +368,12 @@
353368

354369
[] > negative-power-of-zero
355370
assert-that > @
356-
((number 0).pow -567).msg
371+
try
372+
[]
373+
((number 0).pow -567).msg > @
374+
[e]
375+
e > @
376+
nop
357377
$.equal-to "0 cannot be raised to a negative power"
358378

359379
# Checks that number.as-float works properly

0 commit comments

Comments
 (0)