import numpy as np

from enmapbox.exampledata import enmap, enmap_srf_library
from enmapboxprocessing.algorithm.spectralresamplingbyresponsefunctionlibraryalgorithm import \
    SpectralResamplingByResponseFunctionLibraryAlgorithm
from enmapboxprocessing.rasterreader import RasterReader
from enmapboxprocessing.test.algorithm.testcase import TestCase


class TestSpectralResamplingByResponseFunctionLibraryAlgorithmBase(TestCase):

    def test(self):
        alg = SpectralResamplingByResponseFunctionLibraryAlgorithm()
        parameters = {
            alg.P_RASTER: enmap,
            alg.P_LIBRARY: enmap_srf_library,
            alg.P_OUTPUT_RASTER: self.filename('resampled.tif')
        }
        result = self.runalg(alg, parameters)
        self.assertEqual(14908146678, np.sum(RasterReader(result[alg.P_OUTPUT_RASTER]).array(), dtype=float))
