Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 03.11.2011, 01:06   #1
Julila
Форумчанин
 
Регистрация: 04.01.2011
Сообщений: 125
По умолчанию Тестирование программы ява

Тестировала программу, но у меня в тестировании метода CreateY выходят большие числа. как можно их сделать более приблеженными к десятым?
код
Код:
package javaapplication5;
import static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
       Main program = new Main();
        program.run();


    }   
    private double[] arrayX;
    private double[] arrayY;
    double  EPS= 1.0-6;

    public void run() {
        double start = 0.2;
        double end = 2.8;
        double step = 0.4;
    arrayX = createX(start, end, step);
    arrayY = createY(arrayX);
    Print();}


    private void Print(){
        System.out.printf("MinY =: %6.3f\n", arrayY[MinY(arrayY)]);
        System.out.println("Number minY: " + MinY(arrayY));
        System.out.printf("MaxY = %6.3f\n", arrayY[MaxY(arrayY)]);
        System.out.println("Number maxY: " + MaxY(arrayY));
        System.out.printf("Sum = %6.3f\n", sum(arrayY));
        System.out.printf("arith mean у = %6.3f\n", arithMean(arrayY));}

    double[] createX( double start, double end, double step) {
        double[] res = new double[size(start,end,step)];
        for (int i = 0; i < res.length; i++) {
            res[i] = start + i * step;
        }      
        return res;
    }

     double[] createY(double[] arrayX) {
        double[] res = new double[arrayX.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = amount(arrayX[i]);

        }
        return res;
    }

    double amount(double x) {
        final double a=2.3;
        if (x > 2.3 ) {
            return 1.5*a*cos(pow(x,2));
        } 
        else if (x<0.3 ) {
            return 3*a*tan(x);
        }
        else {
            return pow((x-2),2)+6*a;
        }
    }

    int size(double start, double end, double step) {
        return (int) Math.round((end - start) / step) + 1;
    }

     int MinY(double[] arrayY) {
        double miny =  arrayY[0];
        int j = 0;
        for (int i = 0; i < arrayY.length; ++i) {
            if (arrayY[i] < miny) {
                miny = arrayY[i];
                j = i;
            }
        }
        return j;
    }

     int MaxY(double[] arrayY) {
        double maxy = arrayY[0];
        int j = 0;
        for (int i = 0; i < arrayY.length; ++i) {
            if (arrayY[i] > maxy) {
                maxy = arrayY[i];
                j = i;
            }
        }
        return j;
    }

    double sum(double[] array) {
        double sum = 0;
        for (int i = 0; i < array.length; ++i) {
            sum += array[i];
        }
        return sum;
    }

     double arithMean(double[] array) {
        return sum(array) / array.length;
    }
}
тестирование
Julila вне форума Ответить с цитированием
Старый 03.11.2011, 01:06   #2
Julila
Форумчанин
 
Регистрация: 04.01.2011
Сообщений: 125
По умолчанию

Код:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication5;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author julia
 */
public class MainTest {
    double EPS=1.0-1;

    public MainTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

  
    @Test
    public void testRun() {
        System.out.println("run");
        Main instance = new Main();
        instance.run();
    }

    /**
     * Test of createX method, of class Main.
     */
    @Test
    public void testCreateX() {
        System.out.println("createX");
        double start = 2.0;
        double end = 5.00;
        double step = 0.005;
        Main instance = new Main();
        double expResult = 601;
        double expAmount = 3.665;
        double[] result = instance.createX(start, end, step);
        assertEquals(expResult , result.length, EPS);
        assertEquals(expAmount, result[333], EPS);

    }

    /**
     * Test of createY method, of class Main.
     */
    @Test
    public void testCreateY() {
        System.out.println("createY");
        double[] arrayX = {0.2, 2, 3};
        Main instance = new Main();
        double[] expResult = {1.39869924500984, 13.799999999999999, -3.1433994035021353};
        double[] result = instance.createY(arrayX);
        for (int i=0; i<expResult.length; i++){
        assertEquals(expResult[i], result[i], EPS);
    }
    }

    /**
     * Test of amount method, of class Main.
     */
    @Test
    public void testAmount() {
        System.out.println("amount");
        double x = 1.0;
        Main instance = new Main();
        double expResult = 13.8;
        double result = instance.amount(x);
        assertEquals(expResult, result, 13.8);
    }

    /**
     * Test of size method, of class Main.
     */
    @Test
    public void testSize() {
        System.out.println("size");
        double start = 1.0;
        double end = 5.0;
        double step = 1.0;
        Main instance = new Main();
        int expResult = 5;
        int result = instance.size(start, end, step);
        assertEquals(expResult, result);
    }

    /**
     * Test of MinY method, of class Main.
     */
    @Test
    public void testMinY() {
        System.out.println("MinY");
        double[] arrayY = {1.4 , 4.5, 6.5, 3.6 , 0.4 };
        Main instance = new Main();
        double expResult = 0.4;
        int result = instance.MinY(arrayY);
        assertEquals(expResult, result, 4);
    }

    /**
     * Test of MaxY method, of class Main.
     */
    @Test
    public void testMaxY() {
        System.out.println("MaxY");
        double[] arrayY = {9.0, 8.8 , 7.9 , 0.7 , 6.8};
        Main instance = new Main();
        double expResult = 9.0;
        int result = instance.MaxY(arrayY);
        assertEquals(expResult , result, 9.0 );
    }

    /**
     * Test of sum method, of class Main.
     */
    @Test
    public void testSum() {
        System.out.println("sum");
        double[] array = {1.0 , 4.6 , 5.4 };
        Main instance = new Main();
        double expResult = 11.0;
        double result = instance.sum(array);
        assertEquals(expResult, result, 11.0);
    }

    /**
     * Test of arithMean method, of class Main.
     */
    @Test
    public void testArithMean() {
        System.out.println("arithMean");
        double[] array = {1.0 , 3.0 , 2.0, 6.0};
        Main instance = new Main();
        double expResult = 4.0;
        double result = instance.arithMean(array);
        assertEquals(expResult, result, 4.0);
    }

}
Julila вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
ещё одна прога для студентов, тестирование с помощью программы ADSoft Tester - взлом пароля rpy3uH Софт 70 23.12.2021 21:47
Произвести тестирование программы способом тестирования потоков данных. xarti Фриланс 4 17.01.2011 23:06
Делфи, Ява Скрипты или Приложения, Программы? alex198555 Работа с сетью в Delphi 0 09.08.2010 00:28
тестирование программы. Chudo4258 Помощь студентам 9 05.03.2010 12:27
Нужен ява програмист для разработки ява сервера aion roverik Свободное общение 1 19.12.2009 17:14