<commit_before>package ge.edu.freeuni.sdp.arkanoid.model.geometry;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RectangleTest {

    @Mock Size size;
    private Point position;

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
        position = new Point(0,0);
        when(size.getWidth()).thenReturn(2);
        when(size.getHeight()).thenReturn(3);
    }

    @Test
    public void testBottomRightCorner() {
        Rectangle target = new Rectangle(position, size);
        Point bottomRight = target.getBottomRight();

        assertEquals(position.X + size.getWidth(), bottomRight.X, 0.0001);
        assertEquals(position.Y + size.getHeight(), bottomRight.Y, 0.0001);
    }

    @Test
    public void testOverlapWithPointInside() {
        Point pointInside = new Point((position.X + size.getWidth())/2, (position.Y + size.getHeight()/2));

        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(pointInside));
    }

    @Test
    public void testOverlapAtBorder() {
        Point pointInside = new Point(position.X + size.getWidth(), position.Y + size.getHeight());

        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(pointInside));
    }

    @Test
    public void testNoOverlap() {
        Point pointInside = new Point(position.X + size.getWidth() + 10, position.Y + size.getHeight() + 10);

        Rectangle target = new Rectangle(position, size);

        assertFalse(target.canOverlap(pointInside));
    }

    @Test
    public void testCircleOverlap() {
        Circle circle = mock(Circle.class);

        Rectangle target = new Rectangle(position, size);
        when(circle.canOverlap(target)).thenReturn(true);

        assertTrue(target.canOverlap(circle));
    }

    @Test
    public void testCircleNotOverlap() {
        Circle circle = mock(Circle.class);

        Rectangle target = new Rectangle(position, size);
        when(circle.canOverlap(target)).thenReturn(false);

        assertFalse(target.canOverlap(circle));
    }
}<commit_msg>Rectangle overlap with rectangle tested.<commit_after>package ge.edu.freeuni.sdp.arkanoid.model.geometry;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RectangleTest {

    @Mock Size size;
    private Point position;
    private Point targetCenter;

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
        position = new Point(0,0);
        when(size.getWidth()).thenReturn(2);
        when(size.getHeight()).thenReturn(3);
        targetCenter = new Point(position.X + size.getWidth()/2.0, position.Y + size.getHeight()/2.0);
    }

    @Test
    public void testBottomRightCorner() {
        Rectangle target = new Rectangle(position, size);
        Point bottomRight = target.getBottomRight();

        assertEquals(position.X + size.getWidth(), bottomRight.X, 0.0001);
        assertEquals(position.Y + size.getHeight(), bottomRight.Y, 0.0001);
    }

    @Test
    public void testOverlapWithPointInside() {
        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(targetCenter));
    }

    @Test
    public void testOverlapAtBorder() {
        Point pointInside = new Point(position.X + size.getWidth(), position.Y + size.getHeight());
        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(pointInside));
    }

    @Test
    public void testNoOverlap() {
        Point pointOutside = new Point(position.X + size.getWidth() + 10, position.Y + size.getHeight() + 10);
        Rectangle target = new Rectangle(position, size);

        assertFalse(target.canOverlap(pointOutside));
    }

    @Test
    public void testCircleOverlap() {
        Circle circle = mock(Circle.class);
        Rectangle target = new Rectangle(position, size);
        when(circle.canOverlap(target)).thenReturn(true);

        assertTrue(target.canOverlap(circle));
    }

    @Test
    public void testCircleNotOverlap() {
        Circle circle = mock(Circle.class);
        Rectangle target = new Rectangle(position, size);
        when(circle.canOverlap(target)).thenReturn(false);

        assertFalse(target.canOverlap(circle));
    }

    @Test
    public void testRectangleOverlapsFromTop() {
        Rectangle otherRect = mock(Rectangle.class);
        when(otherRect.getPosition()).thenReturn(new Point(position.X - 1, position.Y - 1));
        when(otherRect.getBottomRight()).thenReturn(targetCenter);

        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(otherRect));
    }

    @Test
    public void testRectangleOverlapsFromBottom() {
        Rectangle otherRect = mock(Rectangle.class);
        when(otherRect.getPosition()).thenReturn(targetCenter);
        Point pointOutside = new Point(position.X + size.getWidth() + 10, position.Y + size.getHeight() + 10);
        when(otherRect.getBottomRight()).thenReturn(pointOutside);

        Rectangle target = new Rectangle(position, size);

        assertTrue(target.canOverlap(otherRect));
    }

    @Test
    public void testRectangleNotOverlap() {
        Rectangle otherRect = mock(Rectangle.class);
        Point pointOutside1 = new Point(position.X + size.getWidth() + 10, position.Y + size.getHeight() + 10);
        Point pointOutside2 = new Point(position.X + size.getWidth() + 20, position.Y + size.getHeight() + 20);
        when(otherRect.getPosition()).thenReturn(pointOutside1);
        when(otherRect.getBottomRight()).thenReturn(pointOutside2);

        Rectangle target = new Rectangle(position, size);

        assertFalse(target.canOverlap(otherRect));
    }
}
{'fraction_non_alphanumeric': 0.11854905193734543, 'fraction_numerical': 0.00989282769991756, 'mean_word_length': 3.2037422037422036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3875117', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1736, 'n_words': 360}