<reponame>henrystoldt/MAPLEAF
#Created by: <NAME>
#May 2019

#To run tests:
#In this file: [test_StandardAtmosphere.py]
#In all files in the current directory: [python -m unittest discover]
#Add [-v] for verbose output (displays names of all test functions)

import unittest

from MAPLEAF.Motion import ForceMomentSystem
from MAPLEAF.Motion import Vector


class TestForceMomentSystem(unittest.TestCase):
    def setUp(self):
        self.appliedForce1 = ForceMomentSystem(Vector(0, 0, 10), Vector(1, 0, 0), Vector(0,0,0))
        self.appliedForce2 = ForceMomentSystem(Vector(0, 0, 10), Vector(2, 0, 0), Vector(0,0,0))
        self.appliedForce3 = ForceMomentSystem(Vector(10, 0, 0), Vector(0, 1, 0), Vector(0,0,0))

        self.correctForce1 = ForceMomentSystem(Vector(0, 0, 20), Vector(0,0,0), Vector(0, -30, 0))
        self.correctForce2 = ForceMomentSystem(Vector(10, 0, 10), Vector(0,0,0), Vector(0, -10, -10))

    def test_combineForceMomentSystems(self):
        combinedForce = self.appliedForce1 + self.appliedForce2
        forceAtCG  = combinedForce.getAt(Vector(0,0,0))
        self.assertEqual(forceAtCG, self.correctForce1)

        combinedForce2 = self.appliedForce1 + self.appliedForce3
        forceAtCG2 = combinedForce2.getAt(Vector(0,0,0))
        self.assertEqual(forceAtCG2, self.correctForce2)

    def  test_combineForceMomentSystems_2(self):
        # Example Question 16 - http://www.ce.siue.edu/examples/Worked_examples_Internet_text-only/Data_files-Worked_Exs-Word_&_pdf/Equivalent_forces.pdf
        # Define Force-Moment 1
        force1 = Vector(0, -3.464, -2)
        m1 = Vector(0, -51.962, -30)
        location1 = Vector(4, 1.5, 4.402)
        fms1 = ForceMomentSystem(force1, location1, m1)
        
        # Define Force-Moment 2
        force2 = Vector(-6, 0, 0)
        m2 = Vector(-80, 0, 0)
        location2 = Vector(8, 1.5, 1)
        fms2 = ForceMomentSystem(force2, location2, m2)

        # Combine
        combinedForce = fms1 + fms2
        combinedForceAtOrigin = combinedForce.getAt(Vector(0,0,0))

        # Define correct/expected result
        expectedResultantForce = Vector(-6, -3.464, -2)
        expectedResultantMoment = Vector(12.249, 2, -4.856) # Only includes moments generated by forces, not the moments applied
        resultantLocation = Vector(0,0,0)
        expectedResult = ForceMomentSystem(expectedResultantForce, resultantLocation, expectedResultantMoment)

        # Compare
        from test.testUtilities import assertVectorsAlmostEqual
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.force, expectedResult.force)
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.location, expectedResult.location)
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.moment - m1 - m2, expectedResult.moment, 3)

#If this file is run by itself, run the tests above
if __name__ == '__main__':
    unittest.main()

#Created by: <NAME>
#May 2019

#To run tests:
#In this file: [test_StandardAtmosphere.py]
#In all files in the current directory: [python -m unittest discover]
#Add [-v] for verbose output (displays names of all test functions)

import unittest

from MAPLEAF.Motion import ForceMomentSystem
from MAPLEAF.Motion import Vector


class TestForceMomentSystem(unittest.TestCase):
    def setUp(self):
        self.appliedForce1 = ForceMomentSystem(Vector(0, 0, 10), Vector(1, 0, 0), Vector(0,0,0))
        self.appliedForce2 = ForceMomentSystem(Vector(0, 0, 10), Vector(2, 0, 0), Vector(0,0,0))
        self.appliedForce3 = ForceMomentSystem(Vector(10, 0, 0), Vector(0, 1, 0), Vector(0,0,0))

        self.correctForce1 = ForceMomentSystem(Vector(0, 0, 20), Vector(0,0,0), Vector(0, -30, 0))
        self.correctForce2 = ForceMomentSystem(Vector(10, 0, 10), Vector(0,0,0), Vector(0, -10, -10))

    def test_combineForceMomentSystems(self):
        combinedForce = self.appliedForce1 + self.appliedForce2
        forceAtCG  = combinedForce.getAt(Vector(0,0,0))
        self.assertEqual(forceAtCG, self.correctForce1)

        combinedForce2 = self.appliedForce1 + self.appliedForce3
        forceAtCG2 = combinedForce2.getAt(Vector(0,0,0))
        self.assertEqual(forceAtCG2, self.correctForce2)

    def  test_combineForceMomentSystems_2(self):
        # Example Question 16 - http://www.ce.siue.edu/examples/Worked_examples_Internet_text-only/Data_files-Worked_Exs-Word_&_pdf/Equivalent_forces.pdf
        # Define Force-Moment 1
        force1 = Vector(0, -3.464, -2)
        m1 = Vector(0, -51.962, -30)
        location1 = Vector(4, 1.5, 4.402)
        fms1 = ForceMomentSystem(force1, location1, m1)
        
        # Define Force-Moment 2
        force2 = Vector(-6, 0, 0)
        m2 = Vector(-80, 0, 0)
        location2 = Vector(8, 1.5, 1)
        fms2 = ForceMomentSystem(force2, location2, m2)

        # Combine
        combinedForce = fms1 + fms2
        combinedForceAtOrigin = combinedForce.getAt(Vector(0,0,0))

        # Define correct/expected result
        expectedResultantForce = Vector(-6, -3.464, -2)
        expectedResultantMoment = Vector(12.249, 2, -4.856) # Only includes moments generated by forces, not the moments applied
        resultantLocation = Vector(0,0,0)
        expectedResult = ForceMomentSystem(expectedResultantForce, resultantLocation, expectedResultantMoment)

        # Compare
        from test.testUtilities import assertVectorsAlmostEqual
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.force, expectedResult.force)
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.location, expectedResult.location)
        assertVectorsAlmostEqual(self, combinedForceAtOrigin.moment - m1 - m2, expectedResult.moment, 3)

#If this file is run by itself, run the tests above
if __name__ == '__main__':
    unittest.main()
#Created by: <NAME> #May 2019 #To run tests: #In this file: [test_StandardAtmosphere.py] #In all files in the current directory: [python -m unittest discover] #Add [-v] for verbose output (displays names of all test functions) # Example Question 16 - http://www.ce.siue.edu/examples/Worked_examples_Internet_text-only/Data_files-Worked_Exs-Word_&_pdf/Equivalent_forces.pdf # Define Force-Moment 1 # Define Force-Moment 2 # Combine # Define correct/expected result # Only includes moments generated by forces, not the moments applied # Compare #If this file is run by itself, run the tests above