import static org.junit.Assert.*;
import org.junit.Test;
public class PolynomTest {
Polynom p1 = new Polynom(2, 0, 1, 3);
Polynom p2 = new Polynom(1, 2, 6, 5);
Polynom p3 = new Polynom(3, 3, 0, 3);
Polynom p4 = new Polynom(6, 4, 10, 5);
Polynom p5 = new Polynom(8, 9, 6, 0);
Polynom p6 = new Polynom(0, 2, 5, 8);
Polynom p7 = new Polynom(6, 5, 4, 9);
Polynom p8 = new Polynom(5, 7, 0, 1);
[USER=5814]@test[/USER]
public void constructor1() {
Polynom p = new Polynom(5);
assertEquals(5, p.map(10), "constructor");
}
[USER=5814]@test[/USER]
public void constructor2() {
Polynom p = new Polynom(1, 2);
assertEquals(12, p.map(10), "constructor");
}
[USER=5814]@test[/USER]
public void constructor3() {
Polynom p = new Polynom(1, 2, 3);
assertEquals(123, p.map(10), "constructor");
}
[USER=5814]@test[/USER]
public void constructor4() {
Polynom p = new Polynom(1, 2, 3, 4);
assertEquals(1234, p.map(10), "constructor");
}
[USER=5814]@test[/USER]
public void test1() {
assertEquals("2*x^3 + x + 3", p1.toString(), "toString");
assertEquals(21, p1.map(2), "map");
assertEquals("6*x^2 + 1", Polynom.derivation(p1).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test2() {
assertEquals("x^3 + 2*x^2 + 6*x + 5", p2.toString(), "toString");
assertEquals(329, p2.map(6), "map");
assertEquals("3*x^2 + 4*x + 6", Polynom.derivation(p2).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test3() {
assertEquals("3*x^3 + 3*x^2 + 3", p3.toString(), "toString");
assertEquals(2433, p3.map(9), "map");
assertEquals("9*x^2 + 6*x", Polynom.derivation(p3).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test4() {
assertEquals("6*x^3 + 4*x^2 + 10*x + 5", p4.toString(), "toString");
assertEquals(25, p4.map(1), "map");
assertEquals("18*x^2 + 8*x + 10", Polynom.derivation(p4).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test5() {
assertEquals("8*x^3 + 9*x^2 + 6*x", p5.toString(), "toString");
assertEquals(0, p5.map(0), "map");
assertEquals("24*x^2 + 18*x + 6", Polynom.derivation(p5).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test6() {
assertEquals("2*x^2 + 5*x + 8", p6.toString(), "toString");
assertEquals(26, p6.map(2), "map");
assertEquals("4*x + 5", Polynom.derivation(p6).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test7() {
assertEquals("6*x^3 + 5*x^2 + 4*x + 9", p7.toString(), "toString");
assertEquals(24, p7.map(1), "map");
assertEquals("18*x^2 + 10*x + 4", Polynom.derivation(p7).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void test8() {
assertEquals("5*x^3 + 7*x^2 + 1", p8.toString(), "toString");
assertEquals(433, p8.map(4), "map");
assertEquals("15*x^2 + 14*x", Polynom.derivation(p8).toString(), "derivation");
}
[USER=5814]@test[/USER]
public void add1() {
p6.add(p5);
assertEquals("8*x^3 + 11*x^2 + 11*x + 8", p6.toString(), "add");
}
[USER=5814]@test[/USER]
public void add2() {
p2.add(p7);
assertEquals("7*x^3 + 7*x^2 + 10*x + 14", p2.toString(), "add");
}
[USER=5814]@test[/USER]
public void add3() {
p3.add(p4);
assertEquals("9*x^3 + 7*x^2 + 10*x + 8", p3.toString(), "add");
}
[USER=5814]@test[/USER]
public void add4() {
p5.add(p1);
assertEquals("10*x^3 + 9*x^2 + 7*x + 3", p5.toString(), "add");
}
[USER=5814]@test[/USER]
public void sub1() {
p7.subtract(p2);
assertEquals("5*x^3 + 3*x^2 - 2*x + 4", p7.toString(), "subtract");
}
[USER=5814]@test[/USER]
public void sub2() {
p3.subtract(p5);
assertEquals("-5*x^3 - 6*x^2 - 6*x + 3", p3.toString(), "subtract");
}
[USER=5814]@test[/USER]
public void sub3() {
p1.subtract(p6);
assertEquals("2*x^3 - 2*x^2 - 4*x - 5", p1.toString(), "subtract");
}
[USER=5814]@test[/USER]
public void sub4() {
p4.subtract(p8);
assertEquals("x^3 - 3*x^2 + 10*x + 4", p4.toString(), "subtract");
}
public static void assertEquals(int expected, int actual, String method) {
System.out.print("Testing " + method + " ");
if (expected != actual) {
System.out.println("failed. Expected " + expected + " but got " + actual + ".");
} else {
System.out.println("succeeded.");
}
}
public static void assertEquals(String expected, String actual, String method) {
System.out.print("Testing " + method + " ");
if (expected == null || !expected.equals(actual)) {
System.out.println("failed.");
System.out.println("## Expected:");
System.out.println(expected);
System.out.println("## Actual:");
System.out.println(actual);
if (expected.length() != actual.length()) {
System.out.println("Length of the Strings differ. Expected "+ expected.length() + " but got " + actual.length());
} else {
System.out.println("Length are ok.");
for (int i = 0; i < expected.length(); i++) {
if (expected.charAt(i) != actual.charAt(i)) {
System.out.println("Difference at position " + i + " expected " + expected.charAt(i) + " but got " + actual.charAt(i));
}
}
}
} else {
System.out.println("succeeded.");
}
}
}