Skip to content

Commit

Permalink
Answered Indriya: 322
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Jan 6, 2021
1 parent 95d93f0 commit 8a94c57
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 59 deletions.
46 changes: 4 additions & 42 deletions units/src/test/java/si/uom/AngleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,69 +31,31 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;

import javax.measure.Quantity;
import javax.measure.quantity.Angle;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.quantity.Quantities;
import tech.units.indriya.unit.Units;

public class AngleTest {

private static MultiplyConverter piMultiplierConverter;

@BeforeAll
public static void setUp() throws Exception {
piMultiplierConverter = MultiplyConverter.ofPiExponent(1);
}

@Test
public void testConvertMethod() {
assertEquals(314.15, piMultiplierConverter.convert(100), 0.1);
assertEquals(0, piMultiplierConverter.convert(0), 0);
assertEquals(-314.15, piMultiplierConverter.convert(-100), 0.1);
}

// @Test
// public void testConvertBigDecimalMethod() {
// assertEquals(314.15, piMultiplierConverter.convert(new BigDecimal("100"), MathContext.DECIMAL32).doubleValue(), 0.1);
// assertEquals(0, piMultiplierConverter.convert(BigDecimal.ZERO, MathContext.DECIMAL32).doubleValue(), 0);
// assertEquals(-314.15, piMultiplierConverter.convert(new BigDecimal("-100"), MathContext.DECIMAL32).doubleValue(), 0.1);
// }

@Test
public void testEqualityOfTwoLogConverter() {
assertNotNull(piMultiplierConverter);
}

// @Test
// public void testGetValuePiDivisorConverter() {
// if(piMultiplierConverter instanceof PowerOfPiConverter) {
// assertEquals(1, piMultiplierConverter.g .getExponent());
// }

@Test
public void isLinearOfLogConverterTest() {
assertTrue(piMultiplierConverter.isLinear());
}
public class AngleTest {

@Test
public void testAngleConverter() {
Quantity<Angle> sut = Quantities.getQuantity(BigDecimal.ONE, NonSI.DEGREE_ANGLE).to(Units.RADIAN);
Quantity<Angle> sut = Quantities.getQuantity(1, NonSI.DEGREE_ANGLE).to(Units.RADIAN);
assertNotNull(sut);
assertEquals(Units.RADIAN, sut.getUnit());
assertEquals(new BigDecimal("0.0174532925199432957692369076848861280629300682621303282056192814575568"), sut.getValue());
}

@Test
public void testAngleConverterOpposite() {
Quantity<Angle> sut = Quantities.getQuantity(BigDecimal.ONE, Units.RADIAN).to(NonSI.DEGREE_ANGLE);
Quantity<Angle> sut = Quantities.getQuantity(1d, Units.RADIAN).to(NonSI.DEGREE_ANGLE);
assertNotNull(sut);
assertEquals(NonSI.DEGREE_ANGLE, sut.getUnit());
assertEquals(new BigDecimal("57.2957795130823208767981548141051660"), sut.getValue());
Expand Down
50 changes: 33 additions & 17 deletions units/src/test/java/si/uom/ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,49 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.measure.Quantity;
import javax.measure.quantity.Angle;
import tech.units.indriya.function.MultiplyConverter;

import org.junit.jupiter.api.Test;
public class ConverterTest {

import tech.units.indriya.quantity.Quantities;
import tech.units.indriya.unit.Units;
private static MultiplyConverter piMultiplierConverter;

@BeforeAll
public static void setUp() throws Exception {
piMultiplierConverter = MultiplyConverter.ofPiExponent(1);
}

public class ConverterTest {
@Test
public void testConvertMethod() {
assertEquals(314.15, piMultiplierConverter.convert(100), 0.1);
assertEquals(0, piMultiplierConverter.convert(0), 0);
assertEquals(-314.15, piMultiplierConverter.convert(-100), 0.1);
}

// @Test
// public void testConvertBigDecimalMethod() {
// assertEquals(314.15, piMultiplierConverter.convert(new BigDecimal("100"), MathContext.DECIMAL32).doubleValue(), 0.1);
// assertEquals(0, piMultiplierConverter.convert(BigDecimal.ZERO, MathContext.DECIMAL32).doubleValue(), 0);
// assertEquals(-314.15, piMultiplierConverter.convert(new BigDecimal("-100"), MathContext.DECIMAL32).doubleValue(), 0.1);
// }

@Test
public void testAngleConverter() {
Quantity<Angle> sut = Quantities.getQuantity(1, NonSI.DEGREE_ANGLE).to(Units.RADIAN);
assertNotNull(sut);
assertEquals(Units.RADIAN, sut.getUnit());
assertEquals(new BigDecimal("0.0174532925199432957692369076848861280629300682621303282056192814575568"), sut.getValue());
public void testEqualityOfTwoLogConverter() {
assertNotNull(piMultiplierConverter);
}

// @Test
// public void testGetValuePiDivisorConverter() {
// if(piMultiplierConverter instanceof PowerOfPiConverter) {
// assertEquals(1, piMultiplierConverter.g .getExponent());
// }

@Test
public void testAngleConverterOpposite() {
Quantity<Angle> sut = Quantities.getQuantity(1d, Units.RADIAN).to(NonSI.DEGREE_ANGLE);
assertNotNull(sut);
assertEquals(NonSI.DEGREE_ANGLE, sut.getUnit());
assertEquals(new BigDecimal("57.2957795130823208767981548141051660"), sut.getValue());
public void isLinearOfLogConverterTest() {
assertTrue(piMultiplierConverter.isLinear());
}
}

0 comments on commit 8a94c57

Please sign in to comment.