Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 25, 2022
2 parents 369a665 + c4c74a2 commit 029ae47
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/float.eo
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
^
^.neg

# Sine of $
[] > sin /float

# Cosine of $
[] > cos /float

# Converts this to bytes
[] > as-bytes /bytes

Expand Down
22 changes: 22 additions & 0 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOfloat$EOcos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package EOorg.EOeolang;

import org.eolang.AtComposite;
import org.eolang.Data;
import org.eolang.Param;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;

/**
* Cos.
*/
@XmirObject(oname = "float.cos")
public class EOfloat$EOcos extends PhDefault {

public EOfloat$EOcos(final Phi sigma) {
super(sigma);
this.add("蠁", new AtComposite(this, rho -> new Data.ToPhi(
Math.cos(new Param(rho).strong(Double.class))
)));
}
}
22 changes: 22 additions & 0 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOfloat$EOsin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package EOorg.EOeolang;

import org.eolang.AtComposite;
import org.eolang.Data;
import org.eolang.Param;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;

/**
* Sin.
*/
@XmirObject(oname = "float.sin")
public class EOfloat$EOsin extends PhDefault {

public EOfloat$EOsin(final Phi sigma) {
super(sigma);
this.add("蠁", new AtComposite(this, rho -> new Data.ToPhi(
Math.sin(new Param(rho).strong(Double.class))
)));
}
}
30 changes: 30 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/float-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,36 @@
[] > as-int-works
3.57.as-int.eq 3 > @

[] > sin-zero
eq. > @
0.0
(0.0.sin)

[] > sin-pi-div-2
eq. > @
1.0
(1.5707963267948966.sin)

[] > sin-pi-as-int
eq. > @
0
(3.141592653589793.sin).as-int

[] > cos-zero
eq. > @
1.0
0.0.cos

[] > cos-pi-div-2-as-int
eq. > @
0
(1.5707963267948966.cos).as-int

[] > cos-pi
eq. > @
-1.0
3.141592653589793.cos

[] > to-bytes-and-backwards
eq. > @
3.1415926
Expand Down
65 changes: 65 additions & 0 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOfloatEOcosTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package EOorg.EOeolang;

import org.eolang.Data;
import org.eolang.Dataized;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link EOfloat}
*/
public final class EOfloatEOcosTest {

@Test
public void cos0() {
final double cos0 = Math.cos(0);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOcos(
new Data.ToPhi((double) 0)
)
).take(Double.class),
Matchers.equalTo(cos0)
);
}

@Test
public void cosPi() {
final double cosPi = Math.cos(Math.PI);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOcos(
new Data.ToPhi(Math.PI)
)
).take(Double.class),
Matchers.equalTo(cosPi)
);
}

@Test
public void cosPiDiv2() {
final double cosPiDiv2 = Math.cos(Math.PI / 2);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOcos(
new Data.ToPhi(Math.PI / 2)
)
).take(Double.class),
Matchers.equalTo(cosPiDiv2)
);
}

@Test
public void cosMinusPiDiv2() {
final double cosMinusPiDiv2 = Math.cos(-Math.PI / 2);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOcos(
new Data.ToPhi(-Math.PI / 2)
)
).take(Double.class),
Matchers.equalTo(cosMinusPiDiv2)
);
}
}
65 changes: 65 additions & 0 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOfloatEOsinTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package EOorg.EOeolang;

import org.eolang.Data;
import org.eolang.Dataized;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link EOfloat}
*/
public final class EOfloatEOsinTest {

@Test
public void sin0() {
final double sin0 = Math.sin(0);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOsin(
new Data.ToPhi((double) 0)
)
).take(Double.class),
Matchers.equalTo(sin0)
);
}

@Test
public void sinPi() {
final double sinPi = Math.sin(Math.PI);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOsin(
new Data.ToPhi(Math.PI)
)
).take(Double.class),
Matchers.equalTo(sinPi)
);
}

@Test
public void sinPiDiv2() {
final double sinPiDiv2 = Math.sin(Math.PI / 2);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOsin(
new Data.ToPhi(Math.PI / 2)
)
).take(Double.class),
Matchers.equalTo(sinPiDiv2)
);
}

@Test
public void sinMinusPiDiv2() {
final double sinMinusPiDiv2 = Math.sin(-Math.PI / 2);
MatcherAssert.assertThat(
new Dataized(
new EOfloat$EOsin(
new Data.ToPhi(-Math.PI / 2)
)
).take(Double.class),
Matchers.equalTo(sinMinusPiDiv2)
);
}
}

0 comments on commit 029ae47

Please sign in to comment.