import os
import unittest
from Logger import Logger

class TestLogger(unittest.TestCase):
    def test_file_handling(self):
        testLog = Logger("testLog")
        ## Check if program can create and open file
        self.assertTrue(testLog.opened)
        returns = testLog.close()
        ## Check if logger correctly signs bool OPENED and returns
        ##     0 as succes.
        self.assertFalse(testLog.opened)
        self.assertEqual(returns,0)
        returns = testLog.close()
        ## Check if logger returns 1 when trying to close already
        ##     closed file
        self.assertEqual(returns,1)
        ## Do cleanup:
        os.remove(testLog.name)
        
    def test_logging(self):
        testLog = Logger("testLog")
        testPhrase = "TestLine\r\n"
        testLog.save_line(testPhrase)
        testLog.close()
        logfile = open(testLog.name)
        content = logfile.read()
        logfile.close()
        saved = content.split(" : ")
        ## Check if saved data corresponds
        self.assertEqual(saved[1],testPhrase)
        ## cleanup
        os.remove(testLog.name)

from gpsNavigation import gpsModule,gpsPoint
class TestGPSNavigation(unittest.TestCase):
    def test_gps_angles(self):
        gpsMod = gpsModule()

        A = gpsPoint(10,10)
        B = gpsPoint(10.1,10.1)
        
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,15623.0)
        self.assertEqual(azimut,45.0)

        B = gpsPoint(10.0,10.1)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,10963.0)
        self.assertEqual(azimut,90.0)

        B = gpsPoint(9.9,10.1)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,15625.0)
        self.assertEqual(azimut,135.0)

        B = gpsPoint(9.9,10.0)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,11132.0)
        self.assertEqual(azimut,180.0)

        B = gpsPoint(9.9,9.9)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,15625.0)
        self.assertEqual(azimut,225.0)

        B = gpsPoint(10.0,9.9)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,10963.0)
        self.assertEqual(azimut,270.0)

        B = gpsPoint(10.1,9.9)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,15623.0)
        self.assertEqual(azimut,315.0)

        B = gpsPoint(10.1,10.0)
        distance, azimut = gpsMod.GPSData.getDirAndDist(A,B)
        self.assertEqual(distance,11132.0)
        self.assertEqual(azimut,0)


if __name__ == '__main__':
    unittest.main()

[((85, 4, 85, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((7, 18, 7, 35), 'Logger.Logger', 'Logger', ({(7, 25, 7, 34): '"""testLog"""'}, {}), "('testLog')", False, 'from Logger import Logger\n'), ((20, 8, 20, 31), 'os.remove', 'os.remove', ({(20, 18, 20, 30): 'testLog.name'}, {}), '(testLog.name)', False, 'import os\n'), ((23, 18, 23, 35), 'Logger.Logger', 'Logger', ({(23, 25, 23, 34): '"""testLog"""'}, {}), "('testLog')", False, 'from Logger import Logger\n'), ((34, 8, 34, 31), 'os.remove', 'os.remove', ({(34, 18, 34, 30): 'testLog.name'}, {}), '(testLog.name)', False, 'import os\n'), ((39, 17, 39, 28), 'gpsNavigation.gpsModule', 'gpsModule', ({}, {}), '()', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((41, 12, 41, 27), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(41, 21, 41, 23): '10', (41, 24, 41, 26): '10'}, {}), '(10, 10)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((42, 12, 42, 31), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(42, 21, 42, 25): '10.1', (42, 26, 42, 30): '10.1'}, {}), '(10.1, 10.1)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((48, 12, 48, 31), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(48, 21, 48, 25): '10.0', (48, 26, 48, 30): '10.1'}, {}), '(10.0, 10.1)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((53, 12, 53, 30), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(53, 21, 53, 24): '9.9', (53, 25, 53, 29): '10.1'}, {}), '(9.9, 10.1)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((58, 12, 58, 30), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(58, 21, 58, 24): '9.9', (58, 25, 58, 29): '10.0'}, {}), '(9.9, 10.0)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((63, 12, 63, 29), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(63, 21, 63, 24): '9.9', (63, 25, 63, 28): '9.9'}, {}), '(9.9, 9.9)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((68, 12, 68, 30), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(68, 21, 68, 25): '10.0', (68, 26, 68, 29): '9.9'}, {}), '(10.0, 9.9)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((73, 12, 73, 30), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(73, 21, 73, 25): '10.1', (73, 26, 73, 29): '9.9'}, {}), '(10.1, 9.9)', False, 'from gpsNavigation import gpsModule, gpsPoint\n'), ((78, 12, 78, 31), 'gpsNavigation.gpsPoint', 'gpsPoint', ({(78, 21, 78, 25): '10.1', (78, 26, 78, 30): '10.0'}, {}), '(10.1, 10.0)', False, 'from gpsNavigation import gpsModule, gpsPoint\n')]