Package testing

Source Code of testing.GaussianTest

package testing;

import static org.junit.Assert.*;

import org.junit.Test;

import util.Gaussian;
import util.Util;

public class GaussianTest
{
  @Test
  public void testGaussian()
  {
    Gaussian g = new Gaussian();
   
    assert(g.getPDF() == null && g.getRandomVar() == null && g.isEmpty());
  }

  @Test
  public void testGaussianDouble()
  {
    double stdev = 25.00;
    Gaussian g = new Gaussian(stdev);
   
    assert(    g.getMean() == 1+stdev*3
        && g.isEmpty() == false
        && g.getSize() == Gaussian.DEFAULT_GAUSSIAN_SIZE
        && g.getRandomVar().length == g.getPDF().length);
  }

  @Test
  public void testGaussianDoubleArray()
  {
    double[] zscores = {0.1, 1.0, 1.5, 2.0, 2.5, 3.0};
   
    Gaussian g = new Gaussian(zscores);
   
    assert(    g.isEmpty() == false
        && Util.compareArraysByValue(g.getPDF(),zscores)
        && g.getSize() == zscores.length
        && Util.arrayMean(zscores) == g.getMean()
        && Util.standardDeviation(zscores) == g.getStandardDeviation());
  }

  @Test
  public void testGaussianIntDoubleDoubleDouble()
  {
    int size = 200;
    double mean = 100;
    double stdev = 20;
    double multiplier = 1000;
   
    Gaussian g = new Gaussian(size,mean,stdev,multiplier);
   
    assert(    g.isEmpty() == false
        && g.getSize() == size
        && g.getMean() == mean
        && g.getStandardDeviation() == stdev
        && g.getRandomValue() % multiplier <= multiplier);
  }

  @Test
  public void testGaussianIntDoubleDouble()
  {
    int size = 200;
    double mean = 100;
    double stdev = 20;
   
    Gaussian g = new Gaussian(size,mean,stdev);
   
    assert(    g.isEmpty() == false
        && g.getSize() == size
        && g.getMean() == mean
        && g.getStandardDeviation() == stdev);
  }

  @Test
  public void testGaussianIntDouble()
  {
    int size = 200;
    double stdev = 20;
   
    Gaussian g = new Gaussian(size,stdev);
   
    assert(    g.isEmpty() == false
        && g.getSize() == size
        && g.getStandardDeviation() == stdev);
  }

  @Test
  public void testGaussianDoubleIntDouble()
  {
    int size = 200;
    double stdev = 20;
    double multiplier = 1000;
   
    Gaussian g = new Gaussian(multiplier,size,stdev);
   
    assert(    g.isEmpty() == false
        && g.getSize() == size
        && g.getStandardDeviation() == stdev
        && g.getRandomValue() % multiplier <= multiplier);
  }

  @Test
  public void testGetRandomVar()
  {
    int size = 200;
    double mean = 100;
    double stdev = 20;
    double multiplier = 1000;
   
    Gaussian g = new Gaussian(size,mean,stdev,multiplier);
   
    assert( Util.arrayContains(g.getPDF(), g.getRandomValue()));
  }

  @Test
  public void testGetPDF()
  {
    double[] zscores = {0.1, 1.0, 1.5, 2.0, 2.5, 3.0};
   
    Gaussian g = new Gaussian(zscores);
   
    assert( Util.compareArraysByValue(g.getPDF(),zscores));
  }

  @Test
  public void testGetNumRandomZScores()
  {
    int numZScores = 10;
    int size = 200;
    double stdev = 20;
    double multiplier = 1000;
   
    Gaussian g = new Gaussian(size,stdev,multiplier);
   
    double[][] randomZScores = g.getNumRandomZScores(numZScores);
   
    assert(    Util.arrayContains(g.getRandomVar(), randomZScores[0])
        && Util.arrayContains(g.getPDF(), randomZScores[1]));
  }

  @Test
  public void testGetRandomValue()
  {
    int size = 200;
    double stdev = 20;
    double multiplier = 1000;
   
    Gaussian g = new Gaussian(size,stdev,multiplier);
   
    assert ( Util.arrayContains(g.getPDF(), g.getRandomValue()));
  }

  @Test
  public void testIsEmpty()
  {
    Gaussian g = new Gaussian();
   
    assert (g.isEmpty());
  }

  @Test
  public void testScaleZScores()
  {
    double[] zscores = {0.1, 1.0, 1.5, 2.0, 2.5, 3.0};
    double scale = 100;
   
    Gaussian g = new Gaussian(zscores);
   
    for (int x=0; x < zscores.length; x++) zscores[x] *= scale;
   
    g.scaleZScores(scale);
   
    assert( Util.compareArraysByValue(g.getPDF(),zscores));
  }

  @Test
  public void testGetMean()
  {
    double[] zscores = {0.1, 1.0, 1.5, 2.0, 2.5, 3.0};
    double mean = Util.arrayMean(zscores);
   
    Gaussian g = new Gaussian(zscores);
   
    assert( g.getMean() == mean);
  }

  @Test
  public void testGetStandardDeviation()
  {
    double[] zscores = {0.1, 1.0, 1.5, 2.0, 2.5, 3.0};
    double stdev = Util.standardDeviation(zscores);
   
    Gaussian g = new Gaussian(zscores);
   
    assert( g.getStandardDeviation() == stdev);
  }

}
TOP

Related Classes of testing.GaussianTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.