test_stlcontainers.pyΒΆ

Download this file.

"""Tests the part of stlconverters that is accessible from Python."""
###################
###  WARNING!!! ###
###################
# This file has been autogenerated
from __future__ import print_function
from unittest import TestCase
import nose

from nose.tools import assert_equal, assert_not_equal, assert_raises, raises, \
    assert_almost_equal, assert_true, assert_false, assert_in

from numpy.testing import assert_array_equal, assert_array_almost_equal

import os
import numpy  as np
from collections import Container, Mapping

from mypack import stlcontainers


# Vector Str


# SetUInt
def test_set_uint():
    s = stlcontainers.SetUInt()
    s.add(1)
    assert_true(1 in s)
    assert_true(4294967295 not in s)

    s = stlcontainers.SetUInt([1, 65, 4294967295])
    assert_true(65 in s)
    assert_true(42 not in s)



# MapIntDouble
def test_map_int_double():
    m = stlcontainers.MapIntDouble()
    uismap = isinstance(-65.5555, Mapping) 
    m[1] = 18
    m[42] = -65.5555
    import pprint
    pprint.pprint(m)
    assert_equal(len(m), 2)
    if uismap:
        for key, value in m[42].items():
            print(key, value, -65.5555[key])
            if isinstance(value, np.ndarray):
                assert_almost_equal(value, -65.5555[key])
            else:
                assert_equal(value, -65.5555[key])
    else:
        assert_almost_equal(m[42], -65.5555)

    m = stlcontainers.MapIntDouble({-65: 42.42, 18: 1.0})
    assert_equal(len(m), 2)
    if uismap:
        for key, value in m[-65].items():
            if isinstance(value, np.ndarray):
                print(key, value, 42.42[key])
                assert_almost_equal(value, 42.42[key])
            else:
                assert_equal(value, 42.42[key])
    else:
        assert_almost_equal(m[-65], 42.42)

    n = stlcontainers.MapIntDouble(m, False)
    assert_equal(len(n), 2)
    if uismap:
        for key, value in m[-65].items():
            if isinstance(value, np.ndarray):
                assert_almost_equal(value, 42.42[key])
            else:
                assert_equal(value, 42.42[key])
    else:
        assert_almost_equal(m[-65], 42.42)

    # points to the same underlying map
    n[42] = -65.5555
    if uismap:
        for key, value in m[42].items():
            if isinstance(value, np.ndarray):
                assert_almost_equal(value, -65.5555[key])
            else:
                assert_equal(value, -65.5555[key])
    else:
        assert_almost_equal(m[42], -65.5555)



if __name__ == '__main__':
    nose.run()