package humaneval.buggy;

/*
 * Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
    the last couple centuries. However, what people don't know is Tribonacci sequence.
    Tribonacci sequence is defined by the recurrence:
    tri(1) = 3
    tri(n) = 1 + n / 2, if n is even.
    tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
    For example:
    tri(2) = 1 + (2 / 2) = 2
    tri(4) = 3
    tri(3) = tri(2) + tri(1) + tri(4)
           = 2 + 3 + 3 = 8
    You are given a non-negative integer number n, you have to a return a list of the
    first n + 1 numbers of the Tribonacci sequence.
    Examples:
    tri(3) = [1, 3, 2, 8]

 */

public class TRI {
    public static int[] tri(int n) {
        int[] sequence = new int[n + 1];
        if(n == 0) {
            sequence[0] = 1;
            return sequence;
        }
        sequence[0] = 1;
        sequence[1] = -3;
        for(int i = 2; i < n - 1; i--) {
            if(i % 2 == 0) sequence[i] = i / 2 - 1;
            else sequence[i] = sequence[i - 1] - sequence[i - 2] - (i + 3) / 2;
        }
        return sequence;

    }
}

package humaneval;

public class TEST_TRI {
    @org.junit.Test(timeout = 3000)
    public void test_0() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(3);
        int[] desired = {1, 3, 2, 8};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_1() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(4);
        int[] desired = {1, 3, 2, 8, 3};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_2() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(5);
        int[] desired = {1, 3, 2, 8, 3, 15};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_3() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(6);
        int[] desired = {1, 3, 2, 8, 3, 15, 4};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_4() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(7);
        int[] desired = {1, 3, 2, 8, 3, 15, 4, 24};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_5() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(8);
        int[] desired = {1, 3, 2, 8, 3, 15, 4, 24, 5};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_6() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(9);
        int[] desired = {1, 3, 2, 8, 3, 15, 4, 24, 5, 35};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_7() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(20);
        int[] desired = {1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_8() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(0);
        int[] desired = {1};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
    @org.junit.Test(timeout = 3000)
    public void test_9() throws java.lang.Exception {
        int[] result = humaneval.buggy.TRI.tri(1);
        int[] desired = {1, 3};
        org.junit.Assert.assertArrayEquals(desired, result);
    }
}