/
shvidkuli
/
kkrjava
Обзор
Документация
Войти
/
shvidkuli
/
kkrjava
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/test/java/com/montecarlo/tests/FigureDebfTest.java
161 строка
5 KB
kroc400
first_commit
30 апр 2026, 22:44
30 апр 2026, 22:44
2347fdb
Код
Авторство
О чём код?
package com.montecarlo.tests; import com.montecarlo.geometry.Arc; import com.montecarlo.geometry.FigureDebf; import com.montecarlo.geometry.Point; import com.montecarlo.geometry.Triangle; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; /** * Unit tests for {@link FigureDebf} — the composite figure "debf". * * <h3>Default geometry</h3> * <pre> * Rectangle ABCD = [0,4]×[0,4] * B=(4,0) E=(4,2) F=(2,0) D=(0,4) * * Triangle BEF : area = 2 * Semicircle : centre=(3,1), r=√2, D-side, area = π * Total : 2 + π ≈ 5.14159265… * * The two components are on opposite sides of chord FE (line y = x − 2): * Triangle BEF is on the B-side (x − y ≥ 2) * Semicircle is on the D-side (x − y ≤ 2) * → zero overlap → areas add directly. * </pre> */ public class FigureDebfTest { private FigureDebf figure; @Before public void setUp() { Triangle triangle = new Triangle( new Point(4, 0), // B new Point(4, 2), // E new Point(2, 0) // F ); Arc arc = new Arc( new Point(3, 1), // centre = midpoint(F, E) Math.sqrt(2), // radius = |FE| / 2 new Point(0, 4) // D — reference towards D-side ); figure = new FigureDebf(triangle, arc); } // ----------------------------------------------------------------------- // Analytical area // ----------------------------------------------------------------------- @Test public void testAnalyticalArea() { assertEquals(2 + Math.PI, figure.analyticalArea(), 1e-12); } @Test public void testTriangleArea() { assertEquals(2.0, figure.getTriangle().analyticalArea(), 1e-12); } @Test public void testSemicircleArea() { assertEquals(Math.PI, figure.getArc().analyticalArea(), 1e-12); } // ----------------------------------------------------------------------- // contains — triangle interior // ----------------------------------------------------------------------- @Test public void testContainsCentroidBEF() { // Centroid of BEF: (10/3, 2/3) — inside the triangle assertTrue(figure.contains(new Point(10.0 / 3, 2.0 / 3))); } @Test public void testContainsVertexB() { assertTrue(figure.contains(new Point(4, 0))); } // ----------------------------------------------------------------------- // contains — semicircle interior // ----------------------------------------------------------------------- @Test public void testContainsSemicircleInterior() { // (2.5, 1.5): inside the semicircle assertTrue(figure.contains(new Point(2.5, 1.5))); } @Test public void testContainsSemicircleLeftExtreme() { // (3−√2, 1): leftmost point of the semicircle assertTrue(figure.contains(new Point(3 - Math.sqrt(2), 1))); } // ----------------------------------------------------------------------- // contains — shared boundary (chord FE) // ----------------------------------------------------------------------- @Test public void testContainsMidpointOfChordFE() { // (3, 1) is the centre of the arc AND midpoint of hypotenuse EF → boundary of both assertTrue(figure.contains(new Point(3, 1))); } // ----------------------------------------------------------------------- // contains — points outside // ----------------------------------------------------------------------- @Test public void testNotContainsOrigin() { assertFalse(figure.contains(new Point(0, 0))); } @Test public void testNotContainsTopLeft() { assertFalse(figure.contains(new Point(0, 4))); // D is a reference, not inside the figure } @Test public void testNotContainsFarPoint() { assertFalse(figure.contains(new Point(10, 10))); } @Test public void testNotContainsAboveTriangleAndOutsideSemicircle() { // (1, 3): not in triangle (too far left/up) and not in semicircle (dist > √2 from (3,1)) assertFalse(figure.contains(new Point(1, 3))); } // ----------------------------------------------------------------------- // Bounding box // ----------------------------------------------------------------------- @Test public void testBoundingBoxMinX() { // min(triangle.minX, arc.minX) = min(2, 3−√2) = 3−√2 ≈ 1.586 double expected = 3 - Math.sqrt(2); assertEquals(expected, figure.getBoundingBox().getMinX(), 1e-10); } @Test public void testBoundingBoxMinY() { assertEquals(0.0, figure.getBoundingBox().getMinY(), 1e-10); } @Test public void testBoundingBoxMaxX() { assertEquals(4.0, figure.getBoundingBox().getMaxX(), 1e-10); } @Test public void testBoundingBoxMaxY() { // max(triangle.maxY, arc.maxY) = max(2, 1+√2) = 1+√2 ≈ 2.414 double expected = 1 + Math.sqrt(2); assertEquals(expected, figure.getBoundingBox().getMaxY(), 1e-10); } }