using LeetCode.Logic;

namespace LeetCode.Tests;

public class MaxSubArrayIntsTests
{
    private readonly MaxSubArrayInts _sut = new();

    [Theory]
    [InlineData(new[] {-2, 1, -3, 4, -1, 2, 1, -5, 4 }, 6, new[] { 4, -1, 2, 1 })]
    [InlineData(new[] {100, -1, -1, -1 }, 100, new[] { 100 })]
    [InlineData(new[] {-1, 1, 1, -1 }, 2, new[] { 1, 1 })]
    public void MaxSubArray(int[] nums, int target, int[] result)
    {
        var (maxSum, array, errors) = _sut.MaxSubArray(nums);
        Assert.Equal(target, maxSum);
        Assert. Equal(result, array);
        Assert.Empty(errors);
    }
    
    [Theory]
    [InlineData(new[] {-2, 1, -3, 4, -1, 2, 1, -5, 4 }, 6, new[] { 4, -1, 2, 1 })]
    [InlineData(new[] {100, -1, -1, -1 }, 100, new[] { 100 })]
    [InlineData(new[] {-1, 1, 1, -1 }, 2, new[] { 1, 1 })]
    public void MaxSubArray2(int[] nums, int target, int[] result)
    {
        var (maxSum, array, errors) = _sut.MaxSubArray2(nums);
        Assert.Equal(target, maxSum);
        Assert. Equal(result, array);
        Assert.Empty(errors);
    }
    
    [Theory]
    [InlineData(new[] {-2, 1, -3, 4, -1, 2, 1, -5, 4 }, 6)]
    [InlineData(new[] {100, -1, -1, -1 }, 100)]
    [InlineData(new[] {-1, 1, 1, -1 }, 2)]
    public void MaxSubArraySumOnly(int[] nums, int target)
    {
        var result = _sut.MaxSubArraySumOnly(nums);
        Assert.Equal(target, result);
    }
}