Skip to content

Commit

Permalink
wrote some more tests for functions starting with "B", fixed major is…
Browse files Browse the repository at this point in the history
…sues with BSCHOC and BODVAR
  • Loading branch information
AndrewAnnex committed Jul 12, 2014
1 parent f4b65e0 commit b05590b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
11 changes: 7 additions & 4 deletions SpiceyPy/libspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
libspice.bodfnd_c.restype = ctypes.c_bool
libspice.bodn2c_c.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_bool)]
libspice.bods2c_c.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_bool)]
libspice.bodvar_c.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), (ctypes.c_double * 3)] # last one is some vector.. work on this
libspice.bodvcd_c.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.c_double]
libspice.bodvrd_c.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int), (ctypes.c_double * 3)]
libspice.bodvar_c.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
libspice.bodvcd_c.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int),
ctypes.c_void_p]
libspice.bodvrd_c.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int),
ctypes.c_void_p]
libspice.brcktd_c.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_double]
libspice.brcktd_c.restype = ctypes.c_double
libspice.brckti_c.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
libspice.brckti_c.restype = ctypes.c_int
libspice.bschoc_c.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)]
libspice.bschoc_c.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_char_p,
ctypes.POINTER(ctypes.c_int)]
libspice.bschoc_c.restype = ctypes.c_int
libspice.bschoi_c.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
libspice.bschoi_c.restype = ctypes.c_int
Expand Down
23 changes: 10 additions & 13 deletions SpiceyPy/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,23 @@ def bodvar(body, item, dim):


def bodvcd(bodyid, item, maxn):
#todo: test bodvcd
bodyid = ctypes.c_int(bodyid)
item = stypes.strtocharpoint(item)
maxn = ctypes.c_int(maxn)
dim = ctypes.c_int(0)
dim = ctypes.c_int()
values = stypes.doubleVector(maxn)
maxn = ctypes.c_int(maxn)
libspice.bodvcd_c(bodyid, item, maxn, ctypes.byref(dim), values)
return stypes.vectorToList(values)
return dim.value, stypes.vectorToList(values)


def bodvrd(bodynm, item, maxn):
bodynm = stypes.strtocharpoint(bodynm)
item = stypes.strtocharpoint(item)
dim = ctypes.c_int()
values = stypes.doubleVector(maxn)
maxn = ctypes.c_int(maxn)
dim = ctypes.c_int(0)
values = stypes.doubleVector(3)
libspice.bodvrd_c(bodynm, item, maxn, ctypes.byref(dim), values)
return stypes.vectorToList(values)
return dim.value, stypes.vectorToList(values)


def brcktd(number, end1, end2):
Expand All @@ -166,22 +165,20 @@ def brckti(number, end1, end2):


def bschoc(value, ndim, lenvals, array, order):
#todo: Fix, probably not working
value = stypes.strtocharpoint(value)
ndim = ctypes.c_int(ndim)
lenvals = ctypes.c_int(lenvals)
array = stypes.listtocharvector(array)
array = stypes.listToCharArrayPtr(array, xLen = lenvals, yLen = ndim)
order = stypes.toIntVector(order)
return libspice.bschoc_c(value, ndim, lenvals, ctypes.byref(array), ctypes.byref(order))
return libspice.bschoc_c(value, ndim, lenvals, array, order)


def bschoi(value, ndim, array, order):
#todo: Fix, this is not working
value = ctypes.c_int(value)
ndim = ctypes.c_int(ndim)
order = stypes.toIntVector(order)
array = stypes.toIntVector(array)
return libspice.bschoi_c(value, ndim, ctypes.byref(order), ctypes.byref(array))
order = stypes.toIntVector(order)
return libspice.bschoi_c(value, ndim, array, order)


def bsrchc(value, ndim, lenvals, array):
Expand Down
61 changes: 51 additions & 10 deletions test/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,80 @@ def test_bodvar():


def test_bodvcd():
assert 1
spice.furnsh(_testKernelPath)
dim, values = spice.bodvcd(399, "RADII", 3)
assert dim == 3
expected = np.array([6378.140, 6378.140, 6356.755])
np.testing.assert_array_almost_equal(expected, values, decimal = 1)
spice.kclear()


def test_bodvrd():
assert 1
spice.furnsh(_testKernelPath)
dim, values = spice.bodvrd("EARTH", "RADII", 3)
assert dim == 3
expected = np.array([6378.140, 6378.140, 6356.755])
np.testing.assert_array_almost_equal(expected, values, decimal = 1)
spice.kclear()


def test_brcktd():
assert 1
assert spice.brcktd(-1.0, 1.0, 10.0) == 1.0
assert spice.brcktd(29.0, 1.0, 10.0) == 10.0
assert spice.brcktd(3.0, -10.0, 10.0) == 3.0
assert spice.brcktd(3.0, -10.0, -1.0) == -1.0


def test_brckti():
assert 1
assert spice.brckti(-1, 1, 10) == 1
assert spice.brckti(29, 1, 10) == 10
assert spice.brckti(3, -10, 10) == 3
assert spice.brckti(3, -10, -1) == -1


def test_bschoc():
assert 1
array = ["FEYNMAN", "BOHR", "EINSTEIN", "NEWTON", "GALILEO"]
order = [1, 2, 0, 4, 3]
lenvals = 10
assert spice.bschoc("NEWTON", 5, lenvals, array, order) == 3
assert spice.bschoc("EINSTEIN", 5, lenvals, array, order) == 2
assert spice.bschoc("GALILEO", 5, lenvals, array, order) == 4
assert spice.bschoc("Galileo", 5, lenvals, array, order) == -1
assert spice.bschoc("BETHE", 5, lenvals, array, order) == -1


def test_bschoi():
assert 1
array = [100, 1, 10, 10000, 1000]
order = [1, 2, 0, 4, 3]
assert spice.bschoi(1000, 5, array, order) == 4
assert spice.bschoi(1, 5, array, order) == 1
assert spice.bschoi(10000, 5, array, order) == 3
assert spice.bschoi(-1, 5, array, order) == -1
assert spice.bschoi(17, 5, array, order) == -1


def test_bsrchc():
assert 1
array = ["BOHR", "EINSTEIN", "FEYNMAN", "GALILEO", "NEWTON"]
lenvals = 10
assert spice.bsrchc("NEWTON", 5, lenvals, array) == 4
assert spice.bsrchc("EINSTEIN", 5, lenvals, array) == 1
assert spice.bsrchc("GALILEO", 5, lenvals, array) == 3
assert spice.bsrchc("Galileo", 5, lenvals, array) == -1
assert spice.bsrchc("BETHE", 5, lenvals, array) == -1


def test_bsrchd():
assert 1
array = np.array([-11.0, 0.0, 22.0, 750.0])
assert spice.bsrchd(-11.0, 4, array) == 0
assert spice.bsrchd(22.0, 4, array) == 2
assert spice.bsrchd(751.0, 4, array) == -1


def test_bsrchi():
assert 1
array = np.array([-11, 0, 22, 750])
assert spice.bsrchi(-11, 4, array) == 0
assert spice.bsrchi(22, 4, array) == 2
assert spice.bsrchi(751, 4, array) == -1


def test_card():
Expand Down Expand Up @@ -880,7 +921,7 @@ def test_inelpl():

def test_inrypl():
spice.furnsh(_testKernelPath)
radii = spice.bodvrd("SATURN", "RADII", 3)
dim, radii = spice.bodvrd("SATURN", "RADII", 3)
vertex = [3.0 * radii[0], 0.0, radii[2] * 0.5]
dire = [0.0, np.cos(30.0 * spice.rpd()), -1.0 * np.sin(30.0 * spice.rpd())]
normal = [0.0, 0.0, 1.0]
Expand Down

0 comments on commit b05590b

Please sign in to comment.