Skip to content

Commit

Permalink
python tests done for cassini and mga
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Sep 30, 2024
1 parent 52c3ea4 commit 61527ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pykep/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

import unittest as _ut
from .test_trajopt import mga_tests
from .test_trajopt import *

def float_abs_error(a: float, b: float):
return abs(a - b)
Expand Down Expand Up @@ -313,8 +313,9 @@ def run_test_suite():
suite.addTest(propagate_test("test_stark"))
suite.addTest(py_udplas_test("test_tle"))
suite.addTest(py_udplas_test("test_spice"))
suite.addTest(mga_tests("test_construction"))
suite.addTest(mga_tests("test_encoding_to_encoding"))
suite.addTest(trajopt_mga_tests("test_construction"))
suite.addTest(trajopt_mga_tests("test_encoding_to_encoding"))
suite.addTest(gym_cassini1_tests("test_fitness"))

suite.addTest(tl.loadTestsFromTestCase(vsop2013_test))

Expand Down
22 changes: 18 additions & 4 deletions pykep/test_trajopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@

import unittest as _ut

def float_abs_error(a: float, b: float):
return abs(a - b)

def float_rel_error(a: float, b: float):
return abs(a - b) / abs(a)

class mga_tests(_ut.TestCase):
class trajopt_mga_tests(_ut.TestCase):
def test_construction(self):
import pykep as pk
earth = pk.planet(pk.udpla.jpl_lp("earth"))
Expand Down Expand Up @@ -54,3 +51,20 @@ def test_encoding_to_encoding(self):
self.assertTrue(float_rel_error(gt, udp_eta.fitness(x_eta)[0]) < 1e-14)
self.assertTrue(float_rel_error(gt, udp_direct.fitness(udp_direct.alpha2direct(x_alpha))[0]) < 1e-14)
self.assertTrue(float_rel_error(gt, udp_direct.fitness(udp_eta.eta2direct(x_eta))[0]) < 1e-14)

class gym_cassini1_tests(_ut.TestCase):
def test_fitness(self):
import pykep as pk
udp = pk.trajopt.gym.cassini1
# Three random values. Ground truth provided by the old pykep code
x = [-554.5189290104555, 103.27184879471751, 335.41655259663474, 80.50258543604521, 862.0950563689543, 2865.018040480413 ]
f = udp.fitness(x)[0]
self.assertTrue(float_rel_error(f,80400.08897584089) < 1e-14)

x = [-932.0532394941108, 37.534681289972674, 162.5093144821548, 336.970139545233, 1743.2915882004586, 2527.8785180526465 ]
f = udp.fitness(x)[0]
self.assertTrue(float_rel_error(f,217105.87501757513) < 1e-14)

x = [-583.0776694390058, 388.65047998036107, 334.9959782156864, 65.57508619540917, 1520.2982946551908, 2132.7771932619144 ]
f = udp.fitness(x)[0]
self.assertTrue(float_rel_error(f,107218.0849582104) < 1e-14)

0 comments on commit 61527ff

Please sign in to comment.