package org.vostan.banvor;

import org.junit.Test;
import org.vostan.banvor.model.XYPair;

import static org.junit.Assert.*;

public class UnitTestXYPair {
    public XYPair bottom_left = new XYPair(0, 0);
    public XYPair upper_right = new XYPair(10, 10);
    public XYPair middle = new XYPair(5, 5);

    @Test
    public void isInside_bottom_left_is_inside() {
        assertTrue(bottom_left.isInside(bottom_left, upper_right));
        assertTrue(new XYPair(bottom_left.x(), middle.y()).isInside(bottom_left, upper_right));
        assertTrue(new XYPair(middle.x(), bottom_left.y()).isInside(bottom_left, upper_right));
    }

    @Test
    public void isInside_upper_right_is_not_inside() {
        assertFalse(upper_right.isInside(bottom_left, upper_right));
        assertFalse(new XYPair(upper_right.x(), middle.y()).isInside(bottom_left, upper_right));
        assertFalse(new XYPair(middle.x(), upper_right.y()).isInside(bottom_left, upper_right));
    }

    @Test
    public void isInside_middle_is_inside() {
        assertTrue(middle.isInside(bottom_left, upper_right));
    }

    @Test
    public void isInside_outside_is_not_inside() {
        assertFalse(bottom_left.left().isInside(bottom_left, upper_right));
        assertFalse(new XYPair(middle.x(), bottom_left.y()-1).isInside(bottom_left, upper_right));
        assertFalse(new XYPair(upper_right.x()+1, middle.y()).isInside(bottom_left, upper_right));
        assertFalse(new XYPair(middle.x(), upper_right.y()+1).isInside(bottom_left, upper_right));
    }

    @Test
    public void l1_norne_test() {
        assertEquals(6, new XYPair(2,4).l1_norm());
        assertEquals(6, new XYPair(-2,4).l1_norm());
        assertEquals(6, new XYPair(2,-4).l1_norm());
        assertEquals(6, new XYPair(-2,-4).l1_norm());
        assertEquals(0, new XYPair(0,0).l1_norm());
    }

    @Test
    public void add_test() {
        XYPair c = XYPair.add(new XYPair(2,4), new XYPair(3, 5));
        assertEquals(5, c.x());
        assertEquals(9, c.y());

        c = XYPair.add(new XYPair(-2,4), new XYPair(3, -5));
        assertEquals(1, c.x());
        assertEquals(-1, c.y());
    }

    @Test
    public void sub_test() {
        XYPair c = XYPair.sub(new XYPair(2,9), new XYPair(3, 5));
        assertEquals(-1, c.x());
        assertEquals(4, c.y());

        c = XYPair.sub(new XYPair(-2,-4), new XYPair(3, -5));
        assertEquals(-5, c.x());
        assertEquals(1, c.y());
    }

    @Test
    public void mul_test() {
        XYPair c = XYPair.mul(new XYPair(2,9), 0);
        assertEquals(0, c.x());
        assertEquals(0, c.y());

        c = XYPair.mul(new XYPair(-2,-4), 3);
        assertEquals(-6, c.x());
        assertEquals(-12, c.y());

        c = XYPair.mul(new XYPair(-2,-4), -2);
        assertEquals(4, c.x());
        assertEquals(8, c.y());
    }

    @Test
    public void left_test() {
        XYPair c = new XYPair(5,5).left();
        assertEquals(4, c.x());
        assertEquals(5, c.y());
    }

    @Test
    public void right_test() {
        XYPair c = new XYPair(5,5).right();
        assertEquals(6, c.x());
        assertEquals(5, c.y());
    }

    @Test
    public void up_test() {
        XYPair c = new XYPair(5,5).up();
        assertEquals(5, c.x());
        assertEquals(6, c.y());
    }

    @Test
    public void down_test() {
        XYPair c = new XYPair(5,5).down();
        assertEquals(5, c.x());
        assertEquals(4, c.y());
    }

}
