Skip to content
Snippets Groups Projects
Commit eb0b399a authored by Goik Martin's avatar Goik Martin
Browse files

Test renaming, better zero categories

parent a8e5c2dd
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,14 @@ package de.hdm_stuttgart.mi.sd1.task2;
*
* <p>A quadratic polynomial \( p(x) = a x² + b x + c \) is being defined by its three coefficients
* \(a\), \(b\) and \(c\). This class limits coefficients \(a\), \(b\) and \(c\) to type <code>int</code>. For
* \(a \neq 0\) a general solution is being provided by:</p>
* \(a \neq 0\) zeroes are being calculated by:</p>
*
* <p>\[ x_{1,2} = {{-b \pm \sqrt{b^2 - 4 ac}} \over {2a}} \]</p>
*
* <p>Depending on \( b^2 - 4 ac \) being positive, zero or negative we have either two, one or no real solutions.</p>
* <p>For \( a \neq 0 \) depending on \( b^2 - 4 ac \) being positive, zero or negative we have either two, one or no
* real solutions.</p>
*
* <p>The following sample illustrates zeroes calculation depending on given values of \(a\), \(b\) and \(c\):</p>
* <p>The following samples illustrates calculation of zeroes depending on given values of \(a\), \(b\) and \(c\):</p>
*
* <table class="goikTableDefaults">
* <caption>Sample code illustrating zero values calculation</caption>
......
......@@ -5,7 +5,7 @@ package de.hdm_stuttgart.mi.sd1.task2;
*
* <p>A quadratic polynomial \( p(x) = a x² + b x + c \) is being defined by its three coefficients
* \(a\), \(b\) and \(c\). This class limits coefficients \(a\), \(b\) and \(c\) to type <code>int</code>. For
* \(a \neq 0\) a general solution is being provided by:</p>
* \(a \neq 0\) zeroes are being calculated by:</p>
*
* <p>\[ x_{1,2} = {{-b \pm \sqrt{b^2 - 4 ac}} \over {2a}} \]</p>
*
......@@ -180,9 +180,8 @@ public class QuadratPolynom {
/**
* <p>Re- setting the square coefficient in \( a x² \).</p>
* @param a The desired new value.
* @throws ArithmeticException The square coefficient \( a x² \) must not be zero
*/
public void setA(final int a) throws ArithmeticException {
public void setA(final int a) {
this.a = a;
}
/**
......@@ -203,38 +202,55 @@ public class QuadratPolynom {
/**
* <p>Zeroes are all values of \(x\) solving \(a x² + b x + c = 0\).</p>
*
* <p>For \(a \neq 0\) zeros are being calculated using:</p>
* <p>We observe different categories:</p>
*
* <p>\[ x = {{ -b \pm \sqrt {b² - 4 a c}} \over {2 a}} \]</p>
* <dl>
*
* @return <p>Distinct cases:</p>
* <dt>\( a = 0\):</dt>
* <dd>
* <dl>
* <dt>\( b = 0\):</dt>
* <dd>
* <dl>
* <dt>\( c = 0 \)</dt>
* <dd>Infinite number of zeroes \mathbb{R}, an {@link ArithmeticException} will be thrown</dd>
*
* <dl>
* <dt>\( c \neq 0 \)</dt>
* <dd>Empty set, no zero at all.</dd>
* </dl>
*
* <dt>\( a = b = c = 0\):</dt>
* <dd><p>Zero function, throw an {@link ArithmeticException}</p>.</dd>
* </dd>
*
* <dt>\( a = b = 0\) and \( c \neq 0\):</dt>
* <dd><p><code>double[0]</code> empty array indicating the non-existence of any zero.</p></dd>
* <dt>\( b \neq 0\):</dt>
* <dd>Zero at \(-{c\over b}\)</dd>
*
* <dt>\( a = c = 0\) and \( b \neq 0\):</dt>
* <dd><p><code>double[1]</code> array containing the single value \(0\)</p></dd>
* </dl>
*
* <dt>\( b² - 4 a c &lt; 0\):</dt>
* <dd><p><code>double[0]</code> empty array indicating the non-existence of any real zero.</p></dd>
* </dd>
*
* <dt>\( b² - 4 a c = 0\):</dt>
* <dd><p>An <code>double[1]</code> array containing the single zero {\(-b \over {2 a} \)}.</p></dd>
* <dt>\( a \neq 0\):</dt>
* <dd>
* <dl>
* <dt>\( b² - 4 a c &lt; 0\):</dt>
* <dd><p>Empty array <code>double[0]</code> indicating the non-existence of any real zero.</p></dd>
*
* <dt>\( b² - 4 a c &gt; 0\):</dt>
* <dd><p>An <code>double[2]</code> array containing two distinct zeroes
* \( {1\over {2 a}}\left( -b - \sqrt {b² - 4 a c}\right) \)
* and \( {1\over {2 a}}\left( -b + \sqrt {b² - 4 a c}\right) \) ordered by size.</p></dd>
* <dt>\( b² - 4 a c = 0\):</dt>
* <dd><p>An <code>double[1]</code> array containing the single zero {\(-b \over {2 a} \)}.</p></dd>
*
* <dt>\( b² - 4 a c &gt; 0\):</dt>
* <dd><p>An array <code>double[2]</code> containing two distinct zeroes
* \(-b + \sqrt {b² - 4 a c} \over {2 a} \)
* and \(-b - \sqrt {b² - 4 a c} \over {2 a} \) ordered by size.</p></dd>
* </dl>
* </dd>
* </dl>
*
* @return The finite set of zeroes. In case of an infinite number of zeroes an arithmetic exception is being thrown.
*
* @throws ArithmeticException In case of \(a = b = c = 0 \) an infinite number of zeroes exists which cannot be
* represented by a finite array of double values.
*/
public double[] getZeroes() {
public double[] getZeroes() throws ArithmeticException {
if (0 != a) { // square polynomial
final long radicand = ((long) b) * b - 4L * a * c; // Avoiding overflow errors
......
......@@ -3,7 +3,7 @@ package de.hdm_stuttgart.mi.sd1;
import de.hdm_stuttgart.mi.exam.unitmarking.RunTests;
import de.hdm_stuttgart.mi.sd1.task1.*;
import de.hdm_stuttgart.mi.sd1.task2.Test_QuadratPolynom;
import de.hdm_stuttgart.mi.sd1.task2.TestQuadratPolynom;
public class ShowReachedPoints {
......@@ -17,6 +17,6 @@ public class ShowReachedPoints {
"Task 1"
, A_TrafficLightTest.class, B_StringHelperTest.class, C_ArrayHelperTest.class, D_TextFrameTest.class
);
RunTests.exec("Task 2", Test_QuadratPolynom.class);
RunTests.exec("Task 2", TestQuadratPolynom.class);
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ import org.junit.Test;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Test_QuadratPolynom extends ExaminationTestDefaults {
public class TestQuadratPolynom extends ExaminationTestDefaults {
@Test
@Marking(points = 5)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment