From cb65afb125dd43ea482879045d7d2a840a904e5a Mon Sep 17 00:00:00 2001 From: Valeri Atamaniouk Date: Thu, 21 Apr 2016 11:49:34 +0300 Subject: [PATCH] iqgen: unit tests for signals Added unit test for signal objects. Removed encoder factory module. --- peregrine/iqgen/bits/encoder_factory.py | 199 ------------------------ tests/test_iqgen_signals.py | 75 +++++++++ tests/test_iqgen_sv_glo.py | 24 +-- 3 files changed, 87 insertions(+), 211 deletions(-) delete mode 100644 peregrine/iqgen/bits/encoder_factory.py create mode 100644 tests/test_iqgen_signals.py diff --git a/peregrine/iqgen/bits/encoder_factory.py b/peregrine/iqgen/bits/encoder_factory.py deleted file mode 100644 index f90bd22..0000000 --- a/peregrine/iqgen/bits/encoder_factory.py +++ /dev/null @@ -1,199 +0,0 @@ -# Copyright (C) 2016 Swift Navigation Inc. -# Contact: Valeri Atamaniouk -# -# This source is subject to the license found in the file 'LICENSE' which must -# be be distributed together with this source. All other rights reserved. -# -# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, -# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. - -""" -The :mod:`peregrine.iqgen.bits.encoder_factory` module contains classes and -functions related to object factory for output encoder objects. - -""" - -from peregrine.iqgen.bits.encoder_gps import GPSL1BitEncoder -from peregrine.iqgen.bits.encoder_gps import GPSL2BitEncoder -from peregrine.iqgen.bits.encoder_gps import GPSL1L2BitEncoder -from peregrine.iqgen.bits.encoder_gps import GPSL1TwoBitsEncoder -from peregrine.iqgen.bits.encoder_gps import GPSL2TwoBitsEncoder -from peregrine.iqgen.bits.encoder_gps import GPSL1L2TwoBitsEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL1BitEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL2BitEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL1L2BitEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL1TwoBitsEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL2TwoBitsEncoder -from peregrine.iqgen.bits.encoder_glo import GLONASSL1L2TwoBitsEncoder -from peregrine.iqgen.bits.encoder_other import GPSGLONASSBitEncoder -from peregrine.iqgen.bits.encoder_other import GPSGLONASSTwoBitsEncoder - - -class ObjectFactory(object): - ''' - Object factory for encoder objects. - ''' - - def __init__(self): - super(ObjectFactory, self).__init__() - - def toMapForm(self, obj): - t = type(obj) - if t is GPSL1BitEncoder: - return self.__GPSL1BitEncoder_ToMap(obj) - elif t is GPSL2BitEncoder: - return self.__GPSL2BitEncoder_ToMap(obj) - elif t is GPSL1L2BitEncoder: - return self.__GPSL1L2BitEncoder_ToMap(obj) - elif t is GPSL1TwoBitsEncoder: - return self.__GPSL1TwoBitsEncoder_ToMap(obj) - elif t is GPSL2TwoBitsEncoder: - return self.__GPSL2TwoBitsEncoder_ToMap(obj) - elif t is GPSL1L2TwoBitsEncoder: - return self.__GPSL1L2TwoBitsEncoder_ToMap(obj) - elif t is GLONASSL1BitEncoder: - return self.__GLONASSL1BitEncoder_ToMap(obj) - elif t is GLONASSL2BitEncoder: - return self.__GLONASSL2BitEncoder_ToMap(obj) - elif t is GLONASSL1L2BitEncoder: - return self.__GLONASSL1L2BitEncoder_ToMap(obj) - elif t is GLONASSL1TwoBitsEncoder: - return self.__GLONASSL1TwoBitsEncoder_ToMap(obj) - elif t is GLONASSL2TwoBitsEncoder: - return self.__GLONASSL2TwoBitsEncoder_ToMap(obj) - elif t is GLONASSL1L2TwoBitsEncoder: - return self.__GLONASSL1L2TwoBitsEncoder_ToMap(obj) - elif t is GPSGLONASSBitEncoder: - return self.__GPSGLONASSBitEncoder_ToMap(obj) - elif t is GPSGLONASSTwoBitsEncoder: - return self.__GPSGLONASSTwoBitsEncoder_ToMap(obj) - else: - raise ValueError("Invalid object type") - - def fromMapForm(self, data): - t = data['type'] - if t == 'GPSL1BitEncoder': - return self.__MapTo_GPSL1BitEncoder(data) - elif t == 'GPSL2BitEncoder': - return self.__MapTo_GPSL2BitEncoder(data) - elif t == 'GPSL2BitEncoder': - return self.__MapTo_GPSL1L2BitEncoder(data) - elif t == 'GPSL1TwoBitsEncoder': - return self.__MapTo_GPSL1TwoBitsEncoder(data) - elif t == 'GPSL2TwoBitsEncoder': - return self.__MapTo_GPSL2TwoBitsEncoder(data) - elif t == 'GPSL1L2TwoBitsEncoder': - return self.__MapTo_GPSL1L2TwoBitsEncoder(data) - elif t == 'GLONASSL1BitEncoder': - return self.__MapTo_GLONASSL1BitEncoder(data) - elif t == 'GLONASSL2BitEncoder': - return self.__MapTo_GLONASSL2BitEncoder(data) - elif t == 'GLONASSL2BitEncoder': - return self.__MapTo_GLONASSL1L2BitEncoder(data) - elif t == 'GLONASSL1TwoBitsEncoder': - return self.__MapTo_GLONASSL1TwoBitsEncoder(data) - elif t == 'GLONASSL2TwoBitsEncoder': - return self.__MapTo_GLONASSL2TwoBitsEncoder(data) - elif t == 'GLONASSL1L2TwoBitsEncoder': - return self.__MapTo_GLONASSL1L2TwoBitsEncoder(data) - elif t == 'GPSGLONASSBitEncoder': - return self.__MapTo_GPSGLONASSBitEncoder(data) - elif t == 'GPSGLONASSTwoBitsEncoder': - return self.__MapTo_GPSGLONASSTwoBitsEncoder(data) - else: - raise ValueError("Invalid object type") - - def __GPSL1BitEncoder_ToMap(self, obj): - data = {'type': 'GPSL1BitEncoder'} - return data - - def __GPSL2BitEncoder_ToMap(self, obj): - data = {'type': 'GPSL2BitEncoder'} - return data - - def __GPSL1L2BitEncoder_ToMap(self, obj): - data = {'type': 'GPSL1L2BitEncoder'} - return data - - def __GPSL1TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GPSL1TwoBitsEncoder'} - return data - - def __GPSL2TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GPSL2TwoBitsEncoder'} - return data - - def __GPSL1L2TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GPSL1L2TwoBitsEncoder'} - return data - - def __GLONASSL1BitEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL1BitEncoder'} - return data - - def __GLONASSL2BitEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL2BitEncoder'} - return data - - def __GLONASSL1L2BitEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL1L2BitEncoder'} - return data - - def __GLONASSL1TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL1TwoBitsEncoder'} - return data - - def __GLONASSL2TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL2TwoBitsEncoder'} - return data - - def __GLONASSL1L2TwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GLONASSL1L2TwoBitsEncoder'} - return data - - def __GPSGLONASSBitEncoder_ToMap(self, obj): - data = {'type': 'GPSGLONASSBitEncoder'} - return data - - def __GPSGLONASSTwoBitsEncoder_ToMap(self, obj): - data = {'type': 'GPSGLONASSTwoBitsEncoder'} - return data - - def __MapTo_GPSL1BitEncoder(self, data): - return GPSL1BitEncoder() - - def __MapTo_GPSL2BitEncoder(self, data): - return GPSL2BitEncoder() - - def __MapTo_GPSL1L2BitEncoder(self, data): - return GPSL1L2BitEncoder() - - def __MapTo_GPSL1TwoBitsEncoder(self, data): - return GPSL1TwoBitsEncoder() - - def __MapTo_GPSL2TwoBitsEncoder(self, data): - return GPSL2TwoBitsEncoder() - - def __MapTo_GPSL1L2TwoBitsEncoder(self, data): - return GPSL1L2TwoBitsEncoder() - - def __MapTo_GLONASSL1BitEncoder(self, data): - return GLONASSL1BitEncoder() - - def __MapTo_GLONASSL2BitEncoder(self, data): - return GLONASSL2BitEncoder() - - def __MapTo_GLONASSL1L2BitEncoder(self, data): - return GLONASSL1L2BitEncoder() - - def __MapTo_GLONASSL1TwoBitsEncoder(self, data): - return GLONASSL1TwoBitsEncoder() - - def __MapTo_GLONASSL2TwoBitsEncoder(self, data): - return GLONASSL2TwoBitsEncoder() - - def __MapTo_GLONASSL1L2TwoBitsEncoder(self, data): - return GLONASSL1L2TwoBitsEncoder() - -factoryObject = ObjectFactory() diff --git a/tests/test_iqgen_signals.py b/tests/test_iqgen_signals.py new file mode 100644 index 0000000..35ae9e7 --- /dev/null +++ b/tests/test_iqgen_signals.py @@ -0,0 +1,75 @@ +# Copyright (C) 2016 Swift Navigation Inc. +# +# Contact: Valeri Atamaniouk +# This source is subject to the license found in the file 'LICENSE' which must +# be be distributed together with this source. All other rights reserved. +# +# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +''' +Unit tests for IQgen signal definitions +''' + +from peregrine.iqgen.bits.signals import GPS +from peregrine.iqgen.bits.signals import GLONASS +from scipy.constants import c as C + + +def test_GPSL1(): + ''' + Test GPS L1 signal methods + ''' + doppler = -10. / C * GPS.L1CA.CENTER_FREQUENCY_HZ + assert GPS.L1CA.calcDopplerShiftHz(1000., 10.) == doppler + assert GPS.L1CA.getCodeChipIndex(0.) == 0 + assert GPS.L1CA.getCodeChipIndex(0.5) == 511500 + assert GPS.L1CA.getSymbolIndex(0.) == 0 + assert GPS.L1CA.getSymbolIndex(0.5) == 25 + + +def test_GPSL2(): + ''' + Test GPS L2 signal methods + ''' + doppler = -10. / C * GPS.L2C.CENTER_FREQUENCY_HZ + assert GPS.L2C.calcDopplerShiftHz(1000., 10.) == doppler + assert GPS.L2C.getCodeChipIndex(0.) == 0 + assert GPS.L2C.getCodeChipIndex(0.5) == 511500 + assert GPS.L2C.getSymbolIndex(0.) == 0 + assert GPS.L2C.getSymbolIndex(0.5) == 25 + + +def test_GLONASS_common(): + ''' + Test common GLONASS signal methods + ''' + assert GLONASS.getCodeChipIndex(0.) == 0 + assert GLONASS.getCodeChipIndex(0.5) == 511000 / 2 + assert GLONASS.getSymbolIndex(0.) == 0 + assert GLONASS.getSymbolIndex(0.5) == 50 + + +def test_GLONASSL1(): + ''' + Test GLONASS L1 signal methods + ''' + doppler = -10. / C * GLONASS.L1S[0].CENTER_FREQUENCY_HZ + assert GLONASS.L1S[0].calcDopplerShiftHz(1000., 10.) == doppler + assert GLONASS.L1S[0].getCodeChipIndex(0.) == 0 + assert GLONASS.L1S[0].getCodeChipIndex(0.5) == 511000 / 2 + assert GLONASS.L1S[0].getSymbolIndex(0.) == 0 + assert GLONASS.L1S[0].getSymbolIndex(0.5) == 50 + + +def test_GLONASSL2(): + ''' + Test GLONASS L2 signal methods + ''' + doppler = -10. / C * GLONASS.L2S[0].CENTER_FREQUENCY_HZ + assert GLONASS.L2S[0].calcDopplerShiftHz(1000., 10.) == doppler + assert GLONASS.L2S[0].getCodeChipIndex(0.) == 0 + assert GLONASS.L2S[0].getCodeChipIndex(0.5) == 511000 / 2 + assert GLONASS.L2S[0].getSymbolIndex(0.) == 0 + assert GLONASS.L2S[0].getSymbolIndex(0.5) == 50 diff --git a/tests/test_iqgen_sv_glo.py b/tests/test_iqgen_sv_glo.py index 3b0aaa2..5ec3ffb 100644 --- a/tests/test_iqgen_sv_glo.py +++ b/tests/test_iqgen_sv_glo.py @@ -22,7 +22,7 @@ import numpy -def test_GPSSv_init(): +def test_GLOSv_init(): ''' GLONASS SV initialization test ''' @@ -34,7 +34,7 @@ def test_GPSSv_init(): assert isinstance(sv.doppler, DopplerBase) -def test_GPSSV_bands(): +def test_GLOSV_bands(): ''' GLONASS SV band configurations ''' @@ -58,9 +58,9 @@ def test_GPSSV_bands(): assert sv.isL2Enabled() -def test_GPSSV_messages(): +def test_GLOSV_messages(): ''' - GPS SV messages test + GLONASS SV messages test ''' sv = GLOSatellite(1) assert sv.l1Message == sv.getL1Message() @@ -75,9 +75,9 @@ def test_GPSSV_messages(): assert sv.l2Message == sv.getL2Message() != msg2 -def test_GPSSV_str(): +def test_GLOSV_str(): ''' - GPS SV string representation + GLONASS SV string representation ''' sv = GLOSatellite(3) value = str(sv) @@ -85,9 +85,9 @@ def test_GPSSV_str(): assert value.find('3') >= 0 -def test_SVBase_getBatchSignals0(): +def test_GLOSv_getBatchSignals0(): ''' - GPS SV signal generation: not enabled + GLONASS SV signal generation: not enabled ''' sv = GLOSatellite(1) start = 0. @@ -106,9 +106,9 @@ def test_SVBase_getBatchSignals0(): assert (samples == 0).all() -def test_SVBase_getBatchSignals1(): +def test_GLOSv_getBatchSignals1(): ''' - GPS SV signal generation: not available + GLONASS SV signal generation: not available ''' sv = GLOSatellite(1) start = 0. @@ -127,7 +127,7 @@ def test_SVBase_getBatchSignals1(): assert (samples == 0).all() -def test_SVBase_getBatchSignals2(): +def test_GLOSv_getBatchSignals2(): ''' GLONASS SV signal generation: L1 ''' @@ -154,7 +154,7 @@ def test_SVBase_getBatchSignals2(): assert (samples[3] == 0).all() -def test_SVBase_getBatchSignals3(): +def test_GLOSv_getBatchSignals3(): ''' GLONASS SV signal generation: L2 '''