package net.heartshield.sensors;

import junit.framework.TestCase;

import net.heartshield.signal.DVec;
import net.heartshield.signal.IVec;

/**
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-04-09
 */
public class CameraUtilTest extends TestCase {
    private static final double TOL = 1e-6;

    public void testMeanRow() {
        int[] rgb = new int[]{
                1, 10, 50,
                3, 30, 150
        }; // only tests b
        int height = 2;
        int width = 3;

        double[][] expectRgbMean = new double[][]{{0,0,0},{0,0,0},{2.0,20.0,100.0}};
        double[][] rgbMean = CameraUtil.meanRow(rgb, width, height);

        for(int i = 0; i < 3; i++)
            if(!IVec.all(DVec.eqt(rgbMean[i], expectRgbMean[i], TOL)))
                throw new RuntimeException("failed i=" + i);
    }


    public void testMeanCol() {
        int[] rgb = new int[]{
                1,    3,
                10,  30,
                50, 150
        }; // only tests b
        int height = 3;
        int width = 2;

        double[][] expectRgbMean = new double[][]{{0,0,0},{0,0,0},{2.0,20.0,100.0}};
        double[][] rgbMean = CameraUtil.meanCol(rgb, width, height);

        for(int i = 0; i < 3; i++)
            if(!IVec.all(DVec.eqt(rgbMean[i], expectRgbMean[i], TOL)))
                throw new RuntimeException("failed i=" + i);
    }

    public void testStdRow() {
        int[] rgb = new int[]{
                1, 10, 50,
                3, 30, 150
        }; // only tests b
        int height = 2;
        int width = 3;

        double[][] expectRgbStd = new double[][]{{0,0,0},{0,0,0},{1.0,10.0,50.0}};
        double[][] rgbMean = CameraUtil.meanRow(rgb, width, height);
        double[][] rgbStd = CameraUtil.stdRow(rgb, rgbMean, width, height);

        for(int i = 0; i < 3; i++)
            if(!IVec.all(DVec.eqt(rgbStd[i], expectRgbStd[i], TOL)))
                throw new RuntimeException("failed i=" + i);
    }

    public void testStdCol() {
        int[] rgb = new int[]{
                1,    3,
                10,  30,
                50, 150
        }; // only tests b
        int height = 3;
        int width = 2;

        double[][] expectRgbStd = new double[][]{{0,0,0},{0,0,0},{1.0,10.0,50.0}};
        double[][] rgbMean = CameraUtil.meanCol(rgb, width, height);
        double[][] rgbStd = CameraUtil.stdCol(rgb, rgbMean, width, height);

        for(int i = 0; i < 3; i++)
            if(!IVec.all(DVec.eqt(rgbStd[i], expectRgbStd[i], TOL)))
                throw new RuntimeException("failed i=" + i);
    }
}
