Skip to content
Snippets Groups Projects
Commit 6a895ea7 authored by Luise Odenthal's avatar Luise Odenthal
Browse files

changed test

parent b2c15fe2
No related branches found
No related tags found
No related merge requests found
import unittest
import numpy as np
from navipy.database import database
import navipy.comparing as comparing
import navipy.processing as processing
import pkg_resources
def is_numeric_array(array):
"""Checks if the dtype of the array is numeric.
Booleans, unsigned integer, signed integer, floats and complex are
considered numeric.
Parameters
----------
array : `numpy.ndarray`-like
The array to check.
Returns
-------
is_numeric : `bool`
True if it is a recognized numerical and False if object or
string.
"""
numerical_dtype_kinds = {'b', # boolean
'u', # unsigned integer
'i', # signed integer
'f', # floats
'c'} # complex
try:
return array.dtype.kind in numerical_dtype_kinds
except AttributeError:
# in case it's not a numpy array it will probably have no dtype.
return np.asarray(array).dtype.kind in numerical_dtype_kinds
class TestCase(unittest.TestCase):
def setUp(self):
self.mydb_filename = pkg_resources.resource_filename(
'navipy', 'resources/database.db')
self.mydb = database.DataBaseLoad(self.mydb_filename)
def test_imagediff_curr(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
curr2 = curr.copy()
curr2[3, 5, 2, 0] = np.nan
curr3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
curr3 = [curr3, curr3, curr3]
curr3 = np.array(curr3)
curr4 = np.zeros((3, 4, 5, 0))
for s in [curr2, curr3, curr4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.imagediff(s, mem)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [curr]:
diff = comparing.imagediff(s, mem)
self.assertFalse(diff.shape[1] <= 0)
self.assertTrue(diff.shape[2] == 4)
self.assertFalse(np.any(np.isnan(diff)))
self.assertTrue(is_numeric_array(diff))
self.assertTrue(diff.shape[3] == 1)
self.assertTrue(diff.shape[0] > 0)
self.assertTrue(diff.shape[1] > 0)
def test_imagediff_memory(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
mem2 = curr.copy()
mem2[3, 5, 2, 0] = np.nan
mem3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
mem3 = [mem3, mem3, mem3]
mem3 = np.array(mem3)
mem4 = np.zeros((3, 4, 5, 0))
for s in [mem2, mem3, mem4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.imagediff(curr, s)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [mem]:
diff = comparing.imagediff(curr, s)
self.assertFalse(diff.shape[1] <= 0)
self.assertTrue(diff.shape[2] == 4)
self.assertFalse(np.any(np.isnan(diff)))
self.assertTrue(is_numeric_array(diff))
def test_rot_imagediff_curr(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
curr2 = curr.copy()
curr2[3, 5, 2, 0] = np.nan
curr3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
curr3 = [curr3, curr3, curr3]
curr3 = np.array(curr3)
curr4 = np.zeros((3, 4, 5, 0))
for s in [curr2, curr3, curr4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.rot_imagediff(s, mem)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [curr]:
diff = comparing.rot_imagediff(s, mem)
self.assertFalse(diff.shape[1] <= 0)
self.assertTrue(diff.shape[2] == 4)
self.assertFalse(np.any(np.isnan(diff)))
self.assertTrue(is_numeric_array(diff))
self.assertTrue(diff.shape[3] == 1)
self.assertTrue(diff.shape[0] > 0)
self.assertTrue(diff.shape[1] > 0)
def test_rotimagediff_memory(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
mem2 = curr.copy()
mem2[3, 5, 2, 0] = np.nan
mem3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
mem3 = [mem3, mem3, mem3]
mem3 = np.array(mem3)
mem4 = np.zeros((3, 4, 5, 0))
for s in [mem2, mem3, mem4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.rot_imagediff(curr, s)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [mem]:
diff = comparing.rot_imagediff(curr, s)
self.assertFalse(diff.shape[1] <= 0)
self.assertTrue(diff.shape[2] == 4)
self.assertFalse(np.any(np.isnan(diff)))
self.assertTrue(is_numeric_array(diff))
self.assertTrue(diff.shape[3] == 1)
self.assertTrue(diff.shape[0] > 0)
self.assertTrue(diff.shape[1] > 0)
def test_simple_imagediff_curr(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
curr2 = curr.copy()
curr2[3, 5, 2, 0] = np.nan
curr3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
curr3 = [curr3, curr3, curr3]
curr3 = np.array(curr3)
curr4 = np.zeros((3, 4, 5, 0))
for s in [curr2, curr3, curr4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.simple_imagediff(s, mem)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [curr]:
diff = comparing.rot_imagediff(s, mem)
self.assertFalse(diff.shape[1] <= 0)
self.assertTrue(diff.shape[2] == 4)
self.assertFalse(np.any(np.isnan(diff)))
self.assertTrue(is_numeric_array(diff))
self.assertTrue(diff.shape[3] == 1)
self.assertTrue(diff.shape[0] > 0)
self.assertTrue(diff.shape[1] > 0)
def test_diff_optic_flow_memory(self):
curr = processing.scene(self.mydb, rowid=1)
mem = processing.scene(self.mydb, rowid=2)
mem2 = curr.copy()
mem2[3, 5, 2, 0] = np.nan
mem3 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
mem3 = [mem3, mem3, mem3]
mem3 = np.array(mem3)
mem4 = np.zeros((3, 4, 5, 0))
for s in [mem2, mem3, mem4]: # put useless stuff here
with self.assertRaises(Exception) as cm:
comparing.diff_optic_flow(curr, s)
print("wanted exception occured", cm.exception)
# should be working -> check if result is correct
for s in [mem]:
vec = comparing.diff_optic_flow(curr, s)
self.assertFalse(vec.shape[1] == (1, 2))
self.assertFalse(np.any(np.isnan(vec)))
self.assertTrue(is_numeric_array(vec))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment