
package org.ldp4j.http;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.junit.Test;
import org.ldp4j.commons.testing.Utils;

public class DoubleUtilsTest {

	@Test
	public void isUtilityClass() throws Exception {
		assertThat(Utils.isUtilityClass(DoubleUtils.class),equalTo(true));
	}

	@Test
	public void rejectsValuesWithMoreDigitsThanSpecified() throws Exception {
		assertThat(DoubleUtils.hasPrecision(0.1234,3),equalTo(false));
	}

	@Test
	public void acceptsValuesWithLessDigitsThanSpecified() throws Exception {
		assertThat(DoubleUtils.hasPrecision(0.12345678,9),equalTo(true));
	}

	@Test
	public void acceptsValuesWithTheSameDigitsThanSpecified() throws Exception {
		assertThat(DoubleUtils.hasPrecision(0.12345,5),equalTo(true));
	}

	@Test
	public void doesNotRoundValuesWithLessDigitsThanSpecified() throws Exception {
		assertThat(DoubleUtils.limitPrecision(0.12345678,9),equalTo(0.12345678));
	}

	@Test
	public void roundsValuesWithMoreDigitsThanSpecified$roundDown() throws Exception {
		assertThat(DoubleUtils.limitPrecision(0.12345678,3),equalTo(0.123));
	}

	@Test
	public void roundsValuesWithMoreDigitsThanSpecified$roundUp() throws Exception {
		assertThat(DoubleUtils.limitPrecision(0.12345678,5),equalTo(0.12346));
	}

}
