package ru;

/**
 * Реализуем тест для класса Calculator
 * @author Aleksandr Belov
 * @date 23.09.2016
 */


import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

public class CalculatorTest {

	/*
	 * Тест сложения
	 */

	@Test
	public void whenAddShouldSummateIt() {
		final Calculator calc = new Calculator();
		calc.add(1, 1);
		final double result = calc.getResult();
		assertThat(result, is(2d));
	}

	/*
	 * Тест деления
	 */

	@Test
	public void whenDivShouldDivideIt() {
		final Calculator calc = new Calculator();
		calc.div(2, 2);
		final double result = calc.getResult();
		assertThat(result, is(1d));
	}

	/*
	 * Тест проверки исключения - деления на 0
	 */

	@Test(expected=ArithmeticException.class)
	public void whenDivShouldNotDivideByZero() {
		final Calculator calc = new Calculator();
		calc.div(1, 0);
	}

	/*
	 * Тест вычитания
	 */

	@Test
	public void whenSubstractShouldSubstract() {
		final Calculator calc = new Calculator();
		calc.substract(1, 1);
		final double result = calc.getResult();
		assertThat(result, is(0d));
	}

	/*
	 * Тест умножения
	 */

	@Test
	public void whenMultiplyShouldMultiply() {
		final Calculator calc = new Calculator();
		calc.multiply(3, 3);
		final double result = calc.getResult();
		assertThat(result, is(9d));
	}
}
