Skip to content

Commit

Permalink
implemented init, update test and passed
Browse files Browse the repository at this point in the history
  • Loading branch information
ShisatoYano committed Oct 29, 2023
1 parent b6348e4 commit 9e1884f
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/test_gnss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Unit test of Gnss
Author: Shisato Yano
"""

import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import pytest
import sys
from pathlib import Path

sys.path.append(str(Path(__file__).absolute().parent) + "/../src/components/sensors/gnss")
from gnss import Gnss


# mock class
class MockState:
def __init__(self):
pass

def get_x_m(self):
return 1.0

def get_y_m(self):
return 1.0

def get_yaw_rad(self):
return 1.0

def get_speed_mps(self):
return 1.0


# test instance
gnss = Gnss()
state = MockState()


def test_initialize():
assert gnss.NOISE_VAR_MAT.shape == (2, 2)
assert gnss.NOISE_VAR_MAT[0, 0] == 0.25
assert gnss.NOISE_VAR_MAT[0, 1] == 0.0
assert gnss.NOISE_VAR_MAT[1, 0] == 0.0
assert gnss.NOISE_VAR_MAT[1, 1] == 0.25
assert gnss.DRAW_COLOR == 'g'
assert gnss.latest_observed_xy == None
assert len(gnss.x_history) == 0
assert len(gnss.y_history) == 0


def test_update():
gnss.update(state)
assert gnss.latest_observed_xy.shape == (2, 1)
assert len(gnss.x_history) != 0
assert len(gnss.y_history) != 0


def test_draw():
plt.clf()
plt.close()

figure = plt.figure(figsize=(8, 8))
axes = figure.add_subplot(111)

gnss.draw(axes, [])

0 comments on commit 9e1884f

Please sign in to comment.