Commit e8e74ab4 authored by Justin Dearden's avatar Justin Dearden
Browse files

Version 3.0

Implemented the sin function - more test cases are passing.
parent 36357be7
......@@ -134,7 +134,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toDegrees(i));
double actual = TrigFunctions.sin(i);
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -143,7 +143,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toDegrees(i));
double actual = TrigFunctions.sin(i);
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -152,7 +152,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toDegrees(i));
double actual = TrigFunctions.sin(i);
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -161,7 +161,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toDegrees(i));
double actual = TrigFunctions.sin(i);
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -170,7 +170,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toDegrees(i));
double actual = TrigFunctions.sin(i);
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -179,7 +179,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toRadians(i));
double actual = TrigFunctions.sin(TrigFunctions.toRadian(i));
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -188,7 +188,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toRadians(i));
double actual = TrigFunctions.sin(TrigFunctions.toRadian(i));
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -197,7 +197,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toRadians(i));
double actual = TrigFunctions.sin(TrigFunctions.toRadian(i));
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -206,7 +206,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toRadians(i));
double actual = TrigFunctions.sin(TrigFunctions.toRadian(i));
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
@Test
......@@ -215,7 +215,7 @@ public class TrigFunctionTest {
double expected = Math.sin(Math.toRadians(i));
double actual = TrigFunctions.sin(TrigFunctions.toRadian(i));
assertEquals(expected, actual);
assertEquals(expected, actual, 0);
}
//COS TESTS
......
......@@ -23,7 +23,7 @@ public class TrigFunctions {
public static double toRadian(double degrees) {
double result = degrees * (3.141592653589793 / 180);
double result = degrees * (3.141592653589793238462643383279502884197169399 / 180);
return result;
}
......@@ -31,10 +31,22 @@ public class TrigFunctions {
public static double sin(double degrees) {
double result = degrees;
return 0;
//Taylor series - calculate sin with an accuracy of 15
for(int i = 1; i <= 15; i++) {
//Checks if power is even the result will be positive - if power is odd its negative
if(i % 2 == 0) {
result += TrigFunctions.power(degrees, 2 * i + 1) / TrigFunctions.factorial(2 * i + 1);
}
else {
result -= TrigFunctions.power(degrees, 2 * i + 1) / TrigFunctions.factorial(2 * i + 1);
}
}
return result;
}
public static double cos(double degrees) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment