package ch.usi.sqt;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

class TriangleClassifierTest {

    Integer result;

    @BeforeEach
    public void setUp() {
        result = null;
    }

    @AfterEach
    public void tearDown() {
        final List<Integer> returnValues = Arrays.asList(1, 2, 3, 4);
        Assertions.assertTrue(result == null ||
                returnValues.contains(result), String.format("result not in %s: %d", returnValues, result));
    }

    @Test
    public void test1() {
        int side1 = 2;
        int side2 = 2;
        int side3 = 2;

        result = TriangleClassifier.classify(side1, side2, side3);
        TriangleKind.EQUILATERAL.shouldBeValueOf(result);
    }

    @Test
    public void test2() {
        int side1 = 2;
        int side2 = 2;
        int side3 = 3;

        result = TriangleClassifier.classify(side1, side2, side3);
        TriangleKind.ISOSCELES.shouldBeValueOf(result);
    }

    @Test
    public void test3() {
        int side1 = 2;
        int side2 = 3;
        int side3 = 2;

        result = TriangleClassifier.classify(side1, side2, side3);
        TriangleKind.ISOSCELES.shouldBeValueOf(result);
    }

    @Test
    public void test4() {
        int side1 = 2;
        int side2 = 3;
        int side3 = 4;

        result = TriangleClassifier.classify(side1, side2, side3);
        TriangleKind.SCALENE.shouldBeValueOf(result);
    }

    @Test
    public void test5() {
        int side1 = -1;
        int side2 = 2;
        int side3 = 2;

        Assertions.assertThrows(IllegalArgumentException.class, () -> {
            result = TriangleClassifier.classify(side1, side2, side3);
        });
    }

    @Test
    public void test6() {
        int side1 = 1;
        int side2 = 2;
        int side3 = 3;

        result = TriangleClassifier.classify(side1, side2, side3);
        TriangleKind.WRONG.shouldBeValueOf(result);
    }

    enum TriangleKind {
        EQUILATERAL(1), ISOSCELES(2), SCALENE(3), WRONG(4);

        private final Integer value;

        TriangleKind(int value) {
            this.value = value;
        }

        public void shouldBeValueOf(int result) {
            Assertions.assertEquals(value, result);
        }
    }
}