Repository: SETI/rms-cspyce (language: python)

Issue:
`matchi` does not return a boolean
`cspyce.matchi` determines whether a string is matched by a template containing wild cards (case insensitive). Here are the inputs and returns:
```
    Inputs:
      string string = String to be tested.
      string templ  = Template (with wild cards) to test against string.
      string wstr   = Wild string token.
      string wchr   = Wild character token.
    
    Returns:
      bool   flag   = True if the string matches; False otherwise.
```

Regardless of the arguments, the function currently always returns None. It should be returning True or False. Here is the unit test:

```
import cspyce as cs
import os
import pytest

from gettestkernels import download_kernels


@pytest.fixture(autouse=True)
def clear_kernel_pool_and_reset():
    cs.kclear()
    cs.reset()
    # yield for test
    yield
    # clear kernel pool again
    cs.kclear()
    cs.reset()


def cleanup_kernel(path):
    cs.kclear()
    cs.reset()
    if os.path.isfile(path):
        os.remove(path)  # pragma: no cover
    pass


def setup_module(module):
    download_kernels()
    

string = "  ABCDEFGHIJKLMNOPQRSTUVWXYZ  "
wstr = "*"
wchr = "%"
assert cs.matchi(string, "*A*", wstr, wchr)
assert cs.matchi(string, "A%D*", wstr, wchr) is False
assert cs.matchi(string, "A%C*", wstr, wchr)
assert cs.matchi(string, "%A*", wstr, wchr) is False
assert cs.matchi(string, "%%CD*Z", wstr, wchr)
assert cs.matchi(string, "%%CD", wstr, wchr) is False
assert cs.matchi(string, "A*MN*Y*Z", wstr, wchr)
assert cs.matchi(string, "A*MN*Y*%Z", wstr, wchr) is False
assert cs.matchi(string, "*BCD*Z*", wstr, wchr)
assert cs.matchi(string, "*bdc*z*", wstr, wchr) is False
assert cs.matchi(string, " *bcD*Z*", wstr, wchr)
```


Discussion / hints:

Fix patch:
diff --git a/swig/cspyce0_part2.i b/swig/cspyce0_part2.i
index 6465b1fa..656bb6be 100644
--- a/swig/cspyce0_part2.i
+++ b/swig/cspyce0_part2.i
@@ -8383,7 +8383,7 @@ extern void lxqstr_c(
 %rename (matchi) matchi_c;
 %apply (SpiceBoolean RETURN_BOOLEAN) {SpiceBoolean matchi_c};
 
-extern void matchi_c(
+extern SpiceBoolean matchi_c(
         ConstSpiceChar *CONST_STRING,
         SpiceChar      *CONST_STRING,
         SpiceChar      IN_STRING,
@@ -8418,7 +8418,7 @@ extern void matchi_c(
 %rename (matchw) matchw_c;
 %apply (SpiceBoolean RETURN_BOOLEAN) {SpiceBoolean matchw_c};
 
-extern void matchw_c(
+extern SpiceBoolean matchw_c(
         ConstSpiceChar *CONST_STRING,
         ConstSpiceChar *CONST_STRING,
         SpiceChar      IN_STRING,


Test patch:
diff --git a/unittests/test_f_j.py b/unittests/test_f_j.py
index 1a4fd9b5..bb4098a4 100644
--- a/unittests/test_f_j.py
+++ b/unittests/test_f_j.py
@@ -244,26 +244,29 @@ def fail_getmsg():
     cs.reset()
 
 
-def fail_gfdist():
+def test_gfdist():
     cs.furnsh(CoreKernels.testMetaKernel)
     et0 = cs.str2et("2007 JAN 01 00:00:00 TDB")
     et1 = cs.str2et("2007 APR 01 00:00:00 TDB")
-    cnfine = cs.SpiceCell.create_spice_cell(1, size=2)
-    cs.wninsd(et0, et1, cnfine)
-    result = cs.SpiceCell.create_spice_cell(1, size=1000)
-    cs.gfdist(
-        "moon", "none", "earth", ">", 400000, 0.0, cs.spd(), 1000, cnfine, result
-    )
-    count = cs.wncard(result)
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=1000)
+    result = cs.gfdist(
+        "moon", "none", "earth", ">", 400000, 0.0, cs.spd(), 1000, cnfine)
+    count = int(len(result) / 2)
     assert count == 4
     temp_results = []
-    for i in range(0, count):
-        left, right = cs.wnfetd(result, i)
+    arr = np.arange(0, (len(result)), 1)
+    subarrays = [arr[i:i+2] for i in range(0, len(result), 2)]
+    for i in subarrays:
+        x = i[0]
+        y = i[1]
+        left, right = result[x], result[y]
         timstr_left = cs.timout(
-            left, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41
+            left, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND"
         )
         timstr_right = cs.timout(
-            right, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41
+            right, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND"
         )
         temp_results.append(timstr_left)
         temp_results.append(timstr_right)
@@ -343,560 +346,613 @@ def fail_gfdist():
 #     cs.gfsstp(0.5)
 # =============================================================================
 
-
-# =============================================================================
-# def fail_gffove():
-#     cs.furnsh(CoreKernels.testMetaKernel)
-#     cs.furnsh(CassiniKernels.cassCk)
-#     cs.furnsh(CassiniKernels.cassFk)
-#     cs.furnsh(CassiniKernels.cassIk)
-#     cs.furnsh(CassiniKernels.cassPck)
-#     cs.furnsh(CassiniKernels.cassSclk)
-#     cs.furnsh(CassiniKernels.cassTourSpk)
-#     cs.furnsh(CassiniKernels.satSpk)
-#     # Cassini ISS NAC observed Enceladus on 2013-FEB-25 from ~11:00 to ~12:00
-#     # Split confinement window, from continuous CK coverage, into two pieces
-#     et_start = cs.str2et("2013-FEB-25 10:00:00.000")
-#     et_end = cs.str2et("2013-FEB-25 11:45:00.000")
-#     cnfine = cs.SpiceCell.create_spice_cell(1, size=2)
-#     cs.wninsd(et_start, et_end, cnfine)
-#     result = cs.SpiceCell.create_spice_cell(1, size=1000)
-#     # call gffove
-#     udstep = spiceypy.utils.callbacks.SpiceUDSTEP(spice.gfstep)
-#     udrefn = spiceypy.utils.callbacks.SpiceUDREFN(spice.gfrefn)
-#     udrepi = spiceypy.utils.callbacks.SpiceUDREPI(spice.gfrepi)
-#     udrepu = spiceypy.utils.callbacks.SpiceUDREPU(spice.gfrepu)
-#     udrepf = spiceypy.utils.callbacks.SpiceUDREPF(spice.gfrepf)
-#     udbail = spiceypy.utils.callbacks.SpiceUDBAIL(spice.gfbail)
-#     cs.gfsstp(1.0)
-#     cs.gffove(
-#         "CASSINI_ISS_NAC",
-#         "ELLIPSOID",
-#         [0.0, 0.0, 0.0],
-#         "ENCELADUS",
-#         "IAU_ENCELADUS",
-#         "LT+S",
-#         "CASSINI",
-#         1.0e-6,
-#         udstep,
-#         udrefn,
-#         True,
-#         udrepi,
-#         udrepu,
-#         udrepf,
-#         True,
-#         udbail,
-#         cnfine,
-#         result,
-#     )
-#     # Verify the expected results
-#     assert len(result) == 2
-#     sTimout = "YYYY-MON-DD HR:MN:SC UTC ::RND"
-#     assert cs.timout(result[0], sTimout) == "2013-FEB-25 10:42:33 UTC"
-#     assert cs.timout(result[1], sTimout) == "2013-FEB-25 11:45:00 UTC"
-#     # Cleanup
-#     if cs.gfbail():
-#         cs.gfclrh()  # pragma: no cover
-#     cs.gfsstp(0.5)
-# =============================================================================
-
-
-# =============================================================================
-# def test_gfilum():
-#     cs.furnsh(CoreKernels.testMetaKernel)
-#     cs.furnsh(ExtraKernels.marsSpk)  # to get Phobos ephemeris
-#     # Hard-code the future position of MER-1
-#     # pos, lt = cs.spkpos("MER-1", cs.str2et("2006 OCT 02 00:00:00 UTC"), "iau_mars", "CN+S", "Mars")
-#     pos = [
-#         3376.17890941875839416753,
-#         -325.55203839445334779157,
-#         -121.47422900638389364758,
-#     ]
-#     # Two-month Viking orbiter window for Phobos;
-#     # - marsSPK runs from [1971 OCT 01] to [1972 OCT 01]
-#     startET = cs.str2et("1971 OCT 02 00:00:00 UTC")
-#     endET = cs.str2et("1971 NOV 30 12:00:00 UTC")
-#     # Create confining and result windows for incidence angle GF check
-#     cnfine = cs.SpiceCell.create_spice_cell(1, size=2000)
-#     cs.wninsd(startET, endET, cnfine)
-#     wnsolr = cs.SpiceCell.create_spice_cell(1, size=2000)
-#     # Find windows where solar incidence angle at MER-1 position is < 60deg
-#     cs.gfilum(
-#         "Ellipsoid",
-#         "INCIDENCE",
-#         "Mars",
-#         "Sun",
-#         "iau_mars",
-#         "CN+S",
-#         "PHOBOS",
-#         pos,
-#         "<",
-#         60.0 * cs.rpd(),
-#         0.0,
-#         21600.0,
-#         1000,
-#         cnfine,
-#         wnsolr,
-#     )
-#     # Create result window for emission angle GF check
-#     result = cs.SpiceCell.create_spice_cell(1, size=2000)
-#     # Find windows, within solar incidence angle windows found above (wnsolar),
-#     # where emission angle from MER-1 position to Phobos is < 20deg
-#     cs.gfilum(
-#         "Ellipsoid",
-#         "EMISSION",
-#         "Mars",
-#         "Sun",
-#         "iau_mars",
-#         "CN+S",
-#         "PHOBOS",
-#         pos,
-#         "<",
-#         20.0 * cs.rpd(),
-#         0.0,
-#         900.0,
-#         1000,
-#         wnsolr,
-#         result,
-#     )
-#     # Ensure there were some results
-#     assert cs.wncard(result) > 0
-#     startEpoch = cs.timout(result[0], "YYYY MON DD HR:MN:SC.###### UTC")
-#     endEpoch = cs.timout(result[-1], "YYYY MON DD HR:MN:SC.###### UTC")
-#     # Check times of results
-#     assert startEpoch.startswith("1971 OCT 02")
-#     assert endEpoch.startswith("1971 NOV 29")
-# =============================================================================
+# Resulting in seg fault
+def fail_gffove():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cs.furnsh(CassiniKernels.cassCk)
+    cs.furnsh(CassiniKernels.cassFk)
+    cs.furnsh(CassiniKernels.cassIk)
+    cs.furnsh(CassiniKernels.cassPck)
+    cs.furnsh(CassiniKernels.cassSclk)
+    cs.furnsh(CassiniKernels.cassTourSpk)
+    cs.furnsh(CassiniKernels.satSpk)
+    # Cassini ISS NAC observed Enceladus on 2013-FEB-25 from ~11:00 to ~12:00
+    # Split confinement window, from continuous CK coverage, into two pieces
+    et_start = cs.str2et("2013-FEB-25 10:00:00.000")
+    et_end = cs.str2et("2013-FEB-25 11:45:00.000")
+    step = (et_end - et_start) / 1.0
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et_start, et_end, cnfine)
+    result = cs.SpiceCell(typeno=1, size=1000)
+
+    # call gffove
+    result = cs.gffove(
+        "CASSINI_ISS_NAC",
+        "ELLIPSOID",
+        [0.0, 0.0, 0.0],
+        "ENCELADUS",
+        "IAU_ENCELADUS",
+        "LT+S",
+        "CASSINI",
+        1.0e-6,
+        step,
+        True,
+        cnfine
+    )
+    # Verify the expected results
+    assert len(result) == 2
+    sTimout = "YYYY-MON-DD HR:MN:SC UTC ::RND"
+    assert cs.timout(result[0], sTimout) == "2013-FEB-25 10:42:33 UTC"
+    assert cs.timout(result[1], sTimout) == "2013-FEB-25 11:45:00 UTC"
+    # Cleanup
+    if cs.gfbail():
+        cs.gfclrh()  # pragma: no cover
 
 
-# =============================================================================
-# def fail_gfocce():
-#     if cs.gfbail():
-#         cs.gfclrh()  # pragma: no cover
-#     cs.furnsh(CoreKernels.testMetaKernel)
-#     et0 = cs.str2et("2001 DEC 01 00:00:00 TDB")
-#     et1 = cs.str2et("2002 JAN 01 00:00:00 TDB")
-#     cnfine = cs.SpiceCell.create_spice_cell(1, size=2)
-#     cs.wninsd(et0, et1, cnfine)
-#     result = cs.SpiceCell.create_spice_cell(1, size=1000)
-#     cs.gfsstp(20.0)
-#     udstep = spiceypy.utils.callbacks.SpiceUDSTEP(spice.gfstep)
-#     udrefn = spiceypy.utils.callbacks.SpiceUDREFN(spice.gfrefn)
-#     udrepi = spiceypy.utils.callbacks.SpiceUDREPI(spice.gfrepi)
-#     udrepu = spiceypy.utils.callbacks.SpiceUDREPU(spice.gfrepu)
-#     udrepf = spiceypy.utils.callbacks.SpiceUDREPF(spice.gfrepf)
-#     udbail = spiceypy.utils.callbacks.SpiceUDBAIL(spice.gfbail)
-#     # call gfocce
-#     cs.gfocce(
-#         "Any",
-#         "moon",
-#         "ellipsoid",
-#         "iau_moon",
-#         "sun",
-#         "ellipsoid",
-#         "iau_sun",
-#         "lt",
-#         "earth",
-#         1.0e-6,
-#         udstep,
-#         udrefn,
-#         True,
-#         udrepi,
-#         udrepu,
-#         udrepf,
-#         True,
-#         udbail,
-#         cnfine,
-#         result,
-#     )
-#     if cs.gfbail():
-#         cs.gfclrh()  # pragma: no cover
-#     count = cs.wncard(result)
-#     assert count == 1
-# =============================================================================
+def test_gfilum():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cs.furnsh(ExtraKernels.marsSpk)  # to get Phobos ephemeris
+    # Hard-code the future position of MER-1
+    # pos, lt = cs.spkpos("MER-1", cs.str2et("2006 OCT 02 00:00:00 UTC"), "iau_mars", "CN+S", "Mars")
+    pos = [
+        3376.17890941875839416753,
+        -325.55203839445334779157,
+        -121.47422900638389364758,
+    ]
+    # Two-month Viking orbiter window for Phobos;
+    # - marsSPK runs from [1971 OCT 01] to [1972 OCT 01]
+    startET = cs.str2et("1971 OCT 02 00:00:00 UTC")
+    endET = cs.str2et("1971 NOV 30 12:00:00 UTC")
+    # Create confining and result windows for incidence angle GF check
+    cnfine = cs.SpiceCell(typeno=1, size=2000)
+    cs.wninsd(startET, endET, cnfine)
+    wnsolr = cs.SpiceCell(typeno=1, size=2000)
+    # Find windows where solar incidence angle at MER-1 position is < 60deg
+    wnsolr = cs.gfilum(
+        "Ellipsoid",
+        "INCIDENCE",
+        "Mars",
+        "Sun",
+        "iau_mars",
+        "CN+S",
+        "PHOBOS",
+        pos,
+        "<",
+        60.0 * cs.rpd(),
+        0.0,
+        21600.0,
+        1000,
+        cnfine
+    )
+    # Create result window for emission angle GF check
+    result = cs.SpiceCell(typeno=1, size=2000)
+    # Find windows, within solar incidence angle windows found above (wnsolar),
+    # where emission angle from MER-1 position to Phobos is < 20deg
+    result = cs.gfilum(
+        "Ellipsoid",
+        "EMISSION",
+        "Mars",
+        "Sun",
+        "iau_mars",
+        "CN+S",
+        "PHOBOS",
+        pos,
+        "<",
+        20.0 * cs.rpd(),
+        0.0,
+        900.0,
+        1000,
+        wnsolr
+    )
+    # Ensure there were some results
+    assert len(result) > 0
+    startEpoch = cs.timout(result[0], "YYYY MON DD HR:MN:SC.###### UTC")
+    endEpoch = cs.timout(result[-1], "YYYY MON DD HR:MN:SC.###### UTC")
+    # Check times of results
+    assert startEpoch.startswith("1971 OCT 02")
+    assert endEpoch.startswith("1971 NOV 29")
 
 
-# =============================================================================
-# def test_gfocce():
-#     if spice.gfbail():
-#         spice.gfclrh()  # pragma: no cover
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     et0 = spice.str2et("2001 DEC 01 00:00:00 TDB")
-#     et1 = spice.str2et("2002 JAN 01 00:00:00 TDB")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     result = spice.cell_double(1000)
-#     spice.gfsstp(20.0)
-#     udstep = spiceypy.utils.callbacks.SpiceUDSTEP(spice.gfstep)
-#     udrefn = spiceypy.utils.callbacks.SpiceUDREFN(spice.gfrefn)
-#     udrepi = spiceypy.utils.callbacks.SpiceUDREPI(spice.gfrepi)
-#     udrepu = spiceypy.utils.callbacks.SpiceUDREPU(spice.gfrepu)
-#     udrepf = spiceypy.utils.callbacks.SpiceUDREPF(spice.gfrepf)
-#     udbail = spiceypy.utils.callbacks.SpiceUDBAIL(spice.gfbail)
-#     # call gfocce
-#     spice.gfocce(
-#         "Any",
-#         "moon",
-#         "ellipsoid",
-#         "iau_moon",
-#         "sun",
-#         "ellipsoid",
-#         "iau_sun",
-#         "lt",
-#         "earth",
-#         1.0e-6,
-#         udstep,
-#         udrefn,
-#         True,
-#         udrepi,
-#         udrepu,
-#         udrepf,
-#         True,
-#         udbail,
-#         cnfine,
-#         result,
-#     )
-#     if spice.gfbail():
-#         spice.gfclrh()  # pragma: no cover
-#     count = spice.wncard(result)
-#     assert count == 1
-# =============================================================================
-
+def fail_gfocce():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2001 DEC 01 00:00:00 TDB")
+    et1 = cs.str2et("2002 JAN 01 00:00:00 TDB")
+    cnfine = cs.SpiceCell.create_spice_cell(1, size=2)
+    cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell.create_spice_cell(1, size=1000)
+    step = (et1 - et0) / 20.0
+    # call gfocce
+    cs.gfocce(
+        "Any",
+        "moon",
+        "ellipsoid",
+        "iau_moon",
+        "sun",
+        "ellipsoid",
+        "iau_sun",
+        "lt",
+        "earth",
+        1.0e-6,
+        step,
+        True,
+        cnfine
+    )
+    if cs.gfbail():
+        cs.gfclrh()  # pragma: no cover
+    count = cs.wncard(result)
+    assert count == 1
 
-# =============================================================================
-# def test_gfoclt():
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     et0 = spice.str2et("2001 DEC 01 00:00:00 TDB")
-#     et1 = spice.str2et("2002 JAN 01 00:00:00 TDB")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     result = spice.cell_double(1000)
-#     spice.gfoclt(
-#         "any",
-#         "moon",
-#         "ellipsoid",
-#         "iau_moon",
-#         "sun",
-#         "ellipsoid",
-#         "iau_sun",
-#         "lt",
-#         "earth",
-#         180.0,
-#         cnfine,
-#         result,
-#     )
-#     count = spice.wncard(result)
-#     assert count == 1
-#     start, end = spice.wnfetd(result, 0)
-#     start_time = spice.timout(
-#         start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41
-#     )
-#     end_time = spice.timout(end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41)
-#     assert start_time == "2001-DEC-14 20:10:14.203347 (TDB)"
-#     assert end_time == "2001-DEC-14 21:35:50.328804 (TDB)"
-# =============================================================================
 
-# =============================================================================
-# def test_gfpa():
-#     relate = ["=", "<", ">", "LOCMIN", "ABSMIN", "LOCMAX", "ABSMAX"]
-#     expected = {
-#         "=": [
-#             "2006-DEC-02 13:31:34.425",
-#             "2006-DEC-02 13:31:34.425",
-#             "2006-DEC-07 14:07:55.480",
-#             "2006-DEC-07 14:07:55.480",
-#             "2007-JAN-01 00:00:00.007",
-#             "2007-JAN-01 00:00:00.007",
-#             "2007-JAN-06 08:16:25.522",
-#             "2007-JAN-06 08:16:25.522",
-#             "2007-JAN-30 11:41:32.568",
-#             "2007-JAN-30 11:41:32.568",
-#         ],
-#         "<": [
-#             "2006-DEC-02 13:31:34.425",
-#             "2006-DEC-07 14:07:55.480",
-#             "2007-JAN-01 00:00:00.007",
-#             "2007-JAN-06 08:16:25.522",
-#             "2007-JAN-30 11:41:32.568",
-#             "2007-JAN-31 00:00:00.000",
-#         ],
-#         ">": [
-#             "2006-DEC-01 00:00:00.000",
-#             "2006-DEC-02 13:31:34.425",
-#             "2006-DEC-07 14:07:55.480",
-#             "2007-JAN-01 00:00:00.007",
-#             "2007-JAN-06 08:16:25.522",
-#             "2007-JAN-30 11:41:32.568",
-#         ],
-#         "LOCMIN": [
-#             "2006-DEC-05 00:16:50.327",
-#             "2006-DEC-05 00:16:50.327",
-#             "2007-JAN-03 14:18:31.987",
-#             "2007-JAN-03 14:18:31.987",
-#         ],
-#         "ABSMIN": ["2007-JAN-03 14:18:31.987", "2007-JAN-03 14:18:31.987"],
-#         "LOCMAX": [
-#             "2006-DEC-20 14:09:10.402",
-#             "2006-DEC-20 14:09:10.402",
-#             "2007-JAN-19 04:27:54.610",
-#             "2007-JAN-19 04:27:54.610",
-#         ],
-#         "ABSMAX": ["2007-JAN-19 04:27:54.610", "2007-JAN-19 04:27:54.610"],
-#     }
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     et0 = spice.str2et("2006 DEC 01")
-#     et1 = spice.str2et("2007 JAN 31")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     result = spice.cell_double(2000)
-#     for relation in relate:
-#         spice.gfpa(
-#             "Moon",
-#             "Sun",
-#             "LT+S",
-#             "Earth",
-#             relation,
-#             0.57598845,
-#             0.0,
-#             spice.spd(),
-#             5000,
-#             cnfine,
-#             result,
-#         )
-#         count = spice.wncard(result)
-#         if count > 0:
-#             temp_results = []
-#             for i in range(0, count):
-#                 left, right = spice.wnfetd(result, i)
-#                 timstr_left = spice.timout(left, "YYYY-MON-DD HR:MN:SC.###", 41)
-#                 timstr_right = spice.timout(right, "YYYY-MON-DD HR:MN:SC.###", 41)
-#                 temp_results.append(timstr_left)
-#                 temp_results.append(timstr_right)
-#             assert temp_results == expected.get(relation)
-# =============================================================================
+def test_gfoclt():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2001 DEC 01 00:00:00 TDB")
+    et1 = cs.str2et("2002 JAN 01 00:00:00 TDB")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=1000)
+    result = cs.gfoclt(
+        "any",
+        "moon",
+        "ellipsoid",
+        "iau_moon",
+        "sun",
+        "ellipsoid",
+        "iau_sun",
+        "lt",
+        "earth",
+        180.0,
+        cnfine,
+    )
+    count = len(result) / 2
+    assert count == 1
+    start, end = result[0], result[1]
+    start_time = cs.timout(
+        start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND"
+    )
+    end_time = cs.timout(
+        end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    assert start_time == "2001-DEC-14 20:10:14.203347 (TDB)"
+    assert end_time == "2001-DEC-14 21:35:50.328804 (TDB)"
+
+
+def test_gfpa():
+    relate = ["=", "<", ">", "LOCMIN", "ABSMIN", "LOCMAX", "ABSMAX"]
+    expected = {
+        "=": [
+            "2006-DEC-02 13:31:34.425",
+            "2006-DEC-02 13:31:34.425",
+            "2006-DEC-07 14:07:55.480",
+            "2006-DEC-07 14:07:55.480",
+            "2007-JAN-01 00:00:00.007",
+            "2007-JAN-01 00:00:00.007",
+            "2007-JAN-06 08:16:25.522",
+            "2007-JAN-06 08:16:25.522",
+            "2007-JAN-30 11:41:32.568",
+            "2007-JAN-30 11:41:32.568",
+        ],
+        "<": [
+            "2006-DEC-02 13:31:34.425",
+            "2006-DEC-07 14:07:55.480",
+            "2007-JAN-01 00:00:00.007",
+            "2007-JAN-06 08:16:25.522",
+            "2007-JAN-30 11:41:32.568",
+            "2007-JAN-31 00:00:00.000",
+        ],
+        ">": [
+            "2006-DEC-01 00:00:00.000",
+            "2006-DEC-02 13:31:34.425",
+            "2006-DEC-07 14:07:55.480",
+            "2007-JAN-01 00:00:00.007",
+            "2007-JAN-06 08:16:25.522",
+            "2007-JAN-30 11:41:32.568",
+        ],
+        "LOCMIN": [
+            "2006-DEC-05 00:16:50.327",
+            "2006-DEC-05 00:16:50.327",
+            "2007-JAN-03 14:18:31.987",
+            "2007-JAN-03 14:18:31.987",
+        ],
+        "ABSMIN": ["2007-JAN-03 14:18:31.987", "2007-JAN-03 14:18:31.987"],
+        "LOCMAX": [
+            "2006-DEC-20 14:09:10.402",
+            "2006-DEC-20 14:09:10.402",
+            "2007-JAN-19 04:27:54.610",
+            "2007-JAN-19 04:27:54.610",
+        ],
+        "ABSMAX": ["2007-JAN-19 04:27:54.610", "2007-JAN-19 04:27:54.610"],
+    }
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2006 DEC 01")
+    et1 = cs.str2et("2007 JAN 31")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=2000)
+    for relation in relate:
+        cs.gfpa(
+            "Moon",
+            "Sun",
+            "LT+S",
+            "Earth",
+            relation,
+            0.57598845,
+            0.0,
+            cs.spd(),
+            5000,
+            cnfine
+        )
+        count = len(result) / 2
+        if count > 0:
+            temp_results = []
+            arr = np.arange(0, (len(result)), 1)
+            subarrays = [arr[i:i+2] for i in range(0, len(result), 2)]
+            for i in subarrays:
+                x = i[0]
+                y = i[1]
+                left, right = result[x], result[y]
+                timstr_left = cs.timout(left, "YYYY-MON-DD HR:MN:SC.###")
+                timstr_right = cs.timout(right, "YYYY-MON-DD HR:MN:SC.###")
+                temp_results.append(timstr_left)
+                temp_results.append(timstr_right)
+            assert temp_results == expected.get(relation)
+
+
+def test_gfposc():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2007 JAN 01")
+    et1 = cs.str2et("2008 JAN 01")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=1000)
+    result = cs.gfposc(
+        "sun",
+        "iau_earth",
+        "none",
+        "earth",
+        "latitudinal",
+        "latitude",
+        "absmax",
+        0.0,
+        0.0,
+        90.0 * cs.spd(),
+        1000,
+        cnfine
+    )
+    count = len(result) / 2
+    assert count == 1
+    start, end = result[0], result[1]
+    start_time = cs.timout(
+        start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND"
+    )
+    end_time = cs.timout(end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    assert start_time == end_time
+    assert start_time == "2007-JUN-21 17:54:13.201561 (TDB)"
 
 
-# =============================================================================
-# def test_gfposc():
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     et0 = spice.str2et("2007 JAN 01")
-#     et1 = spice.str2et("2008 JAN 01")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     result = spice.cell_double(1000)
-#     spice.gfposc(
-#         "sun",
-#         "iau_earth",
-#         "none",
-#         "earth",
-#         "latitudinal",
-#         "latitude",
-#         "absmax",
-#         0.0,
-#         0.0,
-#         90.0 * spice.spd(),
-#         1000,
-#         cnfine,
-#         result,
-#     )
-#     count = spice.wncard(result)
-#     assert count == 1
-#     start, end = spice.wnfetd(result, 0)
-#     start_time = spice.timout(
-#         start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41
-#     )
-#     end_time = spice.timout(end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41)
-#     assert start_time == end_time
-#     assert start_time == "2007-JUN-21 17:54:13.201561 (TDB)"
-# =============================================================================
+def test_gfrfov():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cs.furnsh(CassiniKernels.cassCk)
+    cs.furnsh(CassiniKernels.cassFk)
+    cs.furnsh(CassiniKernels.cassIk)
+    cs.furnsh(CassiniKernels.cassPck)
+    cs.furnsh(CassiniKernels.cassSclk)
+    cs.furnsh(CassiniKernels.cassTourSpk)
+    cs.furnsh(CassiniKernels.satSpk)
+    # Changed ABCORR to NONE from S for this test, so we do not need SSB
+    # begin test
+    inst = "CASSINI_ISS_WAC"
+    # Cassini ISS NAC observed Enceladus on 2013-FEB-25 from ~11:00 to ~12:00
+    # Split confinement window, from continuous CK coverage, into two pieces
+    et_start1 = cs.str2et("2013-FEB-25 07:20:00.000")
+    et_end1 = cs.str2et("2013-FEB-25 11:45:00.000")  # \
+    et_start2 = cs.str2et("2013-FEB-25 11:55:00.000")  # _>synthetic 10min gap
+    et_end2 = cs.str2et("2013-FEB-26 14:25:00.000")
+    cnfine = cs.SpiceCell(typeno=1, size=4)
+    cnfine = cs.wninsd(et_start1, et_end1, cnfine)
+    cnfine = cs.wninsd(et_start2, et_end2, cnfine)
+    # The ray direction vector is from Cassini toward Enceladus during the gap
+    et_nom = cs.str2et("2013-FEB-25 11:50:00.000")  # \
+    raydir, lt = cs.spkpos("Enceladus", et_nom, "J2000", "NONE", "Cassini")
+    result = cs.SpiceCell(typeno=1, size=2000)
+    result = cs.gfrfov(inst, raydir, "J2000", "NONE", "Cassini", 10.0, cnfine)
+    # Verify the expected results
+    assert len(result) == 4
+    sTimout = "YYYY-MON-DD HR:MN:SC UTC ::RND"
+    assert cs.timout(result[0], sTimout) == "2013-FEB-25 11:26:46 UTC"
+    assert cs.timout(result[1], sTimout) == "2013-FEB-25 11:45:00 UTC"
+    assert cs.timout(result[2], sTimout) == "2013-FEB-25 11:55:00 UTC"
+    assert cs.timout(result[3], sTimout) == "2013-FEB-25 12:05:33 UTC"
+
+
+def test_gfrr():
+    relate = ["=", "<", ">", "LOCMIN", "ABSMIN", "LOCMAX", "ABSMAX"]
+    expected = {
+        "=": [
+            "2007-JAN-02 00:35:19.583",
+            "2007-JAN-02 00:35:19.583",
+            "2007-JAN-19 22:04:54.905",
+            "2007-JAN-19 22:04:54.905",
+            "2007-FEB-01 23:30:13.439",
+            "2007-FEB-01 23:30:13.439",
+            "2007-FEB-17 11:10:46.547",
+            "2007-FEB-17 11:10:46.547",
+            "2007-MAR-04 15:50:19.940",
+            "2007-MAR-04 15:50:19.940",
+            "2007-MAR-18 09:59:05.966",
+            "2007-MAR-18 09:59:05.966",
+        ],
+        "<": [
+            "2007-JAN-02 00:35:19.583",
+            "2007-JAN-19 22:04:54.905",
+            "2007-FEB-01 23:30:13.439",
+            "2007-FEB-17 11:10:46.547",
+            "2007-MAR-04 15:50:19.940",
+            "2007-MAR-18 09:59:05.966",
+        ],
+        ">": [
+            "2007-JAN-01 00:00:00.000",
+            "2007-JAN-02 00:35:19.583",
+            "2007-JAN-19 22:04:54.905",
+            "2007-FEB-01 23:30:13.439",
+            "2007-FEB-17 11:10:46.547",
+            "2007-MAR-04 15:50:19.940",
+            "2007-MAR-18 09:59:05.966",
+            "2007-APR-01 00:00:00.000",
+        ],
+        "LOCMIN": [
+            "2007-JAN-11 07:03:59.001",
+            "2007-JAN-11 07:03:59.001",
+            "2007-FEB-10 06:26:15.451",
+            "2007-FEB-10 06:26:15.451",
+            "2007-MAR-12 03:28:36.414",
+            "2007-MAR-12 03:28:36.414",
+        ],
+        "ABSMIN": ["2007-JAN-11 07:03:59.001", "2007-JAN-11 07:03:59.001"],
+        "LOCMAX": [
+            "2007-JAN-26 02:27:33.772",
+            "2007-JAN-26 02:27:33.772",
+            "2007-FEB-24 09:35:07.822",
+            "2007-FEB-24 09:35:07.822",
+            "2007-MAR-25 17:26:56.158",
+            "2007-MAR-25 17:26:56.158",
+        ],
+        "ABSMAX": ["2007-MAR-25 17:26:56.158", "2007-MAR-25 17:26:56.158"],
+    }
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2007 JAN 01")
+    et1 = cs.str2et("2007 APR 01")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cs.wninsd(et0, et1, cnfine)
+    for relation in relate:
+        result = cs.SpiceCell(typeno=1, size=2000)
+        cs.gfrr(
+            "moon",
+            "none",
+            "sun",
+            relation,
+            0.3365,
+            0.0,
+            cs.spd(),
+            2000,
+            cnfine
+        )
+        count = len(result) / 2
+        if count > 0:
+            temp_results = []
+            arr = np.arange(0, (len(result)), 1)
+            subarrays = [arr[i:i+2] for i in range(0, len(result), 2)]
+            for i in subarrays:
+                x = i[0]
+                y = i[1]
+                left, right = result[x], result[y]
+                timstr_left = cs.timout(left, "YYYY-MON-DD HR:MN:SC.###")
+                timstr_right = cs.timout(right, "YYYY-MON-DD HR:MN:SC.###")
+                temp_results.append(timstr_left)
+                temp_results.append(timstr_right)
+            assert temp_results == expected.get(relation)
+
+
+def test_gfsep():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    expected = [
+        "2007-JAN-03 14:20:24.628017 (TDB)",
+        "2007-FEB-02 06:16:24.111794 (TDB)",
+        "2007-MAR-03 23:22:42.005064 (TDB)",
+        "2007-APR-02 16:49:16.145506 (TDB)",
+        "2007-MAY-02 09:41:43.840096 (TDB)",
+        "2007-JUN-01 01:03:44.537483 (TDB)",
+        "2007-JUN-30 14:15:26.586223 (TDB)",
+        "2007-JUL-30 01:14:49.010797 (TDB)",
+        "2007-AUG-28 10:39:01.398087 (TDB)",
+        "2007-SEP-26 19:25:51.519413 (TDB)",
+        "2007-OCT-26 04:30:56.635336 (TDB)",
+        "2007-NOV-24 14:31:04.341632 (TDB)",
+        "2007-DEC-24 01:40:12.245932 (TDB)",
+    ]
+    et0 = cs.str2et("2007 JAN 01")
+    et1 = cs.str2et("2008 JAN 01")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=2000)
+    result = cs.gfsep(
+        "MOON",
+        "SPHERE",
+        "NULL",
+        "SUN",
+        "SPHERE",
+        "NULL",
+        "NONE",
+        "EARTH",
+        "LOCMAX",
+        0.0,
+        0.0,
+        6.0 * cs.spd(),
+        1000,
+        cnfine
+    )
+    count = len(result) / 2
+    assert count == 13
+    temp_results = []
+    arr = np.arange(0, (len(result)), 1)
+    subarrays = [arr[i:i+2] for i in range(0, len(result), 2)]
+    for i in subarrays:
+        x = i[0]
+        y = i[1]
+        start, end = result[x], result[y]
+        assert start == end
+        temp_results.append(
+            cs.timout(start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+        )
+    assert temp_results == expected
 
 
-# =============================================================================
-# def test_gfrfov():
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     spice.furnsh(CassiniKernels.cassCk)
-#     spice.furnsh(CassiniKernels.cassFk)
-#     spice.furnsh(CassiniKernels.cassIk)
-#     spice.furnsh(CassiniKernels.cassPck)
-#     spice.furnsh(CassiniKernels.cassSclk)
-#     spice.furnsh(CassiniKernels.cassTourSpk)
-#     spice.furnsh(CassiniKernels.satSpk)
-#     # Changed ABCORR to NONE from S for this test, so we do not need SSB
-#     # begin test
-#     inst = "CASSINI_ISS_WAC"
-#     # Cassini ISS NAC observed Enceladus on 2013-FEB-25 from ~11:00 to ~12:00
-#     # Split confinement window, from continuous CK coverage, into two pieces
-#     et_start1 = spice.str2et("2013-FEB-25 07:20:00.000")
-#     et_end1 = spice.str2et("2013-FEB-25 11:45:00.000")  # \
-#     et_start2 = spice.str2et("2013-FEB-25 11:55:00.000")  # _>synthetic 10min gap
-#     et_end2 = spice.str2et("2013-FEB-26 14:25:00.000")
-#     cnfine = spice.cell_double(4)
-#     spice.wninsd(et_start1, et_end1, cnfine)
-#     spice.wninsd(et_start2, et_end2, cnfine)
-#     # The ray direction vector is from Cassini toward Enceladus during the gap
-#     et_nom = spice.str2et("2013-FEB-25 11:50:00.000")  # \
-#     raydir, lt = spice.spkpos("Enceladus", et_nom, "J2000", "NONE", "Cassini")
-#     result = spice.cell_double(2000)
-#     spice.gfrfov(inst, raydir, "J2000", "NONE", "Cassini", 10.0, cnfine, result)
-#     # Verify the expected results
-#     assert len(result) == 4
-#     sTimout = "YYYY-MON-DD HR:MN:SC UTC ::RND"
-#     assert spice.timout(result[0], sTimout) == "2013-FEB-25 11:26:46 UTC"
-#     assert spice.timout(result[1], sTimout) == "2013-FEB-25 11:45:00 UTC"
-#     assert spice.timout(result[2], sTimout) == "2013-FEB-25 11:55:00 UTC"
-#     assert spice.timout(result[3], sTimout) == "2013-FEB-25 12:05:33 UTC"
-# =============================================================================
+def test_gfsntc():
+    kernel = os.path.join(TEST_FILE_DIR, "gfnstc_test.tf")
+    cleanup_kernel(kernel)
+    with open(kernel, "w") as kernelFile:
+        kernelFile.write("\\begindata\n")
+        kernelFile.write("FRAME_SEM                     =  10100000\n")
+        kernelFile.write("FRAME_10100000_NAME           = 'SEM'\n")
+        kernelFile.write("FRAME_10100000_CLASS          =  5\n")
+        kernelFile.write("FRAME_10100000_CLASS_ID       =  10100000\n")
+        kernelFile.write("FRAME_10100000_CENTER         =  10\n")
+        kernelFile.write("FRAME_10100000_RELATIVE       = 'J2000'\n")
+        kernelFile.write("FRAME_10100000_DEF_STYLE      = 'PARAMETERIZED'\n")
+        kernelFile.write("FRAME_10100000_FAMILY         = 'TWO-VECTOR'\n")
+        kernelFile.write("FRAME_10100000_PRI_AXIS       = 'X'\n")
+        kernelFile.write(
+            "FRAME_10100000_PRI_VECTOR_DEF = 'OBSERVER_TARGET_POSITION'\n")
+        kernelFile.write("FRAME_10100000_PRI_OBSERVER   = 'SUN'\n")
+        kernelFile.write("FRAME_10100000_PRI_TARGET     = 'EARTH'\n")
+        kernelFile.write("FRAME_10100000_PRI_ABCORR     = 'NONE'\n")
+        kernelFile.write("FRAME_10100000_SEC_AXIS       = 'Y'\n")
+        kernelFile.write(
+            "FRAME_10100000_SEC_VECTOR_DEF = 'OBSERVER_TARGET_VELOCITY'\n")
+        kernelFile.write("FRAME_10100000_SEC_OBSERVER   = 'SUN'\n")
+        kernelFile.write("FRAME_10100000_SEC_TARGET     = 'EARTH'\n")
+        kernelFile.write("FRAME_10100000_SEC_ABCORR     = 'NONE'\n")
+        kernelFile.write("FRAME_10100000_SEC_FRAME      = 'J2000'\n")
+        kernelFile.close()
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cs.furnsh(kernel)
+    et0 = cs.str2et("2007 JAN 01")
+    et1 = cs.str2et("2008 JAN 01")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=2000)
+    result = cs.gfsntc(
+        "EARTH",
+        "IAU_EARTH",
+        "Ellipsoid",
+        "NONE",
+        "SUN",
+        "SEM",
+        [1.0, 0.0, 0.0],
+        "LATITUDINAL",
+        "LATITUDE",
+        "=",
+        0.0,
+        0.0,
+        90.0 * cs.spd(),
+        1000,
+        cnfine
+    )
+    count = len(result) / 2
+    assert count > 0
+    beg, end = result[0], result[1]
+    begstr = cs.timout(
+        beg, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    endstr = cs.timout(
+        end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    assert begstr == "2007-MAR-21 00:01:25.527303 (TDB)"
+    assert endstr == "2007-MAR-21 00:01:25.527303 (TDB)"
+    beg, end = result[2], result[3]
+    begstr = cs.timout(
+        beg, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    endstr = cs.timout(
+        end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    assert begstr == "2007-SEP-23 09:46:39.606982 (TDB)"
+    assert endstr == "2007-SEP-23 09:46:39.606982 (TDB)"
+    cleanup_kernel(kernel)
 
 
-# =============================================================================
-# def test_gfrr():
-#     relate = ["=", "<", ">", "LOCMIN", "ABSMIN", "LOCMAX", "ABSMAX"]
-#     expected = {
-#         "=": [
-#             "2007-JAN-02 00:35:19.583",
-#             "2007-JAN-02 00:35:19.583",
-#             "2007-JAN-19 22:04:54.905",
-#             "2007-JAN-19 22:04:54.905",
-#             "2007-FEB-01 23:30:13.439",
-#             "2007-FEB-01 23:30:13.439",
-#             "2007-FEB-17 11:10:46.547",
-#             "2007-FEB-17 11:10:46.547",
-#             "2007-MAR-04 15:50:19.940",
-#             "2007-MAR-04 15:50:19.940",
-#             "2007-MAR-18 09:59:05.966",
-#             "2007-MAR-18 09:59:05.966",
-#         ],
-#         "<": [
-#             "2007-JAN-02 00:35:19.583",
-#             "2007-JAN-19 22:04:54.905",
-#             "2007-FEB-01 23:30:13.439",
-#             "2007-FEB-17 11:10:46.547",
-#             "2007-MAR-04 15:50:19.940",
-#             "2007-MAR-18 09:59:05.966",
-#         ],
-#         ">": [
-#             "2007-JAN-01 00:00:00.000",
-#             "2007-JAN-02 00:35:19.583",
-#             "2007-JAN-19 22:04:54.905",
-#             "2007-FEB-01 23:30:13.439",
-#             "2007-FEB-17 11:10:46.547",
-#             "2007-MAR-04 15:50:19.940",
-#             "2007-MAR-18 09:59:05.966",
-#             "2007-APR-01 00:00:00.000",
-#         ],
-#         "LOCMIN": [
-#             "2007-JAN-11 07:03:59.001",
-#             "2007-JAN-11 07:03:59.001",
-#             "2007-FEB-10 06:26:15.451",
-#             "2007-FEB-10 06:26:15.451",
-#             "2007-MAR-12 03:28:36.414",
-#             "2007-MAR-12 03:28:36.414",
-#         ],
-#         "ABSMIN": ["2007-JAN-11 07:03:59.001", "2007-JAN-11 07:03:59.001"],
-#         "LOCMAX": [
-#             "2007-JAN-26 02:27:33.772",
-#             "2007-JAN-26 02:27:33.772",
-#             "2007-FEB-24 09:35:07.822",
-#             "2007-FEB-24 09:35:07.822",
-#             "2007-MAR-25 17:26:56.158",
-#             "2007-MAR-25 17:26:56.158",
-#         ],
-#         "ABSMAX": ["2007-MAR-25 17:26:56.158", "2007-MAR-25 17:26:56.158"],
-#     }
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     et0 = spice.str2et("2007 JAN 01")
-#     et1 = spice.str2et("2007 APR 01")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     for relation in relate:
-#         result = spice.cell_double(2000)
-#         spice.gfrr(
-#             "moon",
-#             "none",
-#             "sun",
-#             relation,
-#             0.3365,
-#             0.0,
-#             spice.spd(),
-#             2000,
-#             cnfine,
-#             result,
-#         )
-#         count = spice.wncard(result)
-#         if count > 0:
-#             temp_results = []
-#             for i in range(0, count):
-#                 left, right = spice.wnfetd(result, i)
-#                 timstr_left = spice.timout(left, "YYYY-MON-DD HR:MN:SC.###", 41)
-#                 timstr_right = spice.timout(right, "YYYY-MON-DD HR:MN:SC.###", 41)
-#                 temp_results.append(timstr_left)
-#                 temp_results.append(timstr_right)
-#             assert temp_results == expected.get(relation)
-# =============================================================================
+def test_gfstol():
+    cs.gfstol(1.0e-16)
+    cs.gfstol(1.0e-6)
 
 
-# =============================================================================
-# def test_gfsep():
-#     spice.furnsh(CoreKernels.testMetaKernel)
-#     expected = [
-#         "2007-JAN-03 14:20:24.628017 (TDB)",
-#         "2007-FEB-02 06:16:24.111794 (TDB)",
-#         "2007-MAR-03 23:22:42.005064 (TDB)",
-#         "2007-APR-02 16:49:16.145506 (TDB)",
-#         "2007-MAY-02 09:41:43.840096 (TDB)",
-#         "2007-JUN-01 01:03:44.537483 (TDB)",
-#         "2007-JUN-30 14:15:26.586223 (TDB)",
-#         "2007-JUL-30 01:14:49.010797 (TDB)",
-#         "2007-AUG-28 10:39:01.398087 (TDB)",
-#         "2007-SEP-26 19:25:51.519413 (TDB)",
-#         "2007-OCT-26 04:30:56.635336 (TDB)",
-#         "2007-NOV-24 14:31:04.341632 (TDB)",
-#         "2007-DEC-24 01:40:12.245932 (TDB)",
-#     ]
-#     et0 = spice.str2et("2007 JAN 01")
-#     et1 = spice.str2et("2008 JAN 01")
-#     cnfine = spice.cell_double(2)
-#     spice.wninsd(et0, et1, cnfine)
-#     result = spice.cell_double(2000)
-#     spice.gfsep(
-#         "MOON",
-#         "SPHERE",
-#         "NULL",
-#         "SUN",
-#         "SPHERE",
-#         "NULL",
-#         "NONE",
-#         "EARTH",
-#         "LOCMAX",
-#         0.0,
-#         0.0,
-#         6.0 * spice.spd(),
-#         1000,
-#         cnfine,
-#         result,
-#     )
-#     count = spice.wncard(result)
-#     assert count == 13
-#     temp_results = []
-#     for i in range(0, count):
-#         start, end = spice.wnfetd(result, i)
-#         assert start == end
-#         temp_results.append(
-#             spice.timout(start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND", 41)
-#         )
-#     assert temp_results == expected
-# =============================================================================
+def test_gfsubc():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et0 = cs.str2et("2007 JAN 01")
+    et1 = cs.str2et("2008 JAN 01")
+    cnfine = cs.SpiceCell(typeno=1, size=2)
+    cnfine = cs.wninsd(et0, et1, cnfine)
+    result = cs.SpiceCell(typeno=1, size=2000)
+    result = cs.gfsubc(
+        "earth",
+        "iau_earth",
+        "Near point: ellipsoid",
+        "none",
+        "sun",
+        "geodetic",
+        "latitude",
+        ">",
+        16.0 * cs.rpd(),
+        0.0,
+        cs.spd() * 90.0,
+        1000,
+        cnfine
+    )
+    count = len(result) / 2
+    assert count > 0
+    start, end = result[0], result[1]
+    start_time = cs.timout(
+        start, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND"
+    )
+    end_time = cs.timout(end, "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND")
+    assert start_time == "2007-MAY-04 17:08:56.724320 (TDB)"
+    assert end_time == "2007-AUG-09 01:51:29.307830 (TDB)"
 
 
+def test_gftfov():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cs.furnsh(CassiniKernels.cassCk)
+    cs.furnsh(CassiniKernels.cassFk)
+    cs.furnsh(CassiniKernels.cassIk)
+    cs.furnsh(CassiniKernels.cassPck)
+    cs.furnsh(CassiniKernels.cassSclk)
+    cs.furnsh(CassiniKernels.cassTourSpk)
+    cs.furnsh(CassiniKernels.satSpk)
+    # Changed ABCORR to LT from LT+S for this test, so we do not need SSB
+    # begin test
+    # Cassini ISS NAC observed Enceladus on 2013-FEB-25 from ~11:00 to ~12:00
+    # Split confinement window, from continuous CK coverage, into two pieces
+    et_start1 = cs.str2et("2013-FEB-25 07:20:00.000")
+    et_end1 = cs.str2et("2013-FEB-25 11:45:00.000")  # \
+    et_start2 = cs.str2et("2013-FEB-25 11:55:00.000")  # _>synthetic 10min gap
+    et_end2 = cs.str2et("2013-FEB-26 14:25:00.000")
+    cnfine = cs.SpiceCell(typeno=1, size=4)
+    cnfine = cs.wninsd(et_start1, et_end1, cnfine)
+    cnfine = cs.wninsd(et_start2, et_end2, cnfine)
+    # Subtract off the position of the spacecraft relative to the solar system barycenter the result is the ray's direction vector.
+    result = cs.gftfov(
+        "CASSINI_ISS_NAC",
+        "ENCELADUS",
+        "ELLIPSOID",
+        "IAU_ENCELADUS",
+        "LT",
+        "CASSINI",
+        10.0,
+        cnfine
+    )
+    # Verify the expected results
+    assert len(result) == 4
+    sTimout = "YYYY-MON-DD HR:MN:SC UTC ::RND"
+    assert cs.timout(result[0], sTimout) == "2013-FEB-25 10:42:33 UTC"
+    assert cs.timout(result[1], sTimout) == "2013-FEB-25 11:45:00 UTC"
+    assert cs.timout(result[2], sTimout) == "2013-FEB-25 11:55:00 UTC"
+    assert cs.timout(result[3], sTimout) == "2013-FEB-25 12:04:30 UTC"
 # =============================================================================
-# =============================================================================
-# # frmchg
-# =============================================================================
-# gfsep
-# gfsntc
-# gfstol
-# gfsubc
-# gftfov
+# frmchg
 # =============================================================================
 
 
diff --git a/unittests/test_k_o.py b/unittests/test_k_o.py
new file mode 100644
index 00000000..80377f48
--- /dev/null
+++ b/unittests/test_k_o.py
@@ -0,0 +1,712 @@
+import cspyce as cs
+import numpy as np
+import numpy.testing as npt
+import os
+import pytest
+
+from gettestkernels import (
+    CoreKernels,
+    CassiniKernels,
+    ExtraKernels,
+    download_kernels,
+    cleanup_core_kernels,
+    TEST_FILE_DIR
+)
+
+
+@pytest.fixture(autouse=True)
+def clear_kernel_pool_and_reset():
+    cs.kclear()
+    cs.reset()
+    # yield for test
+    yield
+    # clear kernel pool again
+    cs.kclear()
+    cs.reset()
+
+
+def cleanup_kernel(path):
+    cs.kclear()
+    cs.reset()
+    if os.path.isfile(path):
+        os.remove(path)  # pragma: no cover
+    pass
+
+
+def setup_module(module):
+    download_kernels()
+
+
+def test_kclear():
+    cs.kclear()
+    assert cs.ktotal("ALL") == 0
+
+
+def test_kdata():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    file, ftype, source, handle = cs.kdata(0, "META")
+    assert ftype == "META"
+
+
+def test_kinfo():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    filetype, source, handle = cs.kinfo(CoreKernels.testMetaKernel)
+    assert filetype == "META"
+
+
+def test_kplfrm():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    cell = cs.kplfrm(-1)
+    assert cell.size > 100
+
+
+def test_ktotal():
+    # same as unload test
+    cs.furnsh(CoreKernels.testMetaKernel)
+    # 4 kernels + the meta kernel = 5
+    assert cs.ktotal("ALL") == 5
+    cs.unload(CoreKernels.testMetaKernel)
+    assert cs.ktotal("ALL") == 0
+
+
+def test_kxtrct():
+    # Tests from examples at this URL:  https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/ccs/kxtrct_c.html#Examples
+    i = 0
+    while i < 500:
+        i += 1
+        assert [" TO 1 January 1987", True, "1 October 1984 12:00:00"] == cs.kxtrct(
+            "FROM",
+            "from to beginning ending".upper().split(),
+            "FROM 1 October 1984 12:00:00 TO 1 January 1987"
+        )
+        assert ["FROM 1 October 1984 12:00:00", True, "1 January 1987"] == cs.kxtrct(
+            "TO",
+            "from to beginning ending".upper().split(),
+            "FROM 1 October 1984 12:00:00 TO 1 January 1987"
+        )
+        assert [" PHONE: 354-4321", True, "4800 OAK GROVE DRIVE"] == cs.kxtrct(
+            "ADDRESS:",
+            "address: phone: name:".upper().split(),
+            "ADDRESS: 4800 OAK GROVE DRIVE PHONE: 354-4321 ",
+        )
+        assert ["ADDRESS: 4800 OAK GROVE DRIVE", True, "354-4321"] == cs.kxtrct(
+            "PHONE:",
+            "address: phone: name:".upper().split(),
+            "ADDRESS: 4800 OAK GROVE DRIVE PHONE: 354-4321 "
+        )
+# =============================================================================
+#         with pytest.raises(Exception):
+#             cs.kxtrct(
+#                 "NAME:",
+#                 "address: phone: name:".upper().split(),
+#                 "ADDRESS: 4800 OAK GROVE DRIVE PHONE: 354-4321 "
+#             )
+# =============================================================================
+
+
+def test_latcyl():
+    expected1 = np.array([1.0, 0.0, 0.0])
+    expected2 = np.array([1.0, 90.0 * cs.rpd(), 0.0])
+    expected3 = np.array([1.0, 180.0 * cs.rpd(), 0.0])
+    npt.assert_array_almost_equal(
+        expected1, cs.latcyl(1.0, 0.0, 0.0), decimal=7)
+    npt.assert_array_almost_equal(
+        expected2, cs.latcyl(1.0, 90.0 * cs.rpd(), 0.0), decimal=7
+    )
+    npt.assert_array_almost_equal(
+        expected3, cs.latcyl(1.0, 180.0 * cs.rpd(), 0.0), decimal=7
+    )
+
+
+def test_latrec():
+    expected1 = np.array([1.0, 0.0, 0.0])
+    expected2 = np.array([0.0, 1.0, 0.0])
+    expected3 = np.array([-1.0, 0.0, 0.0])
+    npt.assert_array_almost_equal(
+        expected1, cs.latrec(1.0, 0.0, 0.0), decimal=7)
+    npt.assert_array_almost_equal(
+        expected2, cs.latrec(1.0, 90.0 * cs.rpd(), 0.0), decimal=7
+    )
+    npt.assert_array_almost_equal(
+        expected3, cs.latrec(1.0, 180.0 * cs.rpd(), 0.0), decimal=7
+    )
+
+
+def test_latsph():
+    expected1 = np.array([1.0, 90.0 * cs.rpd(), 0.0])
+    expected2 = np.array([1.0, 90.0 * cs.rpd(), 90.0 * cs.rpd()])
+    expected3 = np.array([1.0, 90.0 * cs.rpd(), 180.0 * cs.rpd()])
+    npt.assert_array_almost_equal(
+        expected1, cs.latsph(1.0, 0.0, 0.0), decimal=7)
+    npt.assert_array_almost_equal(
+        expected2, cs.latsph(1.0, 90.0 * cs.rpd(), 0.0), decimal=7
+    )
+    npt.assert_array_almost_equal(
+        expected3, cs.latsph(1.0, 180.0 * cs.rpd(), 0.0), decimal=7
+    )
+
+
+def test_latsrf():
+    cs.furnsh(ExtraKernels.phobosDsk)
+    srfpts = cs.latsrf(
+        "DSK/UNPRIORITIZED", "phobos", 0.0, "iau_phobos", [
+            [0.0, 45.0], [60.0, 45.0]]
+    )
+    radii = [cs.recrad(x)[0] for x in srfpts]
+    assert radii[0] > 9.77
+    assert radii[1] > 9.51
+
+
+def test_ldpool():
+    ldpool_names = [
+        "DELTET/DELTA_T_A",
+        "DELTET/K",
+        "DELTET/EB",
+        "DELTET/M",
+        "DELTET/DELTA_AT",
+    ]
+    ldpool_lens = [1, 1, 1, 2, 46]
+    textbuf = [
+        "DELTET/DELTA_T_A = 32.184",
+        "DELTET/K = 1.657D-3",
+        "DELTET/EB  = 1.671D-2",
+        "DELTET/M = ( 6.239996 1.99096871D-7 )",
+        "DELTET/DELTA_AT = ( 10, @1972-JAN-1",
+        "                     11, @1972-JUL-1",
+        "                     12, @1973-JAN-1",
+        "                     13, @1974-JAN-1",
+        "                     14, @1975-JAN-1",
+        "                     15, @1976-JAN-1",
+        "                     16, @1977-JAN-1",
+        "                     17, @1978-JAN-1",
+        "                     18, @1979-JAN-1",
+        "                     19, @1980-JAN-1",
+        "                     20, @1981-JUL-1",
+        "                     21, @1982-JUL-1",
+        "                     22, @1983-JUL-1",
+        "                     23, @1985-JUL-1",
+        "                     24, @1988-JAN-1",
+        "                     25, @1990-JAN-1",
+        "                     26, @1991-JAN-1",
+        "                     27, @1992-JUL-1",
+        "                     28, @1993-JUL-1",
+        "                     29, @1994-JUL-1",
+        "                     30, @1996-JAN-1",
+        "                     31, @1997-JUL-1",
+        "                     32, @1999-JAN-1 )",
+    ]
+    kernel = os.path.join(TEST_FILE_DIR, "ldpool_test.tls")
+    cleanup_kernel(kernel)
+    with open(kernel, "w") as kernelFile:
+        kernelFile.write("\\begindata\n")
+        for line in textbuf:
+            kernelFile.write(line + "\n")
+        kernelFile.write("\\begintext\n")
+        kernelFile.close()
+    cs.ldpool(kernel)
+    for var, expectLen in zip(ldpool_names, ldpool_lens):
+        n, vartype = cs.dtpool(var)
+        assert expectLen == n
+        assert vartype == "N"
+    cleanup_kernel(kernel)
+
+
+def test_lgresp():
+    yvals = [-2.0, -8.0, 26.0, 148.0]
+    a = cs.lgresp(-1.0, 2.0, yvals, 2.0)
+    assert a == pytest.approx(1.0)
+
+
+def test_lgrind():
+    p, dp = cs.lgrind([-1.0, 0.0, 1.0, 3.0], [-2.0, -7.0, -8.0, 26.0], 2.0)
+    assert p == pytest.approx(1.0)
+    assert dp == pytest.approx(16.0)
+
+
+def test_lgrint():
+    xvals = [-1.0, 0.0, 1.0, 3.0]
+    yvals = [-2.0, -7.0, -8.0, 26.0]
+    a = cs.lgrint(xvals, yvals, 2.0)
+    assert a == pytest.approx(1.0)
+
+
+def test_limbpt():
+    cs.furnsh(CoreKernels.spk)
+    cs.furnsh(ExtraKernels.marsSpk)
+    cs.furnsh(CoreKernels.pck)
+    cs.furnsh(CoreKernels.lsk)
+    cs.furnsh(ExtraKernels.phobosDsk)
+    # set the time
+    et = cs.str2et("1972 AUG 11 00:00:00")
+    # call limpt
+    npts, points, epochs, tangts = cs.limbpt(
+        "TANGENT/DSK/UNPRIORITIZED",
+        "Phobos",
+        et,
+        "IAU_PHOBOS",
+        "CN+S",
+        "CENTER",
+        "MARS",
+        [0.0, 0.0, 1.0],
+        cs.twopi() / 3.0,
+        3,
+        1.0e-4,
+        1.0e-7,
+        10000,
+    )
+    assert points is not None
+    assert len(points[0]) == 3
+
+
+def test_lmpool():
+    lmpool_names = [
+        "DELTET/DELTA_T_A",
+        "DELTET/K",
+        "DELTET/EB",
+        "DELTET/M",
+        "DELTET/DELTA_AT",
+    ]
+    lmpool_lens = [1, 1, 1, 2, 46]
+    textbuf = [
+        "DELTET/DELTA_T_A = 32.184",
+        "DELTET/K = 1.657D-3",
+        "DELTET/EB  = 1.671D-2",
+        "DELTET/M = ( 6.239996 1.99096871D-7 )",
+        "DELTET/DELTA_AT = ( 10, @1972-JAN-1",
+        "                     11, @1972-JUL-1",
+        "                     12, @1973-JAN-1",
+        "                     13, @1974-JAN-1",
+        "                     14, @1975-JAN-1",
+        "                     15, @1976-JAN-1",
+        "                     16, @1977-JAN-1",
+        "                     17, @1978-JAN-1",
+        "                     18, @1979-JAN-1",
+        "                     19, @1980-JAN-1",
+        "                     20, @1981-JUL-1",
+        "                     21, @1982-JUL-1",
+        "                     22, @1983-JUL-1",
+        "                     23, @1985-JUL-1",
+        "                     24, @1988-JAN-1",
+        "                     25, @1990-JAN-1",
+        "                     26, @1991-JAN-1",
+        "                     27, @1992-JUL-1",
+        "                     28, @1993-JUL-1",
+        "                     29, @1994-JUL-1",
+        "                     30, @1996-JAN-1",
+        "                     31, @1997-JUL-1",
+        "                     32, @1999-JAN-1 )",
+    ]
+    cs.lmpool(textbuf)
+    for var, expectLen in zip(lmpool_names, lmpool_lens):
+        n, vartype = cs.dtpool(var)
+        assert expectLen == n
+        assert vartype == "N"
+
+
+def test_lparse():
+    stringtest = "one two three four"
+    items = cs.lparse(stringtest, " ")
+    assert items == ("one", "two", "three", "four")
+
+
+def test_lparsm():
+    stringtest = "  A number of words   separated   by spaces   "
+    # Test with nmax (20) not equal to lenout (23), to ensure that
+    # their purposes have not been switched within cs.lparsm()
+    items = cs.lparsm(stringtest, " ")
+    assert items == ("A", "number", "of", "words", "separated", "by", "spaces")
+    # Test without lenout
+    items = cs.lparsm(stringtest, " ")
+    assert items == ("A", "number", "of", "words", "separated", "by", "spaces")
+
+
+def test_lspcn():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    et = cs.str2et("21 march 2005")
+    lon = cs.dpr() * cs.lspcn("EARTH", et, "NONE")
+    npt.assert_almost_equal(lon, 0.48153755894179384)
+
+
+def test_lstlec():
+    array = ["BOHR", "EINSTEIN", "FEYNMAN", "GALILEO", "NEWTON"]
+    assert cs.lstlec("NEWTON", array) == 4
+    assert cs.lstlec("EINSTEIN", array) == 1
+    assert cs.lstlec("GALILEO", array) == 3
+    assert cs.lstlec("Galileo", array) == 3
+    assert cs.lstlec("BETHE", array) == -1
+
+
+def test_lstled():
+    array = [-2.0, -2.0, 0.0, 1.0, 1.0, 11.0]
+    assert cs.lstled(-3.0, array) == -1
+    assert cs.lstled(-2.0, array) == 1
+    assert cs.lstled(0.0, array) == 2
+    assert cs.lstled(1.0, array) == 4
+    assert cs.lstled(11.1, array) == 5
+
+
+def test_lstlei():
+    array = [-2, -2, 0, 1, 1, 11]
+    assert cs.lstlei(-3, array) == -1
+    assert cs.lstlei(-2, array) == 1
+    assert cs.lstlei(0, array) == 2
+    assert cs.lstlei(1, array) == 4
+    assert cs.lstlei(12, array) == 5
+
+
+def test_lstltc():
+    array = ["BOHR", "EINSTEIN", "FEYNMAN", "GALILEO", "NEWTON"]
+    assert cs.lstltc("NEWTON", array) == 3
+    assert cs.lstltc("EINSTEIN", array) == 0
+    assert cs.lstltc("GALILEO", array) == 2
+    assert cs.lstltc("Galileo", array) == 3
+    assert cs.lstltc("BETHE", array) == -1
+
+
+def test_lstltd():
+    array = [-2.0, -2.0, 0.0, 1.0, 1.0, 11.0]
+    assert cs.lstltd(-3.0, array) == -1
+    assert cs.lstltd(-2.0, array) == -1
+    assert cs.lstltd(0.0, array) == 1
+    assert cs.lstltd(1.0, array) == 2
+    assert cs.lstltd(11.1, array) == 5
+
+
+def test_lstlti():
+    array = [-2, -2, 0, 1, 1, 11]
+    assert cs.lstlti(-3, array) == -1
+    assert cs.lstlti(-2, array) == -1
+    assert cs.lstlti(0, array) == 1
+    assert cs.lstlti(1, array) == 2
+    assert cs.lstlti(12, array) == 5
+
+
+def test_ltime():
+    cs.furnsh(CoreKernels.testMetaKernel)
+    OBS = 399
+    TARGET = 5
+    TIME_STR = "July 4, 2004"
+    et = cs.str2et(TIME_STR)
+    arrive, ltime = cs.ltime(et, OBS, "->", TARGET)
+    arrive_utc = cs.et2utc(arrive, "C", 3)
+    npt.assert_almost_equal(ltime, 2918.71705, decimal=4)
+    assert arrive_utc == "2004 JUL 04 00:48:38.717"
+    receive, rtime = cs.ltime(et, OBS, "<-", TARGET)
+    receive_utc = cs.et2utc(receive, "C", 3)
+    npt.assert_almost_equal(rtime, 2918.75247, decimal=4)
+    assert receive_utc == "2004 JUL 03 23:11:21.248"
+
+
+def test_lx4dec():
+    assert cs.lx4dec("1%2%3", 0) == [0, 1]
+    assert cs.lx4dec("1%2%3", 1) == [0, 0]
+    assert cs.lx4dec("1%2%3", 2) == [2, 1]
+
+
+def test_lx4num():
+    assert cs.lx4num("1%2%3", 0) == [0, 1]
+    assert cs.lx4num("1%2%3", 1) == [0, 0]
+    assert cs.lx4num("1%2%3", 2) == [2, 1]
+    assert cs.lx4num("1%2e1%3", 2) == [4, 3]
+
+
+def test_lx4sgn():
+    assert cs.lx4sgn("1%2%3", 0) == [0, 1]
+    assert cs.lx4sgn("1%2%3", 1) == [0, 0]
+    assert cs.lx4sgn("1%2%3", 2) == [2, 1]
+
+
+def test_lx4uns():
+    # not a very good test
+    assert cs.lx4uns("test 10 end", 4) == [3, 0]
+
+
+def test_lxqstr():
+    assert cs.lxqstr('The "SPICE" system', '"', 4) == [10, 7]
+    assert cs.lxqstr('The "SPICE" system', '"', 4) == [10, 7]
+    assert cs.lxqstr('The "SPICE" system', '"', 0) == [-1, 0]
+    assert cs.lxqstr('The "SPICE" system', "'", 4) == [3, 0]
+    assert cs.lxqstr('The """SPICE"""" system', '"', 4) == [14, 11]
+    assert cs.lxqstr("The &&&SPICE system", "&", 4) == [5, 2]
+    assert cs.lxqstr("' '", "'", 0) == [2, 3]
+    assert cs.lxqstr("''", "'", 0) == [1, 2]
+
+
+def test_m2eul():
+    ticam = [
+        [0.49127379678135830, 0.50872620321864170, 0.70699908539882417],
+        [-0.50872620321864193, -0.49127379678135802, 0.70699908539882428],
+        [0.70699908539882406, -0.70699908539882439, 0.01745240643728360],
+    ]
+    kappa, ang2, ang1 = cs.m2eul(ticam, 3, 1, 3)
+    alpha = ang1 + 1.5 * cs.pi()
+    delta = cs.halfpi() - ang2
+    expected = [315.000000, 1.000000, 45.000000]
+    result = [cs.dpr() * alpha, cs.dpr() * delta, cs.dpr() * kappa]
+    npt.assert_array_almost_equal(expected, result)
+
+
+def test_m2q():
+    r = cs.rotate(cs.halfpi(), 3)
+    q = cs.m2q(r)
+    expected = [np.sqrt(2) / 2.0, 0.0, 0.0, -np.sqrt(2) / 2.0]
+    np.testing.assert_array_almost_equal(expected, q, decimal=6)
+
+
+def test_matchi():
+    string = "  ABCDEFGHIJKLMNOPQRSTUVWXYZ  "
+    wstr = "*"
+    wchr = "%"
+    assert cs.matchi(string, "*A*", wstr, wchr)
+    assert cs.matchi(string, "A%D*", wstr, wchr) is False
+    assert cs.matchi(string, "A%C*", wstr, wchr)
+    assert cs.matchi(string, "%A*", wstr, wchr) is False
+    assert cs.matchi(string, "%%CD*Z", wstr, wchr)
+    assert cs.matchi(string, "%%CD", wstr, wchr) is False
+    assert cs.matchi(string, "A*MN*Y*Z", wstr, wchr)
+    assert cs.matchi(string, "A*MN*Y*%Z", wstr, wchr) is False
+    assert cs.matchi(string, "*BCD*Z*", wstr, wchr)
+    assert cs.matchi(string, "*bdc*z*", wstr, wchr) is False
+    assert cs.matchi(string, " *bcD*Z*", wstr, wchr)
+
+
+def test_matchw():
+    string = "  ABCDEFGHIJKLMNOPQRSTUVWXYZ  "
+    wstr = "*"
+    wchr = "%"
+    assert cs.matchw(string, "*A*", wstr, wchr)
+    assert cs.matchw(string, "A%D*", wstr, wchr) is False
+    assert cs.matchw(string, "A%C*", wstr, wchr)
+    assert cs.matchw(string, "%A*", wstr, wchr) is False
+    assert cs.matchw(string, "%%CD*Z", wstr, wchr)
+    assert cs.matchw(string, "%%CD", wstr, wchr) is False
+    assert cs.matchw(string, "A*MN*Y*Z", wstr, wchr)
+    assert cs.matchw(string, "A*MN*Y*%Z", wstr, wchr) is False
+    assert cs.matchw(string, "*BCD*Z*", wstr, wchr)
+    assert cs.matchw(string, "*bdc*z*", wstr, wchr) is False
+    assert cs.matchw(string, " *BCD*Z*", wstr, wchr)
+
+
+def test_mequ():
+    m1 = np.identity(3)
+    mout = cs.mequ(m1)
+    assert np.array_equal(m1, mout)
+
+
+def test_mequg():
+    m1 = np.identity(2)
+    mout = cs.mequg(m1)
+    assert np.array_equal(m1, mout)
+
+
+def test_mtxm():
+    m1 = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
+    m2 = np.array([[1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
+    mout = cs.mtxm(m1, m2)
+    expected = np.array([[-3.0, 5.0, 7.0], [-3.0, 7.0, 8.0], [-3.0, 9.0, 9.0]])
+    assert np.array_equal(mout, expected)
+
+
+def test_mtxmg():
+    m1 = np.array([[1.0, 2.0, 3.0, 0.0], [1.0, 1.0, 1.0, 1.0]])
+    m2 = np.array([[1.0, 2.0, 3.0], [0.0, 0.0, 0.0]])
+    mout = cs.mtxmg(m1, m2)
+    expected = np.array(
+        [[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [3.0, 6.0, 9.0], [0.0, 0.0, 0.0]]
+    )
+    assert np.array_equal(mout, expected)
+
+
+def test_mtxv():
+    m1 = np.array([[1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
+    vin = np.array([5.0, 10.0, 15.0])
+    mout = cs.mtxv(m1, vin)
+    expected = np.array([-5.0, 15.0, 15.0])
+    assert np.array_equal(mout, expected)
+
+
+def test_mtxvg():
+    m1 = np.array([[1.0, 2.0], [1.0, 3.0], [1.0, 4.0]])
+    v2 = np.array([1.0, 2.0, 3.0])
+    mout = cs.mtxvg(m1, v2)
+    expected = np.array([6.0, 20.0])
+    assert np.array_equal(mout, expected)
+
+
+def test_mxm():
+    m1 = [[1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
+    m2 = [[1.0, 0.0, 0.0], [0.0, 1.0, 1.0], [0.0, -1.0, 1.0]]
+    mout = np.array(cs.mxm(m1, m2))
+    m1 = np.array(m1)
+    m2 = np.array(m2)
+    mout2 = np.dot(m1, m2)
+    assert np.array_equal(mout, mout2)
+
+
+def test_mxmg():
+    m1 = [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]
+    m2 = [[1.0, 2.0, 3.0], [2.0, 4.0, 6.0]]
+    mout = np.array(cs.mxmg(m1, m2))
+    m1 = np.array(m1)
+    m2 = np.array(m2)
+    mout2 = np.dot(m1, m2)
+    assert np.array_equal(mout, mout2)
+
+
+def test_mxmt():
+    m1 = [[0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]
+    mout = cs.mxmt(m1, m1)
+    assert np.array_equal(mout, np.identity(3))
+
+
+def test_mxmtg():
+    m1 = np.array([[1.0, 2.0, 3.0], [3.0, 2.0, 1.0]])
+    m2 = np.array([[1.0, 2.0, 0.0], [2.0, 1.0, 2.0],
+                  [1.0, 2.0, 0.0], [2.0, 1.0, 2.0]])
+    mout = cs.mxmtg(m1, m2)
+    expected = np.array([[5.0, 10.0, 5.0, 10.0], [7.0, 10.0, 7.0, 10.0]])
+    assert np.array_equal(mout, expected)
+
+
+def test_mxv():
+    m1 = np.array([[0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], [0.0, 0.0, 1.0]])
+    vin = np.array([1.0, 2.0, 3.0])
+    mout = cs.mxv(m1, vin)
+    expected = np.array([2.0, -1.0, 3.0])
+    assert np.array_equal(mout, expected)
+
+
+def test_mxvg():
+    m1 = np.array([[1.0, 1.0, 1.0], [2.0, 3.0, 4.0]])
+    v2 = np.array([1.0, 2.0, 3.0])
+    mout = cs.mxvg(m1, v2)
+    expected = np.array([6.0, 20.0])
+    assert np.array_equal(mout, expected)
+
+
+def test_namfrm():
+    assert cs.namfrm("J2000") == 1
+
+
+def test_ncpos():
+    string = "BOB, JOHN, TED, AND MARTIN    "
+    chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    assert cs.ncpos(string, chars, 0) == 3
+    assert cs.ncpos(string, chars, 4) == 4
+    assert cs.ncpos(string, chars, 5) == 9
+    assert cs.ncpos(string, chars, 10) == 10
+    assert cs.ncpos(string, chars, 11) == 14
+    assert cs.ncpos(string, chars, 15) == 15
+    assert cs.ncpos(string, chars, 16) == 19
+    assert cs.ncpos(string, chars, 20) == 26
+    assert cs.ncpos(string, chars, 27) == 27
+    assert cs.ncpos(string, chars, 28) == 28
+    assert cs.ncpos(string, chars, 29) == 29
+    assert cs.ncpos(string, chars, -12) == 3
+    assert cs.ncpos(string, chars, -1) == 3
+    assert cs.ncpos(string, chars, 30) == -1
+    assert cs.ncpos(string, chars, 122) == -1
+
+
+def test_ncposr():
+    string = "BOB, JOHN, TED, AND MARTIN...."
+    chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    assert cs.ncposr(string, chars, 29) == 29
+    assert cs.ncposr(string, chars, 28) == 28
+    assert cs.ncposr(string, chars, 27) == 27
+    assert cs.ncposr(string, chars, 26) == 26
+    assert cs.ncposr(string, chars, 25) == 19
+    assert cs.ncposr(string, chars, 18) == 15
+    assert cs.ncposr(string, chars, 14) == 14
+    assert cs.ncposr(string, chars, 13) == 10
+    assert cs.ncposr(string, chars, 9) == 9
+    assert cs.ncposr(string, chars, 8) == 4
+    assert cs.ncposr(string, chars, 3) == 3
+    assert cs.ncposr(string, chars, 2) == -1
+    assert cs.ncposr(string, chars, -1) == -1
+    assert cs.ncposr(string, chars, -5) == -1
+    assert cs.ncposr(string, chars, 30) == 29
+    assert cs.ncposr(string, chars, 122) == 29
+
+
+def test_nearpt():
+    a, b, c = 1.0, 2.0, 3.0
+    point = [3.5, 0.0, 0.0]
+    pnear, alt = cs.nearpt(point, a, b, c)
+    expected_pnear = [1.0, 0.0, 0.0]
+    expected_alt = 2.5
+    npt.assert_almost_equal(alt, expected_alt)
+    npt.assert_array_almost_equal(pnear, expected_pnear)
+
+
+def test_npedln():
+    linept = [1.0e6, 2.0e6, 3.0e6]
+    a, b, c = 7.0e5, 7.0e5, 6.0e5
+    linedr = [-4.472091234e-1, -8.944182469e-1, -4.472091234e-3]
+    pnear, dist = cs.npedln(a, b, c, linept, linedr)
+    expected_pnear = [-1633.3111, -3266.6222, 599991.83]
+    expected_dist = 2389967.9
+    npt.assert_almost_equal(dist, expected_dist, decimal=1)
+    npt.assert_array_almost_equal(expected_pnear, pnear, decimal=2)
+
+
+def test_npelpt():
+    center = [1.0, 2.0, 3.0]
+    smajor = [3.0, 0.0, 0.0]
+    sminor = [0.0, 2.0, 0.0]
+    point = [-4.0, 2.0, 1.0]
+    expected_pnear = [-2.0, 2.0, 3.0]
+    expected_dist = 2.8284271
+    ellipse = cs.cgv2el(center, smajor, sminor)
+    pnear, dist = cs.npelpt(point, ellipse)
+    npt.assert_almost_equal(dist, expected_dist)
+    npt.assert_array_almost_equal(expected_pnear, pnear)
+
+
+def test_nplnpt():
+    linept = [1.0, 2.0, 3.0]
+    linedr = [0.0, 1.0, 1.0]
+    point = [-6.0, 9.0, 10.0]
+    pnear, dist = cs.nplnpt(linept, linedr, point)
+    expected_pnear = [1.0, 9.0, 10.0]
+    expected_dist = 7.0
+    assert dist == expected_dist
+    npt.assert_array_almost_equal(expected_pnear, pnear)
+
+
+# Test changed
+def test_nvc2pl():
+    normal = [1.0, 1.0, 1.0]
+    constant = 23.0
+    expected_constant = 13.279056
+    expected_normal = [0.57735027, 0.57735027, 0.57735027]
+    plane = cs.nvc2pl(normal, constant)
+    npt.assert_array_almost_equal(plane[0:3], expected_normal)
+    npt.assert_almost_equal(plane[-1], expected_constant, decimal=6)
+
+
+def fail_nvp2pl():
+    normal = [1.0, 1.0, 1.0]
+    point = [1.0, 4.0, 9.0]
+    expected_constant = 8.0829038
+    expected_normal = [0.57735027, 0.57735027, 0.57735027]
+    plane = cs.nvp2pl(normal, point)
+    npt.assert_array_almost_equal(plane.normal, expected_normal)
+    npt.assert_almost_equal(plane.constant, expected_constant, decimal=6)
+
+
+# =============================================================================
+# =============================================================================
+# # nextwd
+# =============================================================================
+# =============================================================================
+# # nthwd
+# =============================================================================
+# nvp2pl
+# occult
+# orderc
+# orderd
+# orderi
+# oscelt
+# oscltx
+# =============================================================================