コード例 #1
0
 def calculate_length2(self, radius):
     """
     function to calculate Length of overlapping circle without using library
     :param radius: value of radius in float
     :return:
     """
     alpha = Alpha()
     mymath = MyMath()
     lengthofline = 2 * radius * (
         1 - mymath.cosine(alpha.valueofalpha() / 2, 5))
     return lengthofline
コード例 #2
0
ファイル: alpha_value.py プロジェクト: samikshamahajan/Cheers
class Alpha:
    """
    Class containing method to calculate the value of alpha used in the program without using any libraries
    """
    mymath = MyMath()

    def valueofalpha(self):
        """
        function to calculate value of alpha using bisection method
        :return: float value of alpha
        """
        lower = 0
        upper = self.mymath.valueofpi()
        for i in range(10):
            mid = (lower + upper) / 2
            valueoffnatlower = self.fn(lower)
            valueoffnatmid = self.fn(mid)
            if valueoffnatlower * valueoffnatmid < 0:
                upper = mid
            else:
                lower = mid
        return (lower + upper) / 2

    def fn(self, x):
        value = x - self.mymath.sine(x, 5) - (self.mymath.valueofpi() / 2
                                              )  # expression
        return value
コード例 #3
0
    def calcStdDeviation(self):

        # determine the polarity std deviation of the users
        userPolarityList = []
        userSubjectivityList = []

        for i in range(0, len(self.userList)):

            userPolarityList += [self.userList[i].avgPolarity + 5.0]
            userSubjectivityList += [self.userList[i].avgSubjectivity + 5.0]

        # Send data off to be computed and set std
        self.stdPolarity = MyMath.stdDeviationWithAvg(userPolarityList,
                                                      self.avgPolarity + 5.0)
        self.stdSubjectivity = MyMath.stdDeviationWithAvg(
            userSubjectivityList, self.avgSubjectivity + 5.0)
コード例 #4
0
class TestMyMath(unittest.TestCase):
    """
    class to test various function in MyMath class
    """
    mymath = MyMath()

    def test_sine(self):
        """
        to test the value of sin
        :return: ok if test passes
        """
        self.assertEqual(MyMath.sine(self.mymath, 3, 5), 0.14112)

    def test_cosine(self):
        """
        to test value of cosine
        :return: ok if test passes
        """
        self.assertEqual(MyMath.cosine(self.mymath, 3, 5), -0.98999)

    def test_power(self):
        """
        to test value of power
        :return: ok if test passes
        """
        self.assertEqual(MyMath.power(self.mymath, 4, 3), 64)

    def test_factorial(self):
        """
        to test factorial value
        :return: ok if test passes
        """
        self.assertEqual(MyMath.factorial(self.mymath, 6), 720)

    def test_valueofpi(self):
        """
        to test value of pi
        :return: ok if test passes
        """
        self.assertEqual(MyMath.valueofpi(self.mymath), 3.1415826535897198)
コード例 #5
0
 def test_valueofpi(self):
     """
     to test value of pi
     :return: ok if test passes
     """
     self.assertEqual(MyMath.valueofpi(self.mymath), 3.1415826535897198)
コード例 #6
0
 def test_factorial(self):
     """
     to test factorial value
     :return: ok if test passes
     """
     self.assertEqual(MyMath.factorial(self.mymath, 6), 720)
コード例 #7
0
 def test_power(self):
     """
     to test value of power
     :return: ok if test passes
     """
     self.assertEqual(MyMath.power(self.mymath, 4, 3), 64)
コード例 #8
0
 def test_cosine(self):
     """
     to test value of cosine
     :return: ok if test passes
     """
     self.assertEqual(MyMath.cosine(self.mymath, 3, 5), -0.98999)
コード例 #9
0
 def test_sine(self):
     """
     to test the value of sin
     :return: ok if test passes
     """
     self.assertEqual(MyMath.sine(self.mymath, 3, 5), 0.14112)
コード例 #10
0
ファイル: Driver.py プロジェクト: balhafni/cv
    s1.lastName = "Stalin"
    s1.id = 1234
    s1.add_grade(45)
    s1.add_grade(90)
    s1.grade = s1.compute_grade()
    print(s1)

    s2 = Student()
    s2.firstName = "Vladimir"
    s2.lastName = "Lenin"
    s2.id = 2222    
    s2.add_grade(90)
    s2.add_grade(80)
    s2.grade = s2.compute_grade()
    print(s2)

    g1 = GraduateStudent("Karl","Marx",666)
    g1.add_grade(85)
    g1.add_grade(91)
    g1.grade = g1.computeGrade()
    print(g1)


    MyMath.pi = 3.141517 #invoking static field
    mm = MyMath("XYZ")
    print(mm.pi)
    mm2 = MyMath("PQR")
    print (mm2.showName() + " " + str(mm2.pi))
    print (MyMath.computeCylinderVolume(4.5, 7.2)) #invoking static method

コード例 #11
0
 def test(self):
     self.assertEqual(MyMath.sum(2, 3), 5)
コード例 #12
0
 def test(self):
     self.assertEqual(MyMath.substract(5, 3), 2)