Java-Programming/AufgabenBlatt7/src/Aufgabe3.java

48 lines
1.5 KiB
Java

import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Generic test class for implementing and testing a crude round function
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Aufgabe3 {
/**
* Divides the numbers and returns the rounded result
* @param numerator the numerator
* @param denominator the denominator
* @return the rounded result of numerator / denominator
*/
private static double rounded(double numerator, double denominator) {
return Math.floor(numerator / denominator + 0.5);
}
@Test
public void testRoundUp() {
assertEquals(3.0, Aufgabe3.rounded(14.0, 5.0), 0.0);
}
@Test
public void testRoundDown() {
assertEquals(3.0, Aufgabe3.rounded(16.0, 5.0), 0.0);
}
@Test
public void testExact() {
assertEquals(3.0, Aufgabe3.rounded(18.0, 6.0), 0.0);
}
}