python/tests/test_cvec.py: more tests
authorPaul Brossier <piem@piem.org>
Mon, 2 May 2016 12:56:40 +0000 (14:56 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 2 May 2016 12:56:40 +0000 (14:56 +0200)
python/tests/test_cvec.py

index 00751c7..a645a14 100755 (executable)
@@ -46,6 +46,38 @@ class aubio_cvec_test_case(TestCase):
         assert_equal(spec.phas[39:-1], -np.pi)
         assert_equal(spec.norm, 0)
 
+    def test_assign_cvec_with_other_cvec(self):
+        """ check dest cvec is still reachable after source was deleted """
+        spec = cvec(1024)
+        a = np.random.rand(1024/2+1).astype(float_type)
+        b = np.random.rand(1024/2+1).astype(float_type)
+        spec.norm = a
+        spec.phas = b
+        new_spec = spec
+        del spec
+        assert_equal(a, new_spec.norm)
+        assert_equal(b, new_spec.phas)
+        assert_equal(id(a), id(new_spec.norm))
+        assert_equal(id(b), id(new_spec.phas))
+
+    def test_pass_to_numpy(self):
+        spec = cvec(1024)
+        norm = spec.norm
+        phas = spec.phas
+        del spec
+        new_spec = cvec(1024)
+        new_spec.norm = norm
+        new_spec.phas = phas
+        assert_equal(norm, new_spec.norm)
+        assert_equal(phas, new_spec.phas)
+        assert_equal(id(norm), id(new_spec.norm))
+        assert_equal(id(phas), id(new_spec.phas))
+        del norm
+        del phas
+        assert_equal(new_spec.norm, 0.)
+        assert_equal(new_spec.phas, 0.)
+        del new_spec
+
 if __name__ == '__main__':
     from nose2 import main
     main()