Maria@18
|
1 # -*- coding: utf-8 -*-
|
Maria@18
|
2 """
|
Maria@18
|
3 Created on Fri Sep 1 19:11:52 2017
|
Maria@18
|
4
|
Maria@18
|
5 @author: mariapanteli
|
Maria@18
|
6 """
|
Maria@18
|
7
|
Maria@18
|
8 import pytest
|
Maria@18
|
9
|
Maria@18
|
10 import numpy as np
|
Maria@18
|
11
|
Maria@18
|
12 import scripts.map_and_average as map_and_average
|
Maria@18
|
13
|
Maria@18
|
14
|
Maria@18
|
15 def test_remove_inds():
|
Maria@18
|
16 labels = np.array(['a', 'a', 'b', 'unknown'])
|
Maria@18
|
17 features = np.array([[0, 1], [0,2], [0, 3], [0, 4]])
|
Maria@18
|
18 audiolabels = np.array(['a', 'b', 'c', 'd'])
|
Maria@18
|
19 features, labels, audiolabels = map_and_average.remove_inds(features, labels, audiolabels)
|
Maria@18
|
20 assert len(features) == 3 and len(labels) == 3 and len(audiolabels) == 3
|
Maria@18
|
21
|
Maria@18
|
22
|
Maria@18
|
23 def test_remove_inds():
|
Maria@18
|
24 labels = np.array(['a', 'a', 'b', 'unknown'])
|
Maria@18
|
25 features = np.array([[0, 1], [0,2], [0, 3], [0, 4]])
|
Maria@18
|
26 audiolabels = np.array(['a', 'b', 'c', 'd'])
|
Maria@18
|
27 features, labels, audiolabels = map_and_average.remove_inds(features, labels, audiolabels)
|
Maria@18
|
28 features_true = np.array([[0, 1], [0,2], [0, 3]])
|
Maria@18
|
29 assert np.array_equal(features, features_true)
|
Maria@18
|
30
|
Maria@18
|
31
|
Maria@18
|
32 def test_averageframes():
|
Maria@18
|
33 classlabels = np.array(['a', 'a', 'b', 'b', 'b'])
|
Maria@18
|
34 features = np.array([[0, 1], [0,2], [0, 1], [1, 1], [2, 1]])
|
Maria@18
|
35 audiolabels = np.array(['a', 'a', 'b', 'b', 'b'])
|
Maria@18
|
36 feat, audio, labels = map_and_average.averageframes(features, audiolabels, classlabels)
|
m@30
|
37 feat_true = np.array([[0, 1.5], [1, 1]])
|
m@62
|
38 assert np.array_equal(feat, feat_true)
|
m@62
|
39
|
m@62
|
40
|
m@62
|
41 def test_limit_to_n_seconds():
|
m@62
|
42 X = np.random.randn(10, 3)
|
m@62
|
43 Y = np.random.randn(10)
|
m@62
|
44 Yaudio = np.concatenate([np.repeat('a', 7), np.repeat('b', 3)])
|
m@62
|
45 Xn, Yn, Yaudion = map_and_average.limit_to_n_seconds([X, Y, Yaudio], n_sec=3.0, win_sec=0.5)
|
m@62
|
46 Yaudion_true = np.concatenate([np.repeat('a', 5), np.repeat('b', 3)])
|
m@62
|
47 assert np.array_equal(Yaudion_true, Yaudion) and len(Xn)==len(Yn) and len(Yn)==len(Yaudion) |