Commit 4dfc3a14 authored by neel2468's avatar neel2468
Browse files

completed version 2.0

parent 30356320
/Trigo/
/TrigoTest/
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -3,7 +3,7 @@ public class Cos extends Trignometry {
public Cos() {}
private int numOfTerms=5;
private int numOfTerms=12;
@Override
public double calculate(double input, String s) {
......@@ -18,15 +18,12 @@ public class Cos extends Trignometry {
{
if(numOfTerms==1) {
sum=1;
sum=1;
}
else
{
sum=sum+Math.pow(-1,i-1)*(Math.pow(angleInRadian,j)/Factorial.calculate_fact(j));
}
}
......
......@@ -3,15 +3,16 @@ package Trigo;
public class Factorial {
public static int calculate_fact(int n) {
int fact=1;
if(n==0) {return 1;}
if(n>0) {
for(int i=1;i<=n;i++) {
public static double calculate_fact(double d) {
double fact=1;
if(d<=1) {return 1;}
else {
for(int i=1;i<=d;i++) {
fact=fact*i;
}
}
return fact;
}
}
}
package Trigo;
import Trigo.Trignometry;
import Trigo.*;
public class Main {
public static void main(String args[]) {
Trignometry sin=new Sin();
Trignometry cos=new Cos();
Trignometry tan=new Tan();
System.out.println(sin.calculate(90,"DEGREE"));
System.out.println(cos.calculate(60,"DEGREE"));
System.out.println(tan.calculate(45,"DEGREE"));
System.out.println(sin.calculate(77,"DEGREE"));
System.out.println(cos.calculate(77,"DEGREE"));
System.out.println(tan.calculate(77,"DEGREE"));
}
......
......@@ -2,7 +2,7 @@ package Trigo;
import Trigo.Factorial;
public class Sin extends Trignometry{
private int numOfTerms=2;
private int numOfTerms=10;
public void Sin() {
......@@ -13,17 +13,11 @@ public class Sin extends Trignometry{
double angleInRadian=input;
if(s.equals("DEGREE")) {
angleInRadian=degreeToRadian(angleInRadian);
//System.out.print("In radian"+sin);
}
double sum=0;
for(int i=1,j=1;i<=numOfTerms;i++,j=j+2)
double sum=angleInRadian;
for(int i=1;i<=numOfTerms;i++)
{
if(i%2!=0)
{
sum=sum+Math.pow(angleInRadian,j)/Factorial.calculate_fact(j);
}
else
sum=sum-Math.pow(angleInRadian,j)/Factorial.calculate_fact(j);
sum=sum+Math.pow(-1,i)*Math.pow(angleInRadian,2*i+1)/Factorial.calculate_fact(2*i+1);
}
......
......@@ -12,8 +12,8 @@ public class Tan extends Trignometry{
Trignometry sin=new Sin();
Trignometry cos=new Cos();
double numerator=sin.calculate(input,"DEGREE");
double denominator=cos.calculate(input,"DEGREE");
double numerator=sin.calculate(input,s);
double denominator=cos.calculate(input,s);
return (numerator/denominator);
}
......
......@@ -21,92 +21,86 @@ class CosTest {
}
@Test
public void testCosInRadianFirstQuad() {
double actual = cos.calculate(25, "RADIAN");
assertEquals(Math.cos(25), actual,0.0001," Cos First Quad");
public void testCocosRadianFirstQuad() {
double actual = cos.calculate(1.309, "RADIAN");
assertEquals(Math.cos(1.309), actual,0.0001," Cos First Quad");
}
@Test
public void testCosInRadianSecondQuad() {
double actual = cos.calculate(100, "RADIAN");
assertEquals(Math.cos(100), actual,0.0001," Cos Second Quad");
public void testCocosRadianSecondQuad() {
double actual = cos.calculate(2.93215, "RADIAN");
assertEquals(Math.cos(2.93215), actual,0.0001," Cos Second Quad");
}
@Test
public void testCosInRadianThirdQuad() {
double actual = cos.calculate(250, "RADIAN");
assertEquals(Math.cos(250), actual,0.0001," Cos Third Quad");
public void testCocosRadianThirdQuad() {
double actual = cos.calculate(3.59538, "RADIAN");
assertEquals(Math.cos(3.59538), actual,0.0001," Cos Third Quad");
}
@Test
public void testCosInRadianFourthQuad() {
double actual = cos.calculate(345, "RADIAN");
assertEquals(Math.cos(345), actual,0.0001," Cos Fourth Quad");
public void testCocosRadianFourthQuad() {
double actual = cos.calculate(6.10865, "RADIAN");
assertEquals(Math.cos(6.10865), actual,0.0001," Cos Fourth Quad");
}
@Test
public void testCosDegreeFirstQuad() {
double actual = cos.calculate(25, "DEGREE");
assertEquals(Math.cos(25), actual,0.0001," Cos First Quad");
assertEquals(Math.cos(Math.toRadians(25)), actual,0.0001," Cos First Quad");
}
@Test
public void testCosDegreeSecondQuad() {
double actual = cos.calculate(100, "DEGREE");
assertEquals(Math.cos(100), actual,0.0001," Cos Second Quad");
assertEquals(Math.cos(Math.toRadians(100)), actual,0.0001," Cos Second Quad");
}
@Test
public void testCosDegreeThirdQuad() {
double actual = cos.calculate(250, "DEGREE");
assertEquals(Math.cos(250), actual,0.0001," Cos Third Quad");
assertEquals(Math.cos(Math.toRadians(250)), actual,0.0001," Cos Third Quad");
}
@Test
public void testCosDegreeFourthQuad() {
double actual = cos.calculate(345, "DEGREE");
assertEquals(Math.cos(345), actual,0.0001," Cos Fourth Quad");
assertEquals(Math.cos(Math.toRadians(345)), actual,0.0001," Cos Fourth Quad");
}
@Test
public void testCos() {
double actual = cos.calculate(0, "DEGREE");
assertEquals(Math.cos(0), actual,0.0001);
assertEquals(Math.cos(Math.toRadians(0)), actual,0.0001);
actual = cos.calculate(90, "DEGREE");
assertEquals(Math.cos(90), actual,0.0001);
assertEquals(Math.cos(Math.toRadians(90)), actual,0.0001);
actual = cos.calculate(180, "DEGREE");
assertEquals(Math.cos(180), actual,0.0001);
assertEquals(Math.cos(Math.toRadians(180)), actual,0.0001);
actual = cos.calculate(270, "DEGREE");
assertEquals(Math.cos(270), actual,0.0001);
assertEquals(Math.cos(Math.toRadians(270)), actual,0.0001);
actual = cos.calculate(360, "DEGREE");
assertEquals(Math.cos(360), actual,0.0001);
assertEquals(Math.cos(Math.toRadians(360)), actual,0.0001);
actual = cos.calculate(0, "RADIAN");
assertEquals(Math.cos(0), actual,0.0001);
actual = cos.calculate(90, "RADIAN");
assertEquals(Math.cos(90), actual,0.0001);
actual = cos.calculate(180, "RADIAN");
assertEquals(Math.cos(180), actual,0.0001);
actual = cos.calculate(270, "RADIAN");
assertEquals(Math.cos(270), actual,0.0001);
actual = cos.calculate(0.26179, "RADIAN");
assertEquals(Math.cos(0.26179), actual,0.0001);
actual = cos.calculate(360, "RADIAN");
assertEquals(Math.cos(360), actual,0.0001);
actual = cos.calculate(2.4085, "RADIAN");
assertEquals(Math.cos(2.4085), actual,0.0001);
actual = cos.calculate(0/0, "RADIAN");
assertEquals(Math.cos(0/0), actual,0.0001);
actual = cos.calculate(3.4033, "RADIAN");
assertEquals(Math.cos(3.4033), actual,0.0001);
actual = cos.calculate(0/0, "DEGREE");
assertEquals(Math.cos(0/0), actual,0.0001);
actual = cos.calculate(5.4454, "RADIAN");
assertEquals(Math.cos(5.4454), actual,0.0001);
}
......
......@@ -22,92 +22,86 @@ class SinTest {
@Test
public void testSinInRadianFirstQuad() {
double actual = sin.calculate(25, "RADIAN");
assertEquals(Math.sin(25), actual,0.0001," Sin First Quad");
double actual = sin.calculate(1.309, "RADIAN");
assertEquals(Math.sin(1.309), actual,0.0001," Sin First Quad");
}
@Test
public void testSinInRadianSecondQuad() {
double actual = sin.calculate(100, "RADIAN");
assertEquals(Math.sin(100), actual,0.0001," Sin Second Quad");
double actual = sin.calculate(2.93215, "RADIAN");
assertEquals(Math.sin(2.93215), actual,0.0001," Sin Second Quad");
}
@Test
public void testSinInRadianThirdQuad() {
double actual = sin.calculate(250, "RADIAN");
assertEquals(Math.sin(250), actual,0.0001," Sin Third Quad");
double actual = sin.calculate(3.59538, "RADIAN");
assertEquals(Math.sin(3.59538), actual,0.0001," Sin Third Quad");
}
@Test
public void testSinInRadianFourthQuad() {
double actual = sin.calculate(345, "RADIAN");
assertEquals(Math.sin(345), actual,0.0001," Sin Fourth Quad");
double actual = sin.calculate(6.10865, "RADIAN");
assertEquals(Math.sin(6.10865), actual,0.0001," Sin Fourth Quad");
}
@Test
public void testSInDegreeFirstQuad() {
double actual = sin.calculate(25, "DEGREE");
assertEquals(Math.sin(25), actual,0.0001," Sin First Quad");
assertEquals(Math.sin(Math.toRadians(25)), actual,0.0001," Sin First Quad");
}
@Test
public void testSInDegreeSecondQuad() {
double actual = sin.calculate(100, "DEGREE");
assertEquals(Math.sin(100), actual,0.0001," Sin Second Quad");
assertEquals(Math.sin(Math.toRadians(100)), actual,0.0001," Sin Second Quad");
}
@Test
public void testSInDegreeThirdQuad() {
double actual = sin.calculate(250, "DEGREE");
assertEquals(Math.sin(250), actual,0.0001," Sin Third Quad");
assertEquals(Math.sin(Math.toRadians(250)), actual,0.0001," Sin Third Quad");
}
@Test
public void testSInDegreeFourthQuad() {
double actual = sin.calculate(345, "DEGREE");
assertEquals(Math.sin(345), actual,0.0001," Sin Fourth Quad");
assertEquals(Math.sin(Math.toRadians(345)), actual,0.0001," Sin Fourth Quad");
}
@Test
public void testSin() {
double actual = sin.calculate(0, "DEGREE");
assertEquals(Math.sin(0), actual,0.0001);
assertEquals(Math.sin(Math.toRadians(0)), actual,0.0001);
actual = sin.calculate(90, "DEGREE");
assertEquals(Math.sin(90), actual,0.0001);
assertEquals(Math.sin(Math.toRadians(90)), actual,0.0001);
actual = sin.calculate(180, "DEGREE");
assertEquals(Math.sin(180), actual,0.0001);
assertEquals(Math.sin(Math.toRadians(180)), actual,0.0001);
actual = sin.calculate(270, "DEGREE");
assertEquals(Math.sin(270), actual,0.0001);
assertEquals(Math.sin(Math.toRadians(270)), actual,0.0001);
actual = sin.calculate(360, "DEGREE");
assertEquals(Math.sin(360), actual,0.0001);
assertEquals(Math.sin(Math.toRadians(360)), actual,0.0001);
actual = sin.calculate(0, "RADIAN");
assertEquals(Math.sin(0), actual,0.0001);
actual = sin.calculate(90, "RADIAN");
assertEquals(Math.sin(90), actual,0.0001);
actual = sin.calculate(180, "RADIAN");
assertEquals(Math.sin(180), actual,0.0001);
actual = sin.calculate(270, "RADIAN");
assertEquals(Math.sin(270), actual,0.0001);
actual = sin.calculate(0.26179, "RADIAN");
assertEquals(Math.sin(0.26179), actual,0.0001);
actual = sin.calculate(360, "RADIAN");
assertEquals(Math.sin(360), actual,0.0001);
actual = sin.calculate(2.4085, "RADIAN");
assertEquals(Math.sin(2.4085), actual,0.0001);
actual = sin.calculate(0/0, "RADIAN");
assertEquals(Math.sin(0/0), actual,0.0001);
actual = sin.calculate(0/0, "DEGREE");
assertEquals(Math.sin(0/0), actual,0.0001);
actual = sin.calculate(3.4033, "RADIAN");
assertEquals(Math.sin(3.4033), actual,0.0001);
actual = sin.calculate(5.4454, "RADIAN");
assertEquals(Math.sin(5.4454), actual,0.0001);
}
......
......@@ -22,92 +22,86 @@ class TanTest {
@Test
public void testTanInRadianFirstQuad() {
double actual = tan.calculate(25, "RADIAN");
assertEquals(Math.tan(25), actual,0.0001," Tan First Quad");
double actual = tan.calculate(1.309,"RADIAN");
assertEquals(Math.tan(1.309), actual,0.0001," Tan First Quad");
}
@Test
public void testTanInRadianSecondQuad() {
double actual = tan.calculate(100, "RADIAN");
assertEquals(Math.tan(100), actual,0.0001," Tan Second Quad");
double actual = tan.calculate(2.93215, "RADIAN");
assertEquals(Math.tan(2.93215), actual,0.0001," Tan Second Quad");
}
@Test
public void testTanInRadianThirdQuad() {
double actual = tan.calculate(250, "RADIAN");
assertEquals(Math.tan(250), actual,0.0001," Tan Third Quad");
double actual = tan.calculate(3.59538, "RADIAN");
assertEquals(Math.tan(3.59538), actual,0.0001," Tan Third Quad");
}
@Test
public void testTanInRadianFourthQuad() {
double actual = tan.calculate(345, "RADIAN");
assertEquals(Math.tan(345), actual,0.0001," Tan Fourth Quad");
double actual = tan.calculate(6.10865, "RADIAN");
assertEquals(Math.tan(6.10865), actual,0.0001," Tan Fourth Quad");
}
@Test
public void testTanDegreeFirstQuad() {
public void testtanDegreeFirstQuad() {
double actual = tan.calculate(25, "DEGREE");
assertEquals(Math.tan(25), actual,0.0001," Tan First Quad");
assertEquals(Math.tan(Math.toRadians(25)), actual,0.0001," tan First Quad");
}
@Test
public void testTanDegreeSecondQuad() {
public void testtanDegreeSecondQuad() {
double actual = tan.calculate(100, "DEGREE");
assertEquals(Math.tan(100), actual,0.0001," Tan Second Quad");
assertEquals(Math.tan(Math.toRadians(100)), actual,0.0001," tan Second Quad");
}
@Test
public void testTanDegreeThirdQuad() {
public void testtanDegreeThirdQuad() {
double actual = tan.calculate(250, "DEGREE");
assertEquals(Math.tan(250), actual,0.0001," Tan Third Quad");
assertEquals(Math.tan(Math.toRadians(250)), actual,0.0001," tan Third Quad");
}
@Test
public void testTanDegreeFourthQuad() {
public void testtanDegreeFourthQuad() {
double actual = tan.calculate(345, "DEGREE");
assertEquals(Math.tan(345), actual,0.0001," Tan Fourth Quad");
assertEquals(Math.tan(Math.toRadians(345)), actual,0.0001," tan Fourth Quad");
}
@Test
public void testTan() {
public void testtan() {
double actual = tan.calculate(0, "DEGREE");
assertEquals(Math.tan(0), actual,0.0001);
assertEquals(Math.tan(Math.toRadians(0)), actual,0.0001);
actual = tan.calculate(90, "DEGREE");
assertEquals(Math.tan(90), actual,0.0001);
actual = tan.calculate(80, "DEGREE");
assertEquals(Math.tan(Math.toRadians(80)), actual,0.0001);
actual = tan.calculate(180, "DEGREE");
assertEquals(Math.tan(180), actual,0.0001);
actual = tan.calculate(170, "DEGREE");
assertEquals(Math.tan(Math.toRadians(170)), actual,0.0001);
actual = tan.calculate(270, "DEGREE");
assertEquals(Math.tan(270), actual,0.0001);
actual = tan.calculate(260, "DEGREE");
assertEquals(Math.tan(Math.toRadians(260)), actual,0.0001);
actual = tan.calculate(360, "DEGREE");
assertEquals(Math.tan(360), actual,0.0001);
actual = tan.calculate(350, "DEGREE");
assertEquals(Math.tan(Math.toRadians(350)), actual,0.0001);
actual = tan.calculate(0, "RADIAN");
assertEquals(Math.tan(0), actual,0.0001);
actual = tan.calculate(90, "RADIAN");
assertEquals(Math.tan(90), actual,0.0001);
actual = tan.calculate(180, "RADIAN");
assertEquals(Math.tan(180), actual,0.0001);
actual = tan.calculate(270, "RADIAN");
assertEquals(Math.tan(270), actual,0.0001);
actual = tan.calculate(0.7853, "RADIAN");
assertEquals(Math.tan(0.7853), actual,0.0001);
actual = tan.calculate(360, "RADIAN");
assertEquals(Math.tan(360), actual,0.0001);
actual = tan.calculate(2.4085, "RADIAN");
assertEquals(Math.tan(2.4085), actual,0.0001);
actual = tan.calculate(0/0, "RADIAN");
assertEquals(Math.tan(0/0), actual,0.0001);
actual = tan.calculate(0/0, "DEGREE");
assertEquals(Math.tan(0/0), actual,0.0001);
actual = tan.calculate(3.4033, "RADIAN");
assertEquals(Math.tan(3.4033), actual,0.0001);
actual = tan.calculate(5.4454, "RADIAN");
assertEquals(Math.tan(5.4454), actual,0.0001);
}
......
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