<commit_before>/*
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <complex>

#include "otbImageFileReader.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbMacro.h"
#include "itkImageRegionIteratorWithIndex.h"

// Do all comparison in double precision
const double Epsilon = 1.E-6;

template<class TPixel>
bool IsEqual(TPixel output, TPixel expected)
{
  typedef typename itk::NumericTraits<TPixel>::RealType       RealType;

  RealType outputReal   = static_cast<RealType>(output);
  RealType expectedReal = static_cast<RealType>(expected);
  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template<class TPixel>
bool IsEqual(std::complex<TPixel> output, std::complex<TPixel> expected)
{
  typedef typename itk::NumericTraits<std::complex<TPixel> >::RealType       RealType;
  typedef typename itk::NumericTraits<std::complex<TPixel> >::ScalarRealType ScalarRealType;

  RealType outputReal  ( static_cast<ScalarRealType>(output.real())  , static_cast<ScalarRealType>(output.imag()) );
  RealType expectedReal( static_cast<ScalarRealType>(expected.real()), static_cast<ScalarRealType>(expected.imag()) );

  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template<class TInternalPixel>
bool IsEqual(itk::VariableLengthVector<TInternalPixel> output, itk::VariableLengthVector<TInternalPixel> expected)
{
  bool result = true;
  for(unsigned int i = 0; i < output.Size(); ++i)
    {
    result = result && IsEqual(output[i], expected[i]);
    }
  return result;
}


template<class TIndex, class TPixel>
bool TestCompare(TIndex idx, TPixel output, TPixel expected)
{
  std::cout << "PIXEL " << idx << "  -->  "
            << "OUTPUT = "   << output
            << "   ||   "
            << "EXPECTED = " << expected
            << std::endl;

  if (!IsEqual(output, expected))
    {
    std::cerr << "ERROR at position " << idx << ". Got " << output << ", expected " << expected << std::endl;
    return false;
    }
  return true;
}<commit_msg>TEST: less verbose IO tests<commit_after>/*
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <complex>

#include "otbImageFileReader.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbMacro.h"
#include "itkImageRegionIteratorWithIndex.h"

// Do all comparison in double precision
const double Epsilon = 1.E-6;

template<class TPixel>
bool IsEqual(TPixel output, TPixel expected)
{
  typedef typename itk::NumericTraits<TPixel>::RealType       RealType;

  RealType outputReal   = static_cast<RealType>(output);
  RealType expectedReal = static_cast<RealType>(expected);
  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template<class TPixel>
bool IsEqual(std::complex<TPixel> output, std::complex<TPixel> expected)
{
  typedef typename itk::NumericTraits<std::complex<TPixel> >::RealType       RealType;
  typedef typename itk::NumericTraits<std::complex<TPixel> >::ScalarRealType ScalarRealType;

  RealType outputReal  ( static_cast<ScalarRealType>(output.real())  , static_cast<ScalarRealType>(output.imag()) );
  RealType expectedReal( static_cast<ScalarRealType>(expected.real()), static_cast<ScalarRealType>(expected.imag()) );

  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template<class TInternalPixel>
bool IsEqual(itk::VariableLengthVector<TInternalPixel> output, itk::VariableLengthVector<TInternalPixel> expected)
{
  bool result = true;
  for(unsigned int i = 0; i < output.Size(); ++i)
    {
    result = result && IsEqual(output[i], expected[i]);
    }
  return result;
}


template<class TIndex, class TPixel>
bool TestCompare(TIndex idx, TPixel output, TPixel expected)
{
  otbLogMacro(Debug, << "PIXEL " << idx << "  -->  "
            << "OUTPUT = "   << output
            << "   ||   "
            << "EXPECTED = " << expected
            << std::endl);

  if (!IsEqual(output, expected))
    {
    std::cerr << "ERROR at position " << idx << ". Got " << output << ", expected " << expected << std::endl;
    return false;
    }
  return true;
}
{'fraction_non_alphanumeric': 0.12618963694043003, 'fraction_numerical': 0.005287275290800141, 'mean_word_length': 4.192131747483989, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6813869', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1689, 'n_words': 484}