use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testExponentiate.
@Test
public void testExponentiate() {
Monomial m = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m.exponentiate(3));
m = makeMonomial("2");
Assert.assertEquals(makeMonomial("8"), m.exponentiate(3));
m = makeMonomial("2*x");
Assert.assertEquals(makeMonomial("8*x^3"), m.exponentiate(3));
m = makeMonomial("2*x^2");
Assert.assertEquals(makeMonomial("8*x^6"), m.exponentiate(3));
m = makeMonomial("2*y^2*x^3");
Assert.assertEquals(makeMonomial("8*x^9*y^6"), m.exponentiate(3));
m = makeMonomial("2*y^2*x^3");
Assert.assertEquals(makeMonomial("1"), m.exponentiate(0));
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testTimes.
@Test
public void testTimes() {
Monomial m1 = makeMonomial("2");
Monomial m2 = makeMonomial("3");
Assert.assertEquals(makeMonomial("6"), m1.times(m2));
m1 = makeMonomial("x");
m2 = makeMonomial("x");
Assert.assertEquals(makeMonomial("x^2"), m1.times(m2));
m1 = makeMonomial("2*x^2");
m2 = makeMonomial("3*x^3");
Assert.assertEquals(makeMonomial("6*x^5"), m1.times(m2));
m1 = makeMonomial("3*x^2*y");
m2 = makeMonomial("3*x^3*z^2");
Assert.assertEquals(makeMonomial("9*x^5*y*z^2"), m1.times(m2));
m1 = makeMonomial("0");
m2 = makeMonomial("3*x^3*z^2");
Assert.assertEquals(makeMonomial("0"), m1.times(m2));
m1 = makeMonomial("3*x^2*y");
m2 = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m1.times(m2));
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testDivideIllegalArgumentException.
@Test(expected = IllegalArgumentException.class)
public void testDivideIllegalArgumentException() {
Monomial m1 = makeMonomial("2*x^3");
Monomial m2 = makeMonomial("0*x");
m1.divide(m2);
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testDegree.
@Test
public void testDegree() {
Monomial m = makeMonomial("2");
Assert.assertEquals(0, m.degree());
m = makeMonomial("x");
Assert.assertEquals(1, m.degree());
m = makeMonomial("2*x");
Assert.assertEquals(1, m.degree());
m = makeMonomial("2*x^3");
Assert.assertEquals(3, m.degree());
m = makeMonomial("2*x^3*y");
Assert.assertEquals(4, m.degree());
m = makeMonomial("2*x^3*y*z^5");
Assert.assertEquals(9, m.degree());
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testGetCoefficient.
@Test
public void testGetCoefficient() {
Monomial m = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("0"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("1");
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("x");
Assert.assertEquals(makeMonomial("x"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("3*x^2");
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(makeMonomial("x^2"), m.getCoefficient(Expressions.parse("tuple(3)").getArguments()));
Assert.assertEquals(makeMonomial("3"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("(3, x)").getArguments()));
m = makeMonomial("3*x^2*y^4");
Assert.assertEquals(makeMonomial("3*x^2*y^4"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("3*x^2*y^4"), m.getCoefficient(Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(makeMonomial("3*y^4"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
}
Aggregations