Skip to content

Commit

Permalink
Merge pull request #11 from Apollo117/add_more_tests
Browse files Browse the repository at this point in the history
wrote tests for a number of functions starting with "B" and fixed errors...
  • Loading branch information
AndrewAnnex committed Jul 12, 2014
2 parents 0a1d081 + 9162960 commit f4b65e0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SpiceyPy/libspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# B
libspice.b1900_c.restype = ctypes.c_double
libspice.b1950_c.restype = ctypes.c_double
libspice.bodc2n_c.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
libspice.bodc2n_c.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
libspice.bodc2s_c.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_char_p]
libspice.boddef_c.argtypes = [ctypes.c_char_p, ctypes.c_int]
libspice.badkpv_c.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_char_p]
Expand Down
19 changes: 9 additions & 10 deletions SpiceyPy/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ def badkpv(caller, name, comp, insize, divby, intype):
insize = ctypes.c_int(insize)
divby = ctypes.c_int(divby)
intype = stypes.strtocharpoint(intype)
return libspice.badkpv(caller, name, comp, insize, divby, intype)
return libspice.badkpv_c(caller, name, comp, insize, divby, intype)


def bodc2n(code, lenout):
#todo: test bodc2n
code = ctypes.c_int(code)
name = stypes.strtocharpoint(" "*lenout)
lenout = ctypes.c_int(lenout)
found = ctypes.c_bool(0)
found = ctypes.c_bool()
libspice.bodc2n_c(code, lenout, name, ctypes.byref(found))
return stypes.toPythonString(name)
if found.value:
return stypes.toPythonString(name)
else:
return None


def bodc2s(code, lenout):
#todo: test bodc2s
code = ctypes.c_int(code)
name = stypes.strtocharpoint(" "*lenout)
lenout = ctypes.c_int(lenout)
Expand All @@ -95,7 +96,7 @@ def boddef(name, code):
def bodfnd(body, item):
body = ctypes.c_int(body)
item = stypes.strtocharpoint(item)
return libspice.bodfnd(body, item)
return libspice.bodfnd_c(body, item)


def bodn2c(name):
Expand All @@ -110,7 +111,6 @@ def bodn2c(name):


def bods2c(name):
#Todo: test bods2c
name = stypes.strtocharpoint(name)
code = ctypes.c_int(0)
found = ctypes.c_bool(0)
Expand All @@ -122,12 +122,11 @@ def bods2c(name):


def bodvar(body, item, dim):
#Todo: test bodvar
body = ctypes.c_int(body)
dim = ctypes.c_int(dim)
item = stypes.strtocharpoint(item)
values = stypes.doubleVector(dim.value)
libspice.bodvar(body, item, ctypes.byref(dim), values)
libspice.bodvar_c(body, item, ctypes.byref(dim), values)
return stypes.vectorToList(values)


Expand Down Expand Up @@ -173,7 +172,7 @@ def bschoc(value, ndim, lenvals, array, order):
lenvals = ctypes.c_int(lenvals)
array = stypes.listtocharvector(array)
order = stypes.toIntVector(order)
return libspice.bschoc(value, ndim, lenvals, ctypes.byref(array), ctypes.byref(order))
return libspice.bschoc_c(value, ndim, lenvals, ctypes.byref(array), ctypes.byref(order))


def bschoi(value, ndim, array, order):
Expand Down
57 changes: 47 additions & 10 deletions test/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def test_appndi():


def test_axisar():
assert 1
axis = np.array([0.0, 0.0, 1.0])
outmatrix = spice.axisar(axis, spice.halfpi())
expected = np.array(
[[0.0, -1.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 0.0, 1.0]]
)
np.testing.assert_array_almost_equal(expected, outmatrix, decimal = 6)


def test_b1900():
Expand All @@ -46,31 +53,50 @@ def test_badkpv():


def test_bodc2n():
assert 1
spice.furnsh(_testKernelPath)
assert spice.bodc2n(399, 10) == "EARTH"
assert spice.bodc2n(0, 40) == "SOLAR SYSTEM BARYCENTER"
spice.kclear()


def test_bodc2s():
assert 1
spice.furnsh(_testKernelPath)
assert spice.bodc2s(399, 10) == "EARTH"
assert spice.bodc2s(0, 40) == "SOLAR SYSTEM BARYCENTER"
spice.kclear()


def test_boddef():
assert 1
spice.boddef("Jebediah", 117)
assert spice.bodc2n(117, 10) == "Jebediah"


def test_bodfnd():
assert 1
spice.furnsh(_testKernelPath)
assert spice.bodfnd(599, "RADII")
spice.kclear()


def test_bodn2c():
assert 1
spice.furnsh(_testKernelPath)
assert spice.bodn2c("EARTH") == 399
assert spice.bodn2c("U.S.S. Enterprise") is None
spice.kclear()


def test_bods2c():
assert 1
spice.furnsh(_testKernelPath)
assert spice.bods2c("EARTH") == 399
assert spice.bods2c("U.S.S. Enterprise") is None
spice.kclear()


def test_bodvar():
assert 1
spice.furnsh(_testKernelPath)
radii = spice.bodvar(399, "RADII", 3)
expected = np.array([6378.140, 6378.140, 6356.755])
np.testing.assert_array_almost_equal(expected, radii, decimal = 1)
spice.kclear()


def test_bodvcd():
Expand Down Expand Up @@ -661,7 +687,7 @@ def test_eul2xf():


def test_exists():
assert 1
assert spice.exists(_testKernelPath)


def test_expool():
Expand Down Expand Up @@ -853,7 +879,18 @@ def test_inelpl():


def test_inrypl():
assert 1
spice.furnsh(_testKernelPath)
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]
point = [0.0, 0.0, 0.0]
plane = spice.nvp2pl(normal, point)
nxpts, xpt = spice.inrypl(vertex, dire, plane)
expectedXpt = np.array([180804.0, 47080.6050513, 0.0])
assert nxpts == 1
np.testing.assert_almost_equal(np.array(xpt), expectedXpt, decimal = 6)
spice.kclear()


def test_insrtc():
Expand Down

0 comments on commit f4b65e0

Please sign in to comment.