MLECO-1868: Code static analyzer warnings fixes

Signed-off-by: alexander <alexander.efremov@arm.com>
Change-Id: Ie423e9cad3fabec6ab077ded7236813fe4933dea
diff --git a/tests/common/ClassifierTests.cc b/tests/common/ClassifierTests.cc
index f08a09a..a04e4c2 100644
--- a/tests/common/ClassifierTests.cc
+++ b/tests/common/ClassifierTests.cc
@@ -18,6 +18,31 @@
 
 #include <catch.hpp>
 
+
+template<typename T>
+void test_classifier_result(std::vector<std::pair<uint32_t, T>>& selectedResults, T defaultTensorValue) {
+    const int dimArray[] = {1, 1001};
+    std::vector <std::string> labels(1001);
+    std::vector<T> outputVec(1001, defaultTensorValue);
+    TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
+    TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(outputVec.data(), dims, 1, 0);
+    TfLiteTensor* outputTensor = &tfTensor;
+
+    std::vector <arm::app::ClassificationResult> resultVec;
+
+    for (auto& selectedResult : selectedResults) {
+        outputVec[selectedResult.first] = selectedResult.second;
+    }
+
+    arm::app::Classifier classifier;
+    REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 5));
+    REQUIRE(5 == resultVec.size());
+
+    for (size_t i = 0; i < resultVec.size(); ++i) {
+        REQUIRE(resultVec[i].m_labelIdx == selectedResults[i].first);
+    }
+}
+
 TEST_CASE("Common classifier")
 {
     SECTION("Test invalid classifier")
@@ -28,49 +53,31 @@
         REQUIRE(!classifier.GetClassificationResults(outputTens, resultVec, {}, 5));
     }
 
-    SECTION("Test valid classifier UINT8")
+    SECTION("Test classification results")
     {
-        const int dimArray[] = {1, 1001};
-        std::vector <std::string> labels(1001);
-        std::vector <uint8_t> outputVec(1001);
-        TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
-        TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
-                outputVec.data(), dims, 1, 0, "test");
-        TfLiteTensor* outputTensor = &tfTensor;
-        std::vector <arm::app::ClassificationResult> resultVec;
-        arm::app::Classifier classifier;
-        REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 5));
-        REQUIRE(5 == resultVec.size());
-    }
+        SECTION("uint8") {
+            /* Set the top five results <position, score>. */
+            std::vector<std::pair<uint32_t, uint8_t>> selectedResults {
+                    {1000, 10}, {15, 9}, {0, 8}, {20, 7}, {10, 7} };
 
-    SECTION("Get classification results")
-    {
-        const int dimArray[] = {1, 1001};
-        std::vector <std::string> labels(1001);
-        std::vector<uint8_t> outputVec(1001, static_cast<uint8_t>(5));
-        TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
-        TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
-                outputVec.data(), dims, 1, 0, "test");
-        TfLiteTensor* outputTensor = &tfTensor;
-
-        std::vector <arm::app::ClassificationResult> resultVec;
-
-        /* Set the top five results. */
-        std::vector<std::pair<uint32_t, uint8_t>> selectedResults {
-                {0, 8}, {20, 7}, {10, 7}, {15, 9}, {1000, 10}};
-
-        for (size_t i = 0; i < selectedResults.size(); ++i) {
-            outputVec[selectedResults[i].first] = selectedResults[i].second;
+            test_classifier_result(selectedResults, static_cast<uint8_t>(5));
         }
 
-        arm::app::Classifier classifier;
-        REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 5));
-        REQUIRE(5 == resultVec.size());
+        SECTION("int8") {
+            /* Set the top five results <position, score>. */
+            std::vector<std::pair<uint32_t, int8_t>> selectedResults {
+                    {1000, 10}, {15, 9}, {0, 8}, {20, -7}, {10, -7} };
 
-        REQUIRE(resultVec[0].m_labelIdx == 1000);
-        REQUIRE(resultVec[1].m_labelIdx == 15);
-        REQUIRE(resultVec[2].m_labelIdx == 0);
-        REQUIRE(resultVec[3].m_labelIdx == 20);
-        REQUIRE(resultVec[4].m_labelIdx == 10);
+            test_classifier_result(selectedResults, static_cast<int8_t>(-100));
+        }
+
+        SECTION("float") {
+            /* Set the top five results <position, score>. */
+            std::vector<std::pair<uint32_t, float>> selectedResults {
+                    {1000, 10.9f}, {15, 9.8f}, {0, 8.7f}, {20, -7.0f}, {10, -7.1f} };
+
+            test_classifier_result(selectedResults, -100.0f);
+        }
+
     }
 }
diff --git a/tests/use_case/asr/AsrClassifierTests.cc b/tests/use_case/asr/AsrClassifierTests.cc
index 7c71912..12523aa 100644
--- a/tests/use_case/asr/AsrClassifierTests.cc
+++ b/tests/use_case/asr/AsrClassifierTests.cc
@@ -35,7 +35,7 @@
     std::vector <uint8_t> outputVec(7134);
     TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
     TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
-                                outputVec.data(), dims, 1, 0, "test");
+                                outputVec.data(), dims, 1, 0);
     TfLiteTensor* outputTensor = &tfTensor;
     std::vector <arm::app::ClassificationResult> resultVec;
     arm::app::AsrClassifier classifier;
@@ -51,7 +51,7 @@
     std::vector<uint8_t> outputVec(150, static_cast<uint8_t>(1));
     TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
     TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
-                                outputVec.data(), dims, 1, 0, "test");
+                                outputVec.data(), dims, 1, 0);
     TfLiteTensor* outputTensor = &tfTensor;
 
     std::vector <arm::app::ClassificationResult> resultVec(10);
diff --git a/tests/use_case/asr/AsrFeaturesTests.cc b/tests/use_case/asr/AsrFeaturesTests.cc
index 9401f40..59fe29b 100644
--- a/tests/use_case/asr/AsrFeaturesTests.cc
+++ b/tests/use_case/asr/AsrFeaturesTests.cc
@@ -25,30 +25,27 @@
 
 class TestPreprocess : public arm::app::audio::asr::Preprocess {
 public:
-    TestPreprocess()
-    : arm::app::audio::asr::Preprocess(0,0,0,0)
-    {}
 
-    bool ComputeDeltas(arm::app::Array2d<float>& mfcc,
+    static bool ComputeDeltas(arm::app::Array2d<float>& mfcc,
                        arm::app::Array2d<float>& delta1,
                        arm::app::Array2d<float>& delta2)
     {
-        return this->_ComputeDeltas(mfcc, delta1, delta2);
+        return Preprocess::ComputeDeltas(mfcc, delta1, delta2);
     }
 
-    float GetMean(arm::app::Array2d<float>& vec)
+    static float GetMean(arm::app::Array2d<float>& vec)
     {
-        return this->_GetMean(vec);
+        return Preprocess::GetMean(vec);
     }
 
-    float GetStdDev(arm::app::Array2d<float>& vec, const float mean)
+    static float GetStdDev(arm::app::Array2d<float>& vec, const float mean)
     {
-       return this->_GetStdDev(vec, mean);
+       return Preprocess::GetStdDev(vec, mean);
     }
 
-    void NormaliseVec(arm::app::Array2d<float>& vec)
+    static void NormaliseVec(arm::app::Array2d<float>& vec)
     {
-        return this->_NormaliseVec(vec);
+        return Preprocess::NormaliseVec(vec);
     }
 };
 
@@ -86,7 +83,6 @@
 
 TEST_CASE("Floating point asr features calculation", "[ASR]")
 {
-    TestPreprocess tp;
 
     SECTION("First and second diff")
     {
@@ -109,7 +105,7 @@
         std::fill(delta1Buf.begin(), delta1Buf.end(), 0.f);
         std::fill(delta2Buf.begin(), delta2Buf.end(), 0.f);
 
-        tp.ComputeDeltas(mfccBuf, delta1Buf, delta2Buf);
+        TestPreprocess::ComputeDeltas(mfccBuf, delta1Buf, delta2Buf);
 
         /* First 4 and last 4 values are different because we pad AFTER diff calculated. */
         for (size_t i = 0; i < numMfccFeats; ++i) {
@@ -136,37 +132,37 @@
                                                 {-1, -2}};
         arm::app::Array2d<float> mean1(2,2); /* {{1, 2},{-1, -2}} */
         populateArray2dWithVectorOfVector(mean1vec, mean1);
-        REQUIRE(0 == Approx(tp.GetMean(mean1)));
+        REQUIRE(0 == Approx(TestPreprocess::GetMean(mean1)));
 
         arm::app::Array2d<float> mean2(2, 2);
         std::fill(mean2.begin(), mean2.end(), 0.f);
-        REQUIRE(0 == Approx(tp.GetMean(mean2)));
+        REQUIRE(0 == Approx(TestPreprocess::GetMean(mean2)));
 
         arm::app::Array2d<float> mean3(3,3);
         std::fill(mean3.begin(), mean3.end(), 1.f);
-        REQUIRE(1 == Approx(tp.GetMean(mean3)));
+        REQUIRE(1 == Approx(TestPreprocess::GetMean(mean3)));
     }
 
     SECTION("Std")
     {
         arm::app::Array2d<float> std1(2, 2);
         std::fill(std1.begin(), std1.end(), 0.f); /* {{0, 0}, {0, 0}} */
-        REQUIRE(0 == Approx(tp.GetStdDev(std1, 0)));
+        REQUIRE(0 == Approx(TestPreprocess::GetStdDev(std1, 0)));
 
         std::vector<std::vector<float>> std2vec{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 0}};
         arm::app::Array2d<float> std2(2,5);
         populateArray2dWithVectorOfVector(std2vec, std2);
-        const float mean = tp.GetMean(std2);
-        REQUIRE(2.872281323 == Approx(tp.GetStdDev(std2, mean)));
+        const float mean = TestPreprocess::GetMean(std2);
+        REQUIRE(2.872281323 == Approx(TestPreprocess::GetStdDev(std2, mean)));
 
         arm::app::Array2d<float> std3(2,2);
         std::fill(std3.begin(), std3.end(), 1.f); /* std3{{1, 1}, {1, 1}}; */
-        REQUIRE(0 == Approx(tp.GetStdDev(std3, 1)));
+        REQUIRE(0 == Approx(TestPreprocess::GetStdDev(std3, 1)));
     }
 
     SECTION("Norm") {
         auto checker = [&](arm::app::Array2d<float>& d, std::vector<float>& g) {
-            tp.NormaliseVec(d);
+            TestPreprocess::NormaliseVec(d);
             std::vector<float> d_vec(d.begin(), d.end());
             REQUIRE_THAT(g, Catch::Approx(d_vec));
         };