Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
* implemented test class for sin, cos, tan, cot, sec & csc

Signed-off-by: johnzhouinfo <[email protected]>
  • Loading branch information
johnzhouinfo committed Nov 5, 2019
1 parent 4bb1d68 commit 63b5741
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions test/TrigFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
public class TrigFunctionTest {
/**
* This is a test class for testing trigfunction.TrigFunction functionality
* This is a test class for testing TrigFunction functionality
*/
private final double DIFF = 0.0000000000001;
private final double DIFF = 0.00000000001; //test for accuracy (11 decimal points )

@Test
public void sinSuccessTest() {
Expand Down Expand Up @@ -55,16 +55,28 @@ public void tanSuccessTest() {
public void tanInvalidTest() {
try {
TrigFunction.tan(Math.PI / 2);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + Math.PI / 2 + ")", e.getMessage());
}
try {
TrigFunction.tan(3 * Math.PI / 2);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
TrigFunction.tan((3 * Math.PI) / 2);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 3 * Math.PI / 2 + ")", e.getMessage());
}
try {
TrigFunction.tan(7 * Math.PI / 2);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 7 * Math.PI / 2 + ")", e.getMessage());
}
try {
TrigFunction.tan(9 * Math.PI / 2);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 9 * Math.PI / 2 + ")", e.getMessage());
}
}

@Test
Expand All @@ -82,16 +94,22 @@ public void secSuccessTest() {
public void secInvalidTest() {
try {
TrigFunction.sec(Math.PI / 2);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + Math.PI / 2 + ")", e.getMessage());
}
try {
TrigFunction.sec(3 * Math.PI / 2);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 3 * Math.PI / 2 + ")", e.getMessage());
}
try {
TrigFunction.sec(7 * Math.PI / 2);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 7 * Math.PI / 2 + ")", e.getMessage());
}
}

@Test
Expand All @@ -108,13 +126,19 @@ public void cotSuccessTest() {
public void cotInvalidTest() {
try {
TrigFunction.cot(0);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = 0)", e.getMessage());
}
try {
TrigFunction.cot(Math.PI);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 2 * Math.PI + ")", e.getMessage());
}
try {
TrigFunction.cot(2 * Math.PI);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 2 * Math.PI + ")", e.getMessage());
}
Expand All @@ -135,13 +159,19 @@ public void cscSuccessTest() {
public void cscInvalidTest() {
try {
TrigFunction.csc(0);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = 0)", e.getMessage());
}
try {
TrigFunction.csc(Math.PI);
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 2 * Math.PI + ")", e.getMessage());
}
try {
TrigFunction.csc(2 * Math.PI);
Assert.fail("Expected an trigfunction.InvalidInputException to be thrown");
Assert.fail("Expected an InvalidInputException to be thrown");
} catch (InvalidInputException e) {
Assert.assertEquals("Invalid number inputted (value = " + 2 * Math.PI + ")", e.getMessage());
}
Expand Down

0 comments on commit 63b5741

Please sign in to comment.